結果

問題 No.3266 岩井星人は見ずにはいられない
ユーザー 紫前燈太
提出日時 2025-09-06 15:10:31
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 15 ms / 2,000 ms
コード長 1,099 bytes
コンパイル時間 2,389 ms
コンパイル使用メモリ 196,384 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-09-06 15:10:35
合計ジャッジ時間 4,136 ms
ジャッジサーバーID
(参考情報)
judge / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
    ll n,X;
    cin >> n >> X;

    vector<bool>tim (n,false),ac(n,false);
    
    ll now = 0,cnt = 0,lk = 0;
    for(int i=0;i<n;i++){
        char x;
        cin >> x;

        if(x == '1'){
            tim[i] = true;
            lk++;
            if(now > 0){
                cnt++;
                now--;
                ac[i] = true;

                if(cnt == X){
                    cout << i+1 << endl;
                    return 0;
                }
            }
        }else{
            now++;
        }
    }

    ll ans = n;
    X -= cnt;

    cnt = 0;
    for(int i=0;i<n;i++){
        if(tim[i]){
            if(now > 0){
                cnt++;
                now--;
                ac[i] = true;
            }
        }else{
            now++;
        }
    }

    ll tn = (X-1LL)/cnt;
    ans += n * tn;

    ll rem = (X-1LL)%cnt + 1LL;
    for(int i=0;i<n;i++){
        if(ac[i])rem--;

        if(rem == 0){
            cout << ans + i + 1LL << endl;
            return 0;
        }
    }
    
}
0