結果
問題 |
No.3266 岩井星人は見ずにはいられない
|
ユーザー |
![]() |
提出日時 | 2025-09-06 15:12:37 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 8 ms / 2,000 ms |
コード長 | 2,749 bytes |
コンパイル時間 | 1,102 ms |
コンパイル使用メモリ | 112,812 KB |
実行使用メモリ | 6,272 KB |
最終ジャッジ日時 | 2025-09-06 15:12:40 |
合計ジャッジ時間 | 2,214 ms |
ジャッジサーバーID (参考情報) |
judge / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 31 |
ソースコード
#include <iostream> #include <iomanip>//小数点出力用 //cout << fixed << setprecision(10) << ans; #include <cmath> #include <algorithm> #include <vector> #include <queue> #include <stack> #include <set> #include <map> #include <unordered_map> using ll = long long; using namespace std; #define modPHash (ll)((1LL<<61)-1) #define modP (ll)998244353 bool chkrng0idx(int pos, int sup) { return (0 <= pos && pos < sup); } int clk4(int num) { return (num - 2) * (num % 2); } void yn(bool tf) { cout << (tf ? "Yes\n" : "No\n"); } int sim(string S, int bef) { int now = bef; for (int i = 0;i < S.size();i++) { if (S[i] == '0') { now--; } else { if (now < 1200) { now++; } } } return now; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll N, A; cin >> N >> A; string S; cin >> S; int delta = sim(S, -1010000) - (-1010000); int J = sim(S, 1200); int delta0 = J - 1200; if (delta < 0) { ll init = 0; int now = 1200; for (int i = 0;i < S.size();i++) { if (S[i] == '0') { now--; } else { if (now < 1200) { now++; init++; } } } if (A <= init) { init = 0; now = 1200; for (int i = 0;i < S.size();i++) { if (S[i] == '0') { now--; } else { if (now < 1200) { now++; init++; if (init == A) { cout << i + 1; return 0; } } } } } ll loop = 0; for (int i = 0;i < N;i++)if (S[i] == '1')loop++; ll cnt = (A - init - 1) / loop; ll ansans = init + cnt * loop; now = J; for (int i = 0;i < S.size();i++) { if (S[i] == '0') { now--; } else { if (now < 1200) { ansans++; now++; if (ansans == A) { cout << (1LL + cnt) * N + i + 1LL; return 0; } } } } } else { ll init = 0; ll loop = 0; int now = 1200; for (int i = 0;i < S.size();i++) { if (S[i] == '0') { now--; } else { if (now < 1200) { now++; init++; } } } if (A <= init) { init = 0; now = 1200; for (int i = 0;i < S.size();i++) { if (S[i] == '0') { now--; } else { if (now < 1200) { now++; init++; if (init == A) { cout << i + 1; return 0; } } } } } now = J; for (int i = 0;i < S.size();i++) { if (S[i] == '0') { now--; } else { if (now < 1200) { now++; loop++; } } } ll cnt = (A - init - 1) / loop; ll ansans = init + cnt * loop; now = J; for (int i = 0;i < S.size();i++) { if (S[i] == '0') { now--; } else { if (now < 1200) { ansans++; now++; if (ansans == A) { cout << (1LL + cnt) * N + i + 1LL; return 0; } } } } } return 0; }