結果

問題 No.2210 equence Squence Seuence
ユーザー umimelumimel
提出日時 2023-02-10 22:04:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 1,873 bytes
コンパイル時間 1,788 ms
コンパイル使用メモリ 171,864 KB
実行使用メモリ 12,048 KB
最終ジャッジ日時 2023-09-21 23:21:15
合計ジャッジ時間 4,233 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 11 ms
4,880 KB
testcase_04 AC 12 ms
4,992 KB
testcase_05 AC 18 ms
6,432 KB
testcase_06 AC 15 ms
5,808 KB
testcase_07 AC 38 ms
10,332 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 46 ms
12,048 KB
testcase_14 AC 46 ms
11,412 KB
testcase_15 AC 46 ms
11,528 KB
testcase_16 AC 44 ms
11,476 KB
testcase_17 AC 45 ms
11,280 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 31 ms
6,524 KB
testcase_24 AC 23 ms
5,160 KB
testcase_25 AC 27 ms
6,196 KB
testcase_26 AC 36 ms
6,656 KB
testcase_27 AC 11 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
#define drep(i, cc, n) for (ll i = (cc); i <= (n); ++i)
#define rep(i, n) drep(i, 0, n - 1)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define fi first
#define se second

const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ll INF = 1LL << 60;
const ll MAX_N = 2e5;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    ll n, k;
    cin >> n >> k;

    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    vector<pll> LC;
    ll now_a = a[0];
    ll cnt = 1;
    for(ll i=1; i<n; i++){
        if(now_a==a[i]){
            cnt++;
        }else{
            LC.pb({now_a, cnt});
            now_a=a[i];
            cnt=1;
        }
    }
    LC.pb({now_a, cnt});

    ll now_cnt = 1;
    ll sum = 0;
    ll m = (ll)LC.size();
    vector<ll> ans;
    for(ll i=0; i<m-1; i++){
        rep(j, LC[i].se-1) ans.pb(LC[i].fi);
        if(LC[i].fi < LC[i+1].fi){
            if(now_cnt<=k && k<=now_cnt+n-sum-LC[i].se-1){
                ans.pb(LC[i].fi);
            }else{
                //確定
                for(ll j=i+1; j<m; j++) rep(l, LC[j].se) ans.pb(LC[j].fi);
                rep(i, n-1) cout << ans[i] << " ";
                cout << endl;

                return 0;
            }
        }else{
            if(now_cnt<=k && k<=now_cnt+LC[i].se-1){
                //確定
                for(ll j=i+1; j<m; j++) rep(l, LC[j].se) ans.pb(LC[j].fi);
                rep(i, n-1) cout << ans[i] << " ";
                cout << endl;

                return 0;
            }else{
                now_cnt += LC[i].se;
                ans.pb(LC[i].fi);
            }
        }

        sum += LC[i].se;
    }

    while((ll)ans.size() < n-1){
        ans.pb(LC[m-1].fi);
    }

    rep(i, n-1) cout << ans[i] << " ";
    cout << endl;
}
0