結果

問題 No.771 しおり
ユーザー bal4ubal4u
提出日時 2019-08-03 20:58:07
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 234 ms / 2,000 ms
コード長 1,023 bytes
コンパイル時間 603 ms
コンパイル使用メモリ 29,848 KB
実行使用メモリ 40,708 KB
最終ジャッジ日時 2023-09-29 12:56:23
合計ジャッジ時間 4,841 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 219 ms
40,664 KB
testcase_01 AC 31 ms
40,672 KB
testcase_02 AC 11 ms
40,656 KB
testcase_03 AC 12 ms
40,708 KB
testcase_04 AC 11 ms
40,628 KB
testcase_05 AC 11 ms
40,592 KB
testcase_06 AC 11 ms
40,660 KB
testcase_07 AC 11 ms
40,616 KB
testcase_08 AC 11 ms
40,628 KB
testcase_09 AC 12 ms
40,648 KB
testcase_10 AC 12 ms
40,616 KB
testcase_11 AC 11 ms
40,544 KB
testcase_12 AC 11 ms
40,612 KB
testcase_13 AC 11 ms
40,668 KB
testcase_14 AC 12 ms
40,612 KB
testcase_15 AC 11 ms
40,616 KB
testcase_16 AC 11 ms
40,656 KB
testcase_17 AC 11 ms
40,700 KB
testcase_18 AC 11 ms
40,588 KB
testcase_19 AC 12 ms
40,636 KB
testcase_20 AC 11 ms
40,548 KB
testcase_21 AC 12 ms
40,708 KB
testcase_22 AC 11 ms
40,644 KB
testcase_23 AC 11 ms
40,700 KB
testcase_24 AC 11 ms
40,616 KB
testcase_25 AC 110 ms
40,632 KB
testcase_26 AC 13 ms
40,676 KB
testcase_27 AC 32 ms
40,636 KB
testcase_28 AC 58 ms
40,672 KB
testcase_29 AC 32 ms
40,624 KB
testcase_30 AC 230 ms
40,656 KB
testcase_31 AC 234 ms
40,688 KB
testcase_32 AC 15 ms
40,592 KB
testcase_33 AC 231 ms
40,628 KB
testcase_34 AC 227 ms
40,684 KB
testcase_35 AC 15 ms
40,676 KB
testcase_36 AC 13 ms
40,656 KB
testcase_37 AC 13 ms
40,660 KB
testcase_38 AC 16 ms
40,696 KB
testcase_39 AC 13 ms
40,656 KB
testcase_40 AC 104 ms
40,628 KB
testcase_41 AC 229 ms
40,632 KB
testcase_42 AC 214 ms
40,656 KB
testcase_43 AC 33 ms
40,544 KB
testcase_44 AC 219 ms
40,616 KB
testcase_45 AC 216 ms
40,616 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: 関数 ‘in’ 内:
main.c:8:14: 警告: 関数 ‘getchar_unlocked’ の暗黙的な宣言です [-Wimplicit-function-declaration]
    8 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:13:24: 備考: in expansion of macro ‘gc’
   13 |         int n = 0, c = gc();
      |                        ^~

ソースコード

diff #

// yukicoder: No.771 しおり
// 2019.8.3 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();
	//	while (isspace(c)) c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

#define INF 0x77777777
#define MAX 19
int N;
int a[MAX], b[MAX];
int dp[1<<MAX][MAX];

int calc(int N) {
	int s, u, v, x, ans;
	int lim = (1 << N)-1;
	
	memset(dp, INF, sizeof(dp));
	for (u = 0; u < N; u++) dp[1<<u][u] = 0;
	for (s = 0; s <= lim; s++) {
		for (u = 0; u < N; u++) if ((s>>u) & 1) for (v = 0; v < N; v++) {
			if ((s>>v) & 1) continue;
			x = dp[s][u] >= b[u]+a[v]? dp[s][u]: b[u]+a[v];
			int *p = &dp[s | (1<<v)][v];
			if (x < *p) *p = x;
		}
	}
	ans = INF;
	for (u = lim; u >= 0; u--) {
		if (ans > dp[lim][u]) ans = dp[lim][u];
	}
	return ans;
}

int main()
{
	int i, j;

	N = in();
	for (i = 0; i < N; i++) a[i] = in(), b[i] = in()-a[i];
	printf("%d\n", calc(N));
	return 0;
}
0