結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
49,604 KB
testcase_01 AC 13 ms
49,556 KB
testcase_02 AC 13 ms
49,668 KB
testcase_03 AC 13 ms
49,604 KB
testcase_04 AC 24 ms
49,536 KB
testcase_05 AC 13 ms
49,544 KB
testcase_06 AC 14 ms
49,604 KB
testcase_07 AC 13 ms
49,656 KB
testcase_08 AC 13 ms
49,608 KB
testcase_09 AC 13 ms
49,668 KB
testcase_10 AC 14 ms
49,540 KB
testcase_11 AC 13 ms
49,536 KB
testcase_12 AC 14 ms
49,568 KB
testcase_13 AC 13 ms
49,600 KB
testcase_14 AC 13 ms
49,580 KB
testcase_15 AC 13 ms
49,532 KB
testcase_16 AC 13 ms
49,532 KB
testcase_17 AC 13 ms
49,584 KB
testcase_18 AC 15 ms
49,668 KB
testcase_19 AC 14 ms
49,656 KB
testcase_20 AC 13 ms
49,540 KB
testcase_21 AC 14 ms
49,536 KB
testcase_22 AC 13 ms
49,672 KB
testcase_23 AC 14 ms
49,628 KB
testcase_24 AC 13 ms
49,668 KB
testcase_25 AC 13 ms
49,540 KB
testcase_26 AC 13 ms
49,604 KB
testcase_27 AC 13 ms
49,604 KB
testcase_28 AC 14 ms
49,660 KB
testcase_29 AC 13 ms
49,532 KB
testcase_30 AC 14 ms
49,536 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) {
		b1000 = a1000, b100 = a100, b1 = a1 - d;
		return 1;
	}
	return 0;
}
	
int main()
{
	int i, j, k, l, t, f, jma, kma;
	int	a[3], d[2], b[2][3];
	
	for (i = 0; i < 3; i++) a[i] = in();
	for (i = 0; i < 2; i++) {
		d[i] = in();
		for (j = 0; j < 3; j++) b[i][j] = in();
	}
	
	memset(dp, -1, sizeof(dp));
	dp[0][jma=a[0]][kma=a[1]] = a[2], f = 1;
	for (i = 0; f; i++) {
		int jj = jma, kk = kma;
		jma = kma = 0, f = 0;
		for (j = 0; j <= jj; j++)  for (k = 0; k <= kk; k++) if ((t = dp[i][j][k]) >= 0) {
			for (l = 0; l < 2; l++) if (enable(j, k, t, d[l])) {
				int *x = &(dp[i+1][b1000+b[l][0]][b100+b[l][1]]);
				f = 1;
				if (*x < b1+b[l][2]) *x = b1+b[l][2];
				if (b1000+b[l][0] > jma) jma = b1000+b[l][0];
				if (b100 +b[l][1] > kma) kma = b100 +b[l][1];
			}
		}
	}
	printf("%d\n", i-1);
	return 0;
}
0