結果
問題 |
No.3266 岩井星人は見ずにはいられない
|
ユーザー |
![]() |
提出日時 | 2025-09-06 14:20:11 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,535 bytes |
コンパイル時間 | 3,602 ms |
コンパイル使用メモリ | 297,600 KB |
実行使用メモリ | 7,720 KB |
最終ジャッジ日時 | 2025-09-06 14:20:19 |
合計ジャッジ時間 | 4,913 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 20 WA * 11 |
ソースコード
#include<bits/stdc++.h> namespace { #pragma GCC diagnostic ignored "-Wunused-function" #include<atcoder/all> #pragma GCC diagnostic warning "-Wunused-function" using namespace std; using namespace atcoder; #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--) #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; } template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; } using ll = long long; using P = pair<int,int>; using VI = vector<int>; using VVI = vector<VI>; using VL = vector<ll>; using VVL = vector<VL>; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n; ll a; cin >> n >> a; string s; cin >> s; int imx = 0, mx = 0, acc = 0; rep(i, n) { if (s[i] == '0') acc--; else { acc++; if (chmax(mx, acc)) imx = i + 1; } } ll ans = 0; ll now = 1200; for (int i = 0; i < imx && a;) { if (s[i] == '0') now--; else if (now < 1200) now++, a--; ans++, i++; } rotate(s.begin(), s.begin() + imx, s.end()); int diff = n - 2 * count(all(s), '0'); int minus = max(0, diff); int gain = count(all(s), '1') - minus; assert(gain > 0); ll q = a / gain; a %= gain; ans += n * q; now += min(0, diff) * q; for (int i = 0; a;) { if (s[i] == '0') now--; else if (now < 1200) now++, a--; ans++, i++; } cout << ans << '\n'; }