結果

問題 No.451 575
ユーザー bal4ubal4u
提出日時 2019-07-29 06:06:20
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 1,468 bytes
コンパイル時間 132 ms
コンパイル使用メモリ 29,952 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-15 11:43:22
合計ジャッジ時間 2,759 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
4,376 KB
testcase_01 AC 0 ms
4,376 KB
testcase_02 AC 0 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 0 ms
4,384 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 8 ms
4,376 KB
testcase_08 AC 0 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 5 ms
4,380 KB
testcase_11 AC 15 ms
4,376 KB
testcase_12 AC 19 ms
4,380 KB
testcase_13 AC 20 ms
4,380 KB
testcase_14 AC 0 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 9 ms
4,380 KB
testcase_18 AC 8 ms
4,380 KB
testcase_19 AC 5 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 19 ms
4,384 KB
testcase_24 AC 10 ms
4,376 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 0 ms
4,380 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 8 ms
4,380 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 3 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: 関数 ‘in’ 内:
main.c:9:14: 警告: 関数 ‘getchar_unlocked’ の暗黙的な宣言です [-Wimplicit-function-declaration]
    9 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:17:27: 備考: in expansion of macro ‘gc’
   17 |         ll n = 0; int c = gc();
      |                           ^~
main.c: 関数 ‘out’ 内:
main.c:10:15: 警告: 関数 ‘putchar_unlocked’ の暗黙的な宣言です [-Wimplicit-function-declaration]
   10 | #define pc(c) putchar_unlocked(c)
      |               ^~~~~~~~~~~~~~~~
main.c:27:21: 備考: in expansion of macro ‘pc’
   27 |         while (i--) pc(b[i]);
      |                     ^~

ソースコード

diff #

// yukicoder: No.451 575
// 2019.7.29 bal4u

#include <stdio.h>

typedef long long ll;

#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif

ll in() {   // 非負整数の入力
	ll n = 0; int c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

void out(ll n) { // 正整数の表示(出力)
	int i;
	char b[50];

	i = 0; while (n) b[i++] = n % 10 + '0', n /= 10;
	while (i--) pc(b[i]);
	pc('\n');
}

void outs(char *s) { while (*s) pc(*s++); }

#define LIM 1000000000000000000LL
ll a[100005];
ll b[100005]; int N;

int main()
{
	int i;
	ll ma, mi12, mi34, sft;
	
	N = (int)in(); for (i = 1; i <= N; i++) b[i] = in();
	if (N == 1) {
		if (b[1] == 1) goto NO;
		else outs("2\n1\n"), out(b[1]-1);
		return 0;
	}
	a[0] = 1;
	a[1] = b[1] - a[0], ma = 0, mi12 = mi34 = LIM+1;
	for (i = 2; i <= N; i++) {
		if (i & 1) a[i] = b[i] - a[i-1];
		else       a[i] = a[i-1] - b[i];
		if ((i & 3) == 1 || (i & 3) == 2) {
			if (a[i] <= 0) goto NO;
			if (a[i] < mi12) mi12 = a[i];
		} else {
			if (a[i] < mi34) mi34 = a[i];
			if (a[i] > ma) ma = a[i];
		}
	}
	if (mi34 > 0) {
		out((ll)N+1);
		for (i = 0; i <= N; i++) out(a[i]);
	} else {
		sft = -mi34+1;
		if (sft > mi12-1 || ma+sft > LIM) goto NO;
		out((ll)N+1);
		for (i = 0; i <= N; i++) {
			if ((i & 3) == 1 || (i & 3) == 2) out(a[i]-sft);
			else out(a[i]+sft);
		}
	}
	return 0;
NO: outs("-1");
	return 0;
}
0