結果

問題 No.10 +か×か
ユーザー bal4ubal4u
提出日時 2021-08-13 12:14:49
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 46 ms / 5,000 ms
コード長 886 bytes
コンパイル時間 350 ms
コンパイル使用メモリ 30,084 KB
実行使用メモリ 33,608 KB
最終ジャッジ日時 2023-08-21 06:33:54
合計ジャッジ時間 1,027 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 45 ms
33,608 KB
testcase_04 AC 3 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 46 ms
32,880 KB
testcase_07 AC 9 ms
8,044 KB
testcase_08 AC 8 ms
6,564 KB
testcase_09 AC 11 ms
9,228 KB
testcase_10 AC 0 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: 関数 ‘in’ 内:
main.c:7:14: 警告: 関数 ‘getchar_unlocked’ の暗黙的な宣言です [-Wimplicit-function-declaration]
    7 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:11:24: 備考: in expansion of macro ‘gc’
   11 |         int n = 0, c = gc();
      |                        ^~
main.c: 関数 ‘main’ 内:
main.c:8:15: 警告: 関数 ‘putchar_unlocked’ の暗黙的な宣言です [-Wimplicit-function-declaration]
    8 | #define pc(c) putchar_unlocked(c)
      |               ^~~~~~~~~~~~~~~~
main.c:37:36: 備考: in expansion of macro ‘pc’
   37 |         for (i = N-2; i >= 0; --i) pc((dp[N-1][total]>>i) & 1? '*': '+');
      |                                    ^~

ソースコード

diff #

// yukicoder: 10 +か×か
// 2021.8.13

#include <stdio.h>

typedef long long ll;
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)

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

ll dp[55][100005];  // +or*
void chmin(ll *a, ll b) { if (*a == 0 || *a > b) *a = b; }
int max(int a, int b) { return a >= b? a: b; }

int main()
{
	int i, j, ma, A;

	int N = in(), total = in();
	A = in(), dp[0][A] = 1, ma = A;
	for (i = 1; i < N; ++i) {
		A = in();
		for (j = ma; j >= 0; --j) if (dp[i-1][j]) {
			int t;
			t = j*A; if (t <= total)
			chmin(&dp[i][t], (dp[i-1][j]<<1)|1);
			t = j+A; if (t <= total)
			chmin(&dp[i][t], dp[i-1][j]<<1);
		}
		ma = max(ma*A, ma+A); if (ma > total) ma = total;
	}
	for (i = N-2; i >= 0; --i) pc((dp[N-1][total]>>i) & 1? '*': '+');
	pc('\n');
	return 0;
}
0