結果
問題 | No.78 クジ付きアイスバー |
ユーザー |
|
提出日時 | 2025-01-27 15:16:13 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 3,434 bytes |
コンパイル時間 | 4,299 ms |
コンパイル使用メモリ | 313,308 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2025-01-27 15:16:19 |
合計ジャッジ時間 | 5,298 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 35 |
ソースコード
typedef long long ll; typedef long double ld; #include <bits/stdc++.h> using namespace std; // #define int long long #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; template<typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>; // std::cout << *s.find_by_order(1) << std::endl; // 2 signed main(){ // これがないと落ちることがある ios_base::sync_with_stdio(false); cin.tie(0); ll n,k; cin >> n>>k; string s; cin >> s; ll atari = 0; for (auto e : s) { atari += e-'0'; } if(atari>=n){ ll cnt = 0; ll ata = 0; for (ll i = 0; i < n; i++){ if(i==k)break; if(s[i]=='0'){ if(ata>0){ ata--; }else{ cnt++; } }else if(s[i]=='1'){ if(ata>0){ }else{ cnt++; ata++; } }else{ if(ata>0){ ata++; }else{ cnt++; ata+=2; } } } cout << cnt << endl; }else{ ll cnt = 0; ll ata = 0; bool ok = false; for (ll i = 0; i < n; i++){ if(i==k){ok=true;break;} if(s[i]=='0'){ if(ata>0){ ata--; }else{ cnt++; } }else if(s[i]=='1'){ if(ata>0){ }else{ cnt++; ata++; } }else{ if(ata>0){ ata++; }else{ cnt++; ata+=2; } } } if(ok){ cout << cnt << endl; return 0; } ll orc = cnt; k-=n; for (ll i = 0; i < n; i++){ if(i==k){ok=true;break;} if(s[i]=='0'){ if(ata>0){ ata--; }else{ cnt++; } }else if(s[i]=='1'){ if(ata>0){ }else{ cnt++; ata++; } }else{ if(ata>0){ ata++; }else{ cnt++; ata+=2; } } } if(ok){ cout << cnt << endl; return 0; } k-=n; // n進めるのにorc-cntコスト cnt += (cnt-orc)*((k)/n); k%=n; for (ll i = 0; i < n; i++){ if(i==k){ok=true;break;} if(s[i]=='0'){ if(ata>0){ ata--; }else{ cnt++; } }else if(s[i]=='1'){ if(ata>0){ }else{ cnt++; ata++; } }else{ if(ata>0){ ata++; }else{ cnt++; ata+=2; } } } cout << cnt << endl; } }