結果

問題 No.884 Eat and Add
ユーザー bal4ubal4u
提出日時 2019-09-21 15:29:56
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 3 ms / 1,000 ms
コード長 751 bytes
コンパイル時間 1,250 ms
コンパイル使用メモリ 29,416 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 03:35:38
合計ジャッジ時間 1,845 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

// yukicoder 884 Eat and Add
// 2019.9.21 bal4u

#include <stdio.h>

#if 1
int getchar_unlocked(void);
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif

int ins(char *s) { // 文字列の入力 スペース以下の文字で入力終了
	char *p = s--; int c;
	do c = gc(), *++s = c & 1;
	while (c > ' ');
	return s - p;
}

#define MIN(a,b) ((a)<=(b)?(a):(b))
char N[200005]; int w;

int main()
{
	int i, j, ans;
	
	w = ins(N+1);
	ans = 0, i = w; while (1) {
		while (i > 0 && N[i] == 0) i--;
		if (i == 0) break;
		j = i; while (N[i]) i--;
		j -= i;
		if (i == 0) { ans += MIN(2, j); break; }
		if (j == 1) ans++;
		else if (i > 1 && N[i-1] == 0 && j <= 2) ans += j;
		else ans++, N[i] = 1;
	}
	printf("%d\n", ans);
	return 0;
}
0