結果

問題 No.1668 Grayscale
ユーザー qisnotnqqisnotnq
提出日時 2021-09-04 14:49:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 767 ms / 4,000 ms
コード長 1,085 bytes
コンパイル時間 2,132 ms
コンパイル使用メモリ 207,972 KB
実行使用メモリ 65,616 KB
最終ジャッジ日時 2023-08-22 22:36:09
合計ジャッジ時間 6,052 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 193 ms
65,516 KB
testcase_07 AC 197 ms
65,616 KB
testcase_08 AC 79 ms
16,324 KB
testcase_09 AC 767 ms
63,796 KB
testcase_10 AC 196 ms
19,080 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 19 ms
6,780 KB
testcase_14 AC 74 ms
13,836 KB
testcase_15 AC 37 ms
7,580 KB
testcase_16 AC 26 ms
5,864 KB
testcase_17 AC 12 ms
5,320 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define REP(i,n) for (int i=0;i<(n);++i)

using namespace std;

using pii = pair<int, int>;

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int H, W, N;
    cin >> H >> W >> N;
    vector<vector<int>> C(H, vector<int>(W));
    vector<vector<pii>> C_to_ij(N);
    REP(i, H) REP(j, W) {
        cin >> C[i][j];
        --C[i][j];
        C_to_ij[C[i][j]].emplace_back(i, j);
    }
    vector<int> C_to_D(N);
    REP(k, N) {
        if (k) {
            amax(C_to_D[k], C_to_D[k - 1]);
        }
        for (auto [i, j] : C_to_ij[k]) {
            REP(d, 4) {
                int ni = i + dx[d];
                int nj = j + dy[d];
                if (0 <= ni && ni < H && 0 <= nj && nj < W && C[i][j] < C[ni][nj]) {
                    amax(C_to_D[C[ni][nj]], C_to_D[k] + 1);
                }
            }
        }
    }
    int result = C_to_D[N - 1] + 1;
    cout << result << endl;

    return 0;
}
0