結果

問題 No.771 しおり
コンテスト
ユーザー pekempey
提出日時 2018-12-19 06:18:31
言語 C(gnu17)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=gnu17 -Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=incompatible-pointer-types -Wno-error=int-conversion -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
WA  
実行時間 -
コード長 824 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 164 ms
コンパイル使用メモリ 39,744 KB
最終ジャッジ日時 2026-02-22 02:15:09
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 3
other AC * 4 WA * 39
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <stdio.h>

int n, a[1000], b[1000];
int dp[1 << 18][18];

int min(int x, int y) {
    return x < y ? x : y;
}

int max(int x, int y) {
    return x > y ? x : y;
}

int main(void) {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d %d", &a[i], &b[i]);
    }
    for (int i = 0; i < 1 << n; i++) {
        if ((i & i - 1) == 0) continue;
        for (int j = 0; j < n; j++) {
            dp[i][j] = 2147483647;
            if (i & 1 << j) {
                for (int k = 0; k < n; k++) if (i & 1 << k) {
                    dp[i][j] = min(dp[i][j], max(dp[i ^ 1 << k][k], a[j] + b[k] - a[k]));
                }
            }
        }
    }
    int ans = 2147483647;
    for (int i = 0; i < n; i++) {
        ans = min(ans, dp[(1 << n) - 1][i]);
    }
    printf("%d\n", ans);
    return 0;
}

0