結果
| 問題 |
No.884 Eat and Add
|
| ユーザー |
|
| 提出日時 | 2022-09-05 07:37:03 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 43 ms / 1,000 ms |
| コード長 | 1,910 bytes |
| コンパイル時間 | 3,133 ms |
| コンパイル使用メモリ | 179,080 KB |
| 最終ジャッジ日時 | 2025-02-07 02:52:03 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 9 |
ソースコード
#include <atcoder/all>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip>
#pragma GCC optimize("Ofast")
using namespace std;
using namespace atcoder;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
typedef long long ll;
typedef unsigned long long ull;
const ll inf=1e18;
using graph = vector<vector<int> > ;
using P= pair<ll,ll>;
using vi=vector<int>;
using vvi=vector<vi>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vp=vector<P>;
using vpp=vector<vp>;
//string T="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
//string S="abcdefghijklmnopqrstuvwxyz";
//g++ main.cpp -std=c++14 -I .
//cout <<setprecision(20);
//cout << fixed << setprecision(10);
//cin.tie(0); ios::sync_with_stdio(false);
const double PI = acos(-1);
int main(){cin.tie(0); ios::sync_with_stdio(false);
string s; cin >> s;
reverse(s.begin(),s.end());
int n=s.size();
vi a(n);
rep(i,n)a[i]=s[i]-'0';
vvll dp(n+1,vll(2,inf));
dp[0][0]=0;
rep(i,n)rep(j,2){
int now=j+a[i];
int nj=now/2;
if(now%2==0)dp[i+1][nj]=min(dp[i+1][nj],dp[i][j]);
else {
dp[i+1][1]=min(dp[i+1][1],dp[i][j]+1);
dp[i+1][0]=min(dp[i+1][0],dp[i][j]+1);
}
}
cout << min(dp[n][0],dp[n][1]+1) << endl;
}