結果

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long

int N,A;

signed main(){
  cin>>N>>A;
  string S; cin>>S;
  vector<bool> B(N);
  for(int i = 0; i < N; i++) B[i] = (S[i] == '1');
  int now = 1200;
  int cnt = 0;
  for(int i = 0; i < N; i++){
  	if(B[i]){
  		if(1200 > now){
  			now++;
  			cnt++;
  		}
  	}
  	else now--;
  	if(A <= cnt){
  		cout << i+1 << "\n";
  		return 0;
  	}
  }
  int a = now;
  int b = cnt;
  cnt = 0;
  for(int i = 0; i < N; i++){
  	if(B[i]){
  		if(1200 > now){
  			now++;
  			cnt++;
  		}
  	}
  	else now--;
  }
  A -= b;
  int ans = N;
  A--;
  ans += (A / cnt) * N;
  A %= cnt;
  A++;
  for(int i = 0; i < 2*N; i++){
  	if(A <= 0){
  		cout << ans + i << "\n";
  		return 0;
  	}
  	if(B[i]){
  		if(1200 > now){
  			now++;
  			cnt++;
  			A--;
  		}
  	}
  	else now--;
  	if(A <= 0){
  		cout << ans + i + 1 << "\n";
  		return 0;
  	}
  }
}
0