結果
| 問題 |
No.3266 岩井星人は見ずにはいられない
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-09-06 13:22:11 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,258 bytes |
| コンパイル時間 | 825 ms |
| コンパイル使用メモリ | 68,532 KB |
| 実行使用メモリ | 7,720 KB |
| 最終ジャッジ日時 | 2025-09-06 13:22:18 |
| 合計ジャッジ時間 | 2,042 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 22 WA * 9 |
ソースコード
#include<iostream>
#include<vector>
#include<cassert>
using namespace std;
//0-indexed
#include<vector>
#include<cassert>
template<typename T>
struct BIT{
int N;
vector<T>bit;
BIT(int N_=0):N(N_),bit(N_){}
T sum(int i)
{
assert(0<=i&&i<=N);
T ans=0;
for(;i>0;i-=i&-i)ans+=bit[i-1];
return ans;
}
void add(int i,T a)
{
assert(0<=i&&i<N);
i++;
for(;i<=N;i+=i&-i)bit[i-1]+=a;
}
int lower_bound(T k)//k<=sum(ret)
{
if(k<=0)return 0;
int ret=0,i=1;
while((i<<1)<=N)i<<=1;
for(;i;i>>=1)
{
if(ret+i<=N&&bit[ret+i-1]<k)
{
ret+=i;
k-=bit[ret-1];
}
}
return ret+1;
//ret+1 == N+1 <=> sum<k
}
};
int N;
long A;
string S;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin>>N>>A>>S;
int cur=0;
vector<int>E;
BIT<int>bit(N);
for(int i=0;i<N;i++)
{
if(S[i]=='0')cur--;
else
{
if(cur==0)E.push_back(i);
else cur++,bit.add(i,1);
}
}
A--;
long pos=0;
if(cur<0)
{
int ei=0;
while(ei<E.size())
{
if(A<bit.sum(N))
{
cout<<pos+bit.lower_bound(A+1)<<endl;
return 0;
}
A-=bit.sum(N);
for(int t=0;t<-cur&&ei<E.size();t++,ei++)bit.add(E[ei],1);
pos+=N;
}
}
long t=A/bit.sum(N);
A-=t*bit.sum(N);
pos+=t*N;
cout<<pos+bit.lower_bound(A+1)<<endl;
}