結果

問題 No.555 世界史のレポート
ユーザー bal4ubal4u
提出日時 2019-07-13 21:45:38
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 14 ms / 2,000 ms
コード長 1,120 bytes
コンパイル時間 168 ms
コンパイル使用メモリ 29,496 KB
実行使用メモリ 12,920 KB
最終ジャッジ日時 2023-08-14 16:49:13
合計ジャッジ時間 1,272 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 6 ms
6,480 KB
testcase_11 AC 5 ms
5,828 KB
testcase_12 AC 6 ms
7,272 KB
testcase_13 AC 8 ms
8,720 KB
testcase_14 AC 14 ms
12,920 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 5 ms
5,848 KB
testcase_17 AC 4 ms
4,380 KB
testcase_18 AC 5 ms
5,884 KB
testcase_19 AC 5 ms
6,056 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// yukicoder: No.555 世界史のレポート
// 2019.7.13 bal4u

#include <stdio.h>

#define HASHSIZ 900007
typedef struct { int r, w, c; } HASH;
HASH hash[HASHSIZ+5], *hashend = hash + HASHSIZ;

int insert(int r, int w, int c) {
	HASH *p = hash + (int)((((long long)r << 16) + w) % HASHSIZ);
	while (p->r) {
		if (p->r == r && p->w == w) {
			if (p->c <= c) return 0;
			p->c = c;
			return 1;
		}
		if (++p == hashend) p = hash;
	}
	p->r = r, p->w = w, p->c = c;
	return 1;
}

typedef struct { int r, w, c; } Q;  // レポートの文字数、クリップボードの文字数、コスト
Q q[1000000]; int top, end;
int C, V, N;

int main()
{
	int r, w, c, mi;

	scanf("%d%d%d", &N, &C, &V);
	mi = 0x7ffffff;
	q[0].r = 1, q[0].w = 1, q[0].c = C, end = 1;
	while (top != end) {
		r = q[top].r, w = q[top].w, c = q[top++].c;
		if (r >= N) {
			if (c < mi) mi = c;
			continue;
		}
		if (c >= mi) continue;
		if (insert(r, w, c)) {
			q[end].r = r+w, q[end].w = w, q[end++].c = c + V;         // paste
			q[end].r = r+r, q[end].w = r, q[end++].c = c + C + V;     // copy & paste
		}
	}
	printf("%d\n", mi);
	return 0;
}
0