結果
| 問題 |
No.3015 右に寄せろ!
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-07-14 16:23:03 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 61 ms / 2,000 ms |
| コード長 | 1,339 bytes |
| コンパイル時間 | 4,753 ms |
| コンパイル使用メモリ | 255,164 KB |
| 実行使用メモリ | 17,552 KB |
| 最終ジャッジ日時 | 2025-07-14 16:23:12 |
| 合計ジャッジ時間 | 7,373 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 36 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll inf_ll = 9223372036854775807;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using mint = atcoder::modint998244353;
using mint1 = atcoder::modint1000000007;
using Pa = std::pair<ll, ll>;
int Yes(bool x){
if(x) cout << "Yes";
else cout << "No";
cout << endl;
return 0;
}
ll solve(deque<Pa> &A){
if(A.size() < 2){
return 0;
}
auto [a, b] = A.front();
A.pop_front();
if(a == 0){
return solve(A);
}
auto [c, d] = A.front();
A.pop_front();
if(A.size() == 0){
return (b / 2) * d;
}
auto [e, f] = A.front();
A.pop_front();
A.push_front({e, f+(b/2)*2});
ll x = (b/2)*d;
x += solve(A);
return x;
}
int main(){
string S;
cin >> S;
ll N = S.size();
deque<Pa> A;
ll x = 0;
rep(i, N){
if(i == 0 || S[i-1] == S[i]){
x++;
}
else{
A.push_back({S[i-1]-'0', x});
x = 1;
}
}
A.push_back({S[N-1]-'0', x});
cout << solve(A);
}