結果

問題 No.2210 equence Squence Seuence
ユーザー CoCo_Japan_panCoCo_Japan_pan
提出日時 2023-02-11 20:44:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 1,392 bytes
コンパイル時間 2,629 ms
コンパイル使用メモリ 207,456 KB
実行使用メモリ 5,548 KB
最終ジャッジ日時 2023-09-22 15:59:37
合計ジャッジ時間 4,954 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 8 ms
4,376 KB
testcase_04 AC 10 ms
4,376 KB
testcase_05 AC 14 ms
4,380 KB
testcase_06 AC 12 ms
4,376 KB
testcase_07 AC 31 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 38 ms
4,568 KB
testcase_14 AC 38 ms
4,576 KB
testcase_15 AC 38 ms
4,740 KB
testcase_16 AC 38 ms
4,592 KB
testcase_17 AC 38 ms
4,572 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 28 ms
4,912 KB
testcase_24 AC 21 ms
4,612 KB
testcase_25 AC 25 ms
4,904 KB
testcase_26 AC 33 ms
5,548 KB
testcase_27 AC 10 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// 提出時に定数倍高速化,assertはオフ
#ifndef DEBUG
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#ifndef NDEBUG
#define NDEBUG
#endif
#endif

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define all(x) (x).begin(), (x).end()
template <class T> using vec = vector<T>;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, K;
    cin >> N >> K;
    vec<int>A(N);
    for(int &a : A) cin >> a;
    stack<int> cur;
    vec<int> ans(N, -1);
    int frontIndex = 0, backIndex = N - 1;
    for(int i = 0; i < N; i++){
        if(cur.empty()){
            cur.push(i);
            continue;
        }
        if(A[cur.top()] > A[i]){
            while(!cur.empty()){
                ans[frontIndex++] = cur.top();
                cur.pop();
            }
        } else if(A[cur.top()] < A[i]){
            while(!cur.empty()){
                ans[backIndex--] = cur.top();
                cur.pop();
            }
        }
        cur.push(i);
    }
    while(!cur.empty()){
        ans[frontIndex++] = cur.top();
        cur.pop();
    }
    /*
    for(int i = 0; i < N; i++){
        cout << ans[i] << "\n";
    }
    //*/
    //*
    int ansIndex = ans[K - 1];
    for(int i = 0; i < N; i++){
        if(i != ansIndex) cout << A[i] << " ";
    }
    cout << "\n";
    //*/
}
0