結果

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
	int n;
	cin>>n;
	ll a;
	cin>>a;
	string s;
	cin>>s;
	ll x=0,y=0,z=0;
	for(int i=0;i<n;i++){
		if(s[i]=='0')x++;
		else{
			if(x!=0){
				a--;
				x--;
				z++;
				if(a==0){
					cout<<i+1<<endl;
					return 0;
				}
			}else y++;
		}
	}
		
	ll cnt=z;
	ll ans=n;
	ll xx=x;
	if(x==0){
		ans+=n*((a-1)/cnt);
		a=(a-1)%cnt+1;
		for(int i=0;i<n;i++){
			if(s[i]=='0')x++;
			else{
				if(x!=0){
					a--;
					x--;
					if(a==0){
						cout<<ans+i+1<<endl;
						return 0;
					}
				}
			}
		}
		assert(0);
	}else if(x>=y){
		z+=y;
		ans+=n*((a-1)/z);
		a=(a-1)%z+1;
		for(int i=0;i<n;i++){
			if(s[i]=='0')x++;
			else{
				if(x!=0){
					a--;
					x--;
					if(a==0){
						cout<<ans+i+1<<endl;
						return 0;
					}
				}
			}
		}
		assert(0);
	}else{
		z+=x;
		ans+=n*((a-1)/z);
		a=(a-1)%z+1;

		for(int i=0;i<n;i++){
			if(s[i]=='0')x++;
			else{
				if(x!=0){
					a--;
					x--;
					if(a==0){
						cout<<ans+i+1<<endl;
						return 0;
					}
				}
			}
		}
		assert(0);
	}
}


	
0