結果
| 問題 |
No.78 クジ付きアイスバー
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-11-09 08:09:29 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 606 bytes |
| コンパイル時間 | 1,627 ms |
| コンパイル使用メモリ | 168,240 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-17 18:30:06 |
| 合計ジャッジ時間 | 2,722 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 35 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
int main(){
string s,t;
long n,k;
cin>>n>>k>>s;
long dp[32][n];
t=s+s;
for(int i=0;i<n;i++){
int j=i,cnt=1;
while(j<2*n&&cnt){
cnt+=t[j++]-'0'-1;
}
dp[0][i]=(cnt?1LL<<31:j-i);
}
for(int i=1;i<32;i++){
for(int j=0;j<n;j++){
dp[i][j]=dp[i-1][(dp[i-1][j]+j)%n]+dp[i-1][j];
}
}
long cur=0,ans=0;
for(int i=31;i>=0;i--){
if(cur+dp[i][cur%n]<k){
ans+=1LL<<i;
cur+=dp[i][cur%n];
}
}
cout<<++ans<<endl;
}