結果

問題 No.158 奇妙なお使い
ユーザー bal4ubal4u
提出日時 2019-07-19 20:36:31
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 35 ms / 5,000 ms
コード長 1,296 bytes
コンパイル時間 148 ms
コンパイル使用メモリ 30,132 KB
実行使用メモリ 49,628 KB
最終ジャッジ日時 2023-09-14 23:37:20
合計ジャッジ時間 1,938 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
49,616 KB
testcase_01 AC 16 ms
49,604 KB
testcase_02 AC 14 ms
49,580 KB
testcase_03 AC 15 ms
49,548 KB
testcase_04 AC 35 ms
49,560 KB
testcase_05 AC 14 ms
49,604 KB
testcase_06 AC 14 ms
49,556 KB
testcase_07 AC 14 ms
49,612 KB
testcase_08 AC 14 ms
49,616 KB
testcase_09 AC 15 ms
49,580 KB
testcase_10 AC 14 ms
49,580 KB
testcase_11 AC 14 ms
49,540 KB
testcase_12 AC 14 ms
49,576 KB
testcase_13 AC 14 ms
49,544 KB
testcase_14 AC 14 ms
49,612 KB
testcase_15 AC 14 ms
49,624 KB
testcase_16 AC 14 ms
49,540 KB
testcase_17 AC 15 ms
49,540 KB
testcase_18 AC 17 ms
49,604 KB
testcase_19 AC 14 ms
49,544 KB
testcase_20 AC 15 ms
49,540 KB
testcase_21 AC 26 ms
49,540 KB
testcase_22 AC 26 ms
49,584 KB
testcase_23 AC 14 ms
49,480 KB
testcase_24 AC 15 ms
49,628 KB
testcase_25 AC 15 ms
49,624 KB
testcase_26 AC 14 ms
49,604 KB
testcase_27 AC 14 ms
49,616 KB
testcase_28 AC 15 ms
49,548 KB
testcase_29 AC 14 ms
49,476 KB
testcase_30 AC 15 ms
49,584 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: 関数 ‘in’ 内:
main.c:8:14: 警告: 関数 ‘getchar_unlocked’ の暗黙的な宣言です [-Wimplicit-function-declaration]
    8 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:14:24: 備考: in expansion of macro ‘gc’
   14 |         int n = 0, c = gc();
      |                        ^~

ソースコード

diff #

// yukicoder: No.158 奇妙なお使い
// 2019.7.19 bal4u

#include <stdio.h>
#include <string.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif

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

int dp[10002][12][102];
int b1000, b100, b1;

int enable(int a1000, int a100, int a1, int d) {
	if (d >= 1000 && a1000) {
		if (a1000 >= d/1000) a1000 -= d/1000, d %= 1000;
		else d -= a1000*1000, a1000 = 0;
	}
	if (d >= 100 && a100) {
		if (a100 >= d/100) a100 -= d/100, d %= 100;
		else d -= a100*100, a100 = 0;
	}
	if (a1 < d) return 0;
	b1000 = a1000, b100 = a100, b1 = a1 - d;
	return 1;
}
	
int main()
{
	int i, j, k, l, t, f;
	int	a[3], m[2][4];
	
	for (i = 0; i < 3; i++) a[i] = in();
	for (i = 0; i < 2; i++) for (j = 0; j < 4; j++) m[i][j] = in();
	
	memset(dp, -1, sizeof(dp));
	dp[0][a[0]][a[1]] = a[2], f = 1;
	for (i = 0; f; i++) {
		f = 0;
		for (j = 0; j <= 10; j++)  for (k = 0; k <= 100; k++) if ((t = dp[i][j][k]) >= 0) {
			for (l = 0; l < 2; l++) if (enable(j, k, t, m[l][0])) {
				int x = dp[i+1][b1000+m[l][1]][b100+m[l][2]];
				f = 1;
				if (x == 0 || x < b1+m[l][3]) dp[i+1][b1000+m[l][1]][b100+m[l][2]] = b1+m[l][3];
			}
		}
	}
	printf("%d\n", i-1);
	return 0;
}
0