結果
問題 |
No.3015 右に寄せろ!
|
ユーザー |
![]() |
提出日時 | 2025-03-12 23:52:54 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,019 bytes |
コンパイル時間 | 3,427 ms |
コンパイル使用メモリ | 276,796 KB |
実行使用メモリ | 15,464 KB |
最終ジャッジ日時 | 2025-03-12 23:53:00 |
合計ジャッジ時間 | 5,849 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 6 WA * 30 |
ソースコード
#include <bits/stdc++.h> //#include <atcoder/modint> using namespace std; //using namespace atcoder; using ll = long long; //using mint = modint998244353; vector<pair<char, int>> encode(string &S){ vector<pair<char, int>> encoded; int l = 0, r, N=S.size(); while(l != N){ r = l+1; while(r<N && S[l] == S[r]) r++; encoded.push_back(make_pair(S[l], r-l)); l = r; } return encoded; } int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); /* 1が連続する数を持っておく。 それが奇数なら1110...->1011で1引いて持ち越し、 偶数ならそのまま持ち越し、0より前にある連続する1の数/2の和が答え。 */ string S; cin >> S; vector<pair<char, int>> v = encode(S); ll ans=0, sm=0; for (auto [c, x] : v){ if (c == '1') sm += x; else{ ans += sm/2; sm = sm/2*2; } } cout << ans << endl; return 0; }