結果

問題 No.884 Eat and Add
ユーザー chocoruskchocorusk
提出日時 2019-09-13 21:48:48
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 8 ms / 1,000 ms
コード長 820 bytes
コンパイル時間 695 ms
コンパイル使用メモリ 97,032 KB
実行使用メモリ 5,164 KB
最終ジャッジ日時 2023-09-17 07:07:34
合計ジャッジ時間 1,485 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 7 ms
5,084 KB
testcase_04 AC 8 ms
5,044 KB
testcase_05 AC 7 ms
5,044 KB
testcase_06 AC 7 ms
5,116 KB
testcase_07 AC 7 ms
5,064 KB
testcase_08 AC 7 ms
5,164 KB
testcase_09 AC 7 ms
5,040 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const int INF=1e9+7;
int main()
{
	string s; cin>>s;
	s="00"+s;
	int n=s.size();
	int dp[2][200020];
	dp[0][0]=0;
	dp[1][0]=INF;
	for(int i=1; i<n; i++){
		dp[0][i]=min(dp[1][i-1]+1, dp[0][i-1])+s[i]-'0';
		int d=2;
		dp[1][i]=min(dp[1][i-1], dp[0][i-1]+1)+d-1-(s[i]-'0');
	}
	cout<<min(dp[0][n-1], dp[1][n-1]+1)<<endl;
	return 0;
}
0