結果
問題 | No.884 Eat and Add |
ユーザー | tarattata1 |
提出日時 | 2019-09-14 00:17:05 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 5 ms / 1,000 ms |
コード長 | 1,138 bytes |
コンパイル時間 | 549 ms |
コンパイル使用メモリ | 72,908 KB |
実行使用メモリ | 4,780 KB |
最終ジャッジ日時 | 2023-09-17 15:38:06 |
合計ジャッジ時間 | 1,207 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,380 KB |
testcase_01 | AC | 1 ms
4,376 KB |
testcase_02 | AC | 1 ms
4,376 KB |
testcase_03 | AC | 5 ms
4,780 KB |
testcase_04 | AC | 5 ms
4,700 KB |
testcase_05 | AC | 5 ms
4,724 KB |
testcase_06 | AC | 5 ms
4,732 KB |
testcase_07 | AC | 4 ms
4,756 KB |
testcase_08 | AC | 4 ms
4,704 KB |
testcase_09 | AC | 4 ms
4,696 KB |
testcase_10 | AC | 2 ms
4,376 KB |
testcase_11 | AC | 2 ms
4,376 KB |
ソースコード
#include <stdio.h> #include <string> #include <cstring> #include <stdlib.h> #include <math.h> #include <algorithm> #include <vector> #include <set> #include <map> #include <queue> #include <stack> #include <list> #include <iterator> #include <assert.h> #pragma warning(disable:4996) typedef long long ll; #define MIN(a, b) ((a)>(b)? (b): (a)) #define MAX(a, b) ((a)<(b)? (b): (a)) #define LINF 9223300000000000000 #define INF 2140000000 const long long MOD = 1000000007; using namespace std; char str[200005]; int dp[200005][2]; int main(int argc, char* argv[]) { scanf("%s", str); int n=strlen(str); if(n==1) { if(str[0]=='0') printf("0\n"); else printf("1\n"); return 0; } int i; dp[0][0]=1; dp[0][1]=0; for(i=1; i<n; i++) { if(str[i]=='0') { dp[i][0]=MIN(dp[i-1][0], dp[i-1][1]+2); dp[i][1]=MIN(dp[i-1][0]+1, dp[i-1][1]+1); } else { dp[i][0]=MIN(dp[i-1][0]+1, dp[i-1][1]+2); dp[i][1]=MIN(dp[i-1][0], dp[i-1][1]); } } printf("%d\n", MIN(dp[n-1][0], dp[n-1][1]+2)); return 0; }