結果

問題 No.884 Eat and Add
コンテスト
ユーザー bal4u
提出日時 2019-09-21 15:29:56
言語 C(gnu17)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=gnu17 -Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=incompatible-pointer-types -Wno-error=int-conversion -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
AC  
実行時間 3 ms / 1,000 ms
コード長 751 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 235 ms
コンパイル使用メモリ 38,724 KB
最終ジャッジ日時 2026-02-22 04:44:25
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 9
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function 'main':
main.c:36:34: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=]
   36 |                 else ans++, N[i] = 1;
      |                             ~~~~~^~~
main.c:21:6: note: at offset [-2147483648, -1] into destination object 'N' of size 200005
   21 | char N[200005]; int w;
      |      ^

ソースコード

diff #
raw source code

// 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