結果
| 問題 |
No.884 Eat and Add
|
| コンテスト | |
| ユーザー |
bal4u
|
| 提出日時 | 2019-09-21 15:17:34 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 1,000 ms |
| コード長 | 783 bytes |
| コンパイル時間 | 497 ms |
| コンパイル使用メモリ | 29,440 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-09-18 23:27:28 |
| 合計ジャッジ時間 | 1,408 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 9 |
ソースコード
// yukicoder 884 Eat and Add
// 2019.9.21 bal4u
#include <stdio.h>
#include <string.h>
#if 1
int getchar_unlocked(void);
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
int ins(char *s) { // 文字列の入力 スペース以下の文字で入力終了
char *p = s--;
do *++s = gc();
while (*s > ' ');
*s = 0;
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);
ans = 0, i = w-1; while (1) {
while (i >= 0 && N[i] == '0') i--;
if (i < 0) break;
j = i; while (i >= 0 && N[i] == '1') i--;
if (i < 0) { ans += MIN(2, j-i); break; }
if (j-i == 1) ans++;
else if (i > 0 && N[i-1] == '0' && j-i <= 2) ans += j-i;
else ans++, N[i] = '1';
}
printf("%d\n", ans);
return 0;
}
bal4u