結果

問題 No.2210 equence Squence Seuence
ユーザー boatmusclesboatmuscles
提出日時 2023-02-10 21:56:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 2,235 bytes
コンパイル時間 2,091 ms
コンパイル使用メモリ 154,512 KB
実行使用メモリ 6,152 KB
最終ジャッジ日時 2023-09-21 23:09:47
合計ジャッジ時間 4,637 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 12 ms
4,376 KB
testcase_04 AC 14 ms
4,376 KB
testcase_05 AC 19 ms
4,432 KB
testcase_06 AC 17 ms
4,376 KB
testcase_07 AC 42 ms
5,508 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 52 ms
5,936 KB
testcase_14 AC 53 ms
6,152 KB
testcase_15 AC 53 ms
6,044 KB
testcase_16 AC 51 ms
6,060 KB
testcase_17 AC 54 ms
5,944 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 38 ms
5,516 KB
testcase_24 AC 29 ms
4,940 KB
testcase_25 AC 33 ms
5,372 KB
testcase_26 AC 45 ms
5,888 KB
testcase_27 AC 14 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>
#include<cassert>
#include<vector>
#include<iostream>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<functional>
#include<utility>
#include<cstring>
#include<numeric>
#include<algorithm>
#include<atcoder/math>
#include<atcoder/modint>
#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
using Mint = modint998244353;
using mint = modint;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define rep2(i, a, b) for (int i = (int)a; i < (int)(b); ++i)
#define rrep2(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); --i)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
constexpr int dx[] = {-1,0,1,0};
constexpr int dy[] = {0,-1,0,1};
constexpr int MAX_N = 100000;
//ダイクストラ法:makedijkstra
//エラトステネスの篩:makesieve
//テストケースが複数の場合:multest

int main(){
    int N, K;
    scanf("%d %d", &N, &K);
    int A[N];
    for(int i = 0; i < N; ++i) scanf("%d", A + i);
    int last = A[0], l = 0;
    int diff_idx[N];
    bool is_bigger_than_next[N];
    rep(i, N-1){
        if(A[i+1] != A[i]){
            rep2(j, l, i+1){
                diff_idx[j] = i+1;
                is_bigger_than_next[j] = A[i] > A[i+1];
            }
            l = i+1;
        }
    }
    rep2(i, l, N){
        diff_idx[i] = N;
        is_bigger_than_next[i] = false;
    }
    int answer[N];
    iota(answer, answer + N, 0);
    auto comp = [&](int a, int b){
        assert(a < b);
        if(diff_idx[a] > b) return false;
        return is_bigger_than_next[a];
    };
    nth_element(answer, answer + K - 1, answer + N, [&](int a, int b){
        return a < b ? comp(a, b) : !comp(b, a);
    });
    rep(i, answer[K-1]){
        printf("%d", A[i]);
        printf(i < N-1 ? " " : "\n");
    }
    rep2(i, answer[K-1]+1, N){
        printf("%d", A[i]);
        printf(i < N-1 ? " " : "\n");
    }
}
0