結果

問題 No.2210 equence Squence Seuence
ユーザー umimel
提出日時 2023-02-10 22:04:58
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 1,873 bytes
コンパイル時間 1,995 ms
コンパイル使用メモリ 175,520 KB
実行使用メモリ 11,568 KB
最終ジャッジ日時 2024-07-07 16:20:27
合計ジャッジ時間 4,233 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

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