結果
問題 |
No.3015 右に寄せろ!
|
ユーザー |
![]() |
提出日時 | 2025-01-25 14:15:33 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 3,433 bytes |
コンパイル時間 | 2,121 ms |
コンパイル使用メモリ | 173,104 KB |
実行使用メモリ | 21,704 KB |
最終ジャッジ日時 | 2025-01-25 23:13:27 |
合計ジャッジ時間 | 37,293 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 5 WA * 22 TLE * 9 |
ソースコード
#include <bits/stdc++.h> #include <iostream> #include <vector> #include <string> #include <stack> #include <algorithm> #include <iomanip> #define rep(i,n) for (ll i = 0;i < (ll)(n);i++) #define Yes cout << "Yes" << endl// YESの短縮 #define No cout << "No" << endl// NOの短縮 #define rtr0 return(0)//return(0)の短縮 #define gyakugen(x) modpow(x,mod - 2,mod); #define anothergyakugen(x) modpow(x,anothermod - 2,anothermod); using namespace std; using ll = long long;//63bit型整数型 using ld = long double;//doubleよりも長い値を保存できるもの using ull = unsigned long long;//符号がない64bit型整数 ll mod = 998244353; ll anothermod = 1000000007; ll MINF = -5000000000000000000; ll INF = 5000000000000000000; ll BAD = -1; vector<ll>tate = {0,-1,0,1};//グリッド上の全探索時の四方向の上下のチェック vector<ll>yoko = {1,0,-1,0};//グリッド上の全探索時の四方向の右左のチェック vector<ll>eightx = {0,-1,-1,-1,0,1,1,1};//グリッド上の全探索時の八方向の上下のチェック vector<ll>eighty = {1,1,0,-1,-1,-1,0,1};//グリッド上の全探索時の八方向の右左のチェック vector<ll>hexsax = {0,1,1,0,-1,-1}; vector<ll>hexsay = {1,1,0,-1,-1,0}; //返り値は素数のリスト。 vector < bool > isprime; vector < ll > Era(int n){//書き方 vector<ll>[] = Era(x); とやるとxまでの素数が出てくる。 isprime.resize(n, true); vector < ll > res; isprime[0] = false; isprime[1] = false; for(ll i = 2; i < n; ++i) isprime[i] = true; for(ll i = 2; i < n; ++i) { if(isprime[i]) { res.push_back(i); for(ll j = i * 2; j < n; j += i) isprime[j] = false; } } return res; } // 素数判定 21~35 long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } // モッドを使った累乗 /*ll ans = INF; ll N,M,K; vector<vector<pair<ll,ll>>>graph; void DFS(set<ll>&next,set<ll>&past,ll &cost){ if(past.size() == N){ ans = min(ans,cost%K); return; } if(next.empty() == true)return; ll a = *next.begin(); next.erase(a); for(ll i = 0;i<graph[a].size();i++){ ll b = graph[a][i].first; ll c = graph[a][i].second; if(!past.count(b)){ next.insert(b); past.insert(a); ll COST = (cost + c) % K; DFS(next,past,COST); next.erase(b); past.erase(a); } } DFS(next,past,cost); }*/ ll ans = 0; int main(){ //B以上は基本詳細を書いておくと便利 A = ooの値とか 見直す時に便利 // この問題の本質 string S; cin >> S; reverse(S.begin(),S.end()); ll ans = 0; vector<ll>soloone(0); ll N = S.size(); for(ll i = 0;i<N - 1;i++){ if(S[i] == '1' && S[i + 1] == '0')soloone.push_back(i); else if(S[i] == '1' && S[i + 1] == '1')i++; } ll right = 0; for(ll i = 0;i<N;i++){ if(S[i] != '1')break; else right++; } for(ll i = 0;i<soloone.size();i++)cout << soloone[i] << endl; //cout << ans << " " << S <<" " <<right << endl; for(ll i = 0;i<N - 1;i++){ if(S[i] == '1' && S[i + 1] == '1' && i > right){ ll a = lower_bound(soloone.begin(),soloone.end(),i - right) - soloone.begin(); ans += i - a - right; string X,Y,Z; X = S.substr(0,right); Y = S.substr(right,i - right); Z = S.substr(i + 2,N - right + 2); S = X + "11" + Y + Z; right += 2; //cout << ans << " " << S <<" " <<right << endl; } } cout << ans << endl; }