結果

問題 No.2157 崖
ユーザー みここみここ
提出日時 2022-12-10 19:57:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4,819 ms / 6,000 ms
コード長 939 bytes
コンパイル時間 753 ms
コンパイル使用メモリ 77,792 KB
実行使用メモリ 21,120 KB
最終ジャッジ日時 2024-04-23 00:43:35
合計ジャッジ時間 37,897 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2,874 ms
15,616 KB
testcase_14 AC 3,970 ms
21,120 KB
testcase_15 AC 2,572 ms
16,896 KB
testcase_16 AC 2,631 ms
16,896 KB
testcase_17 AC 3,289 ms
19,584 KB
testcase_18 AC 3,184 ms
19,328 KB
testcase_19 AC 3,886 ms
17,408 KB
testcase_20 AC 4,819 ms
20,736 KB
testcase_21 AC 4,677 ms
20,992 KB
testcase_22 AC 2,936 ms
18,816 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 6 ms
15,744 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
using namespace std;

const int INF = 1000000007;

int d[1505][1505];
int dp[1505][1505];

int main()
{
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < m; j++)
        {
            cin >> d[i][j];
        }
        sort(d[i], d[i] + m);
    }
    for(int i = 1; i < n; i++)
    {
        for(int j = 0; j < m; j++)
        {
            dp[i][j] = INF;
        }
    }
    for(int i = 1; i < n; i++)
    {
        for(int j = 0; j < m; j++)
        {
            for(int k = 0; k < m; k++)
            {
                if(d[i][j] >= d[i - 1][k])
                {
                    dp[i][j] = min(dp[i][j], max(dp[i - 1][k], d[i][j] - d[i - 1][k]));
                }
            }
        }
    }
    int ans = INF;
    for(int j = 0; j < m; j++)
    {
        ans = min(ans, dp[n - 1][j]);
    }
    cout << (ans == INF ? -1 : ans) << endl;
}
0