結果

問題 No.1668 Grayscale
ユーザー t33ft33f
提出日時 2021-09-04 09:16:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,003 ms / 4,000 ms
コード長 998 bytes
コンパイル時間 876 ms
コンパイル使用メモリ 87,628 KB
実行使用メモリ 86,996 KB
最終ジャッジ日時 2023-08-22 15:51:55
合計ジャッジ時間 5,918 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 473 ms
81,224 KB
testcase_07 AC 477 ms
81,252 KB
testcase_08 AC 136 ms
7,260 KB
testcase_09 AC 1,003 ms
86,996 KB
testcase_10 AC 302 ms
34,192 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 32 ms
8,016 KB
testcase_14 AC 110 ms
17,976 KB
testcase_15 AC 62 ms
9,968 KB
testcase_16 AC 42 ms
7,192 KB
testcase_17 AC 21 ms
6,368 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 3 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
    int h, w, n; cin >> h >> w >> n;
    vector C(h, vector<int>(w));
    for (int i = 0; i < h; i++)
        for (int j = 0; j < w; j++) {
            int c; cin >> c;
            C[i][j] = c - 1;
        }
    vector<vector<pair<int, int> > > adj(n);
    for (int c = 1; c < n; c++) adj[c-1].emplace_back(c, 0);
    for (int i = 0; i < h; i++)
        for (int j = 0; j < w; j++) {
            if (i > 0) {
                if (const int a = C[i-1][j], b = C[i][j]; a != b)
                    adj[min(a, b)].emplace_back(max(a, b), 1);
            }
            if (j > 0) {
                if (const int a = C[i][j-1], b = C[i][j]; a != b)
                    adj[min(a, b)].emplace_back(max(a, b), 1);
            }
        }
    vector<int> dp(n, 1);
    for (int i = 0; i < n; i++)
        for (auto [j, d] : adj[i]) dp[j] = max(dp[j], dp[i] + d);
    cout << dp.back() << '\n';
}
0