結果

問題 No.10 +か×か
ユーザー bal4ubal4u
提出日時 2021-08-13 11:37:39
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 112 ms / 5,000 ms
コード長 1,171 bytes
コンパイル時間 172 ms
コンパイル使用メモリ 30,924 KB
実行使用メモリ 93,904 KB
最終ジャッジ日時 2023-08-21 06:33:58
合計ジャッジ時間 1,142 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 0 ms
4,376 KB
testcase_03 AC 112 ms
93,904 KB
testcase_04 AC 5 ms
4,792 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 112 ms
91,920 KB
testcase_07 AC 24 ms
20,296 KB
testcase_08 AC 18 ms
15,552 KB
testcase_09 AC 25 ms
22,064 KB
testcase_10 AC 1 ms
4,376 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: 関数 ‘mypr’ 内:
main.c:8:15: 警告: 関数 ‘putchar_unlocked’ の暗黙的な宣言です [-Wimplicit-function-declaration]
    8 | #define pc(c) putchar_unlocked(c)
      |               ^~~~~~~~~~~~~~~~
main.c:23:9: 備考: in expansion of macro ‘pc’
   23 |         pc((dp[i][j][1] & 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][3];  // [0]:exist, [1]:+or*, [2]:prev
void chmin(int *a, int b) { if (*a > b) *a = b; }
int max(int a, int b) { return a >= b? a: b; }

void mypr(int i, int j) {
	if (i == 0) return;
	mypr(i-1, dp[i][j][2]);
	pc((dp[i][j][1] & 1)? '*': '+');
}

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

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