結果

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

ソースコード

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);
	}
	while(a>0){
		ll ncnt=cnt;
		if(x>=y){
			ncnt+=y;
			xx+=x-y;
			y=0;
		}else{
			ncnt+=x;
			y-=x;
		}
		if(y==0){
			ans+=n*((a-1)/ncnt);
			a=(a-1)%ncnt+1;
		}
		if(ncnt>=a){
//			cout<<"xx"<<xx<<endl;
//			cout<<ans<<endl;
			for(int i=0;i<n;i++){
				if(s[i]=='0')xx++;
				else{
					if(xx!=0){
						a--;
						xx--;
						if(a==0){
							cout<<ans+i+1<<endl;
							return 0;
						}
					}
				}
			}
			assert(0);
		}else{
			a-=ncnt;
			cnt=ncnt;
			ans+=n;
		}
	}
}
0