結果

問題 No.158 奇妙なお使い
ユーザー bal4ubal4u
提出日時 2019-07-19 21:42:28
言語 C
(gcc 12.3.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,777 bytes
コンパイル時間 158 ms
コンパイル使用メモリ 30,832 KB
実行使用メモリ 49,660 KB
最終ジャッジ日時 2023-09-14 23:37:48
合計ジャッジ時間 1,742 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
49,540 KB
testcase_01 AC 15 ms
49,660 KB
testcase_02 AC 14 ms
49,536 KB
testcase_03 WA -
testcase_04 AC 0 ms
4,380 KB
testcase_05 AC 14 ms
49,580 KB
testcase_06 AC 15 ms
49,660 KB
testcase_07 AC 14 ms
49,544 KB
testcase_08 AC 14 ms
49,536 KB
testcase_09 AC 14 ms
49,576 KB
testcase_10 AC 14 ms
49,576 KB
testcase_11 AC 15 ms
49,660 KB
testcase_12 AC 15 ms
49,604 KB
testcase_13 AC 14 ms
49,588 KB
testcase_14 AC 14 ms
49,588 KB
testcase_15 AC 14 ms
49,608 KB
testcase_16 AC 14 ms
49,604 KB
testcase_17 AC 15 ms
49,580 KB
testcase_18 AC 15 ms
49,660 KB
testcase_19 AC 14 ms
49,580 KB
testcase_20 AC 14 ms
49,604 KB
testcase_21 AC 0 ms
4,376 KB
testcase_22 AC 0 ms
4,380 KB
testcase_23 AC 14 ms
49,576 KB
testcase_24 AC 14 ms
49,548 KB
testcase_25 AC 15 ms
49,648 KB
testcase_26 AC 15 ms
49,540 KB
testcase_27 AC 14 ms
49,604 KB
testcase_28 AC 15 ms
49,544 KB
testcase_29 AC 15 ms
49,648 KB
testcase_30 AC 14 ms
49,660 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;
}

#define TOTAL(a,b,c) ((a)*1000+(b)*100+(c))

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();
	}
	
	// for special case
	for (i = 0; i < 2; i++) {
		if (d[i] - (j = TOTAL(b[i][0], b[i][1], b[i][2])) == 1 && d[i] <= d[!i]) {
			if (a[0] >= b[i][0] && a[0]*10+a[1] >= b[i][0]*10+b[i][1] &&
				(k = TOTAL(a[0], a[1], a[2])) >= j) {
				printf("%d\n", k-j);
				return 0;
			}
		}
	}
	
	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