結果

問題 No.2210 equence Squence Seuence
ユーザー Manuel1024
提出日時 2023-02-10 22:03:58
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 92 ms / 2,000 ms
コード長 895 bytes
コンパイル時間 879 ms
コンパイル使用メモリ 81,288 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-07 16:19:30
合計ジャッジ時間 3,544 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    int n, k; cin >> n >> k;
    vector<int> a(n);
    for(auto &it: a) cin >> it;

    vector<bool> mem(n);
    for(int i = 0; i < n-1; ){
        int j = i;
        while(j+1 < n && a[j] == a[j+1]) j++;
        bool res = true;
        if(j+1 < n) res = a[j] < a[j+1];
        for(int l = i; l <= j && l < n; l++) mem[l] = res;
        i = j+1;
    }

    vector<int> v(n);
    for(int i = 0; i < n; i++) v[i] = i;
    sort(v.begin(), v.end(), [&](int x, int y){
        if(x < y){
            return !mem[x];
        }else{
            return (bool)mem[y];
        }
    });
    vector<int> ans;
    for(int i = 0; i < n; i++){
        if(v[k-1] == i) continue;
        ans.emplace_back(a[i]);
    }
    for(int i = 0; i < ans.size(); i++) cout << ans[i] << " \n"[i == ans.size()-1];
    return 0;
}
0