結果

問題 No.1668 Grayscale
ユーザー SSRSSSRS
提出日時 2021-09-03 21:45:06
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,524 ms / 4,000 ms
コード長 1,020 bytes
コンパイル時間 1,781 ms
コンパイル使用メモリ 171,444 KB
実行使用メモリ 124,260 KB
最終ジャッジ日時 2023-08-21 20:51:16
合計ジャッジ時間 6,808 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,388 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 504 ms
124,260 KB
testcase_07 AC 499 ms
124,260 KB
testcase_08 AC 157 ms
16,184 KB
testcase_09 AC 1,524 ms
120,236 KB
testcase_10 AC 354 ms
19,592 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 43 ms
10,128 KB
testcase_14 AC 204 ms
23,448 KB
testcase_15 AC 79 ms
9,872 KB
testcase_16 AC 49 ms
6,696 KB
testcase_17 AC 27 ms
7,304 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 3 ms
4,376 KB
testcase_21 AC 3 ms
4,380 KB
testcase_22 AC 2 ms
4,384 KB
testcase_23 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
vector<int> dx = {1, 0, -1, 0};
vector<int> dy = {0, 1, 0, -1};
int main(){
  int H, W, N;
  cin >> H >> W >> N;
  vector<vector<int>> C(H, vector<int>(W));
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      cin >> C[i][j];
      C[i][j]--;
    }
  }
  vector<vector<int>> px(N), py(N);
  vector<int> cnt(N);
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      px[C[i][j]].push_back(i);
      py[C[i][j]].push_back(j);
      cnt[C[i][j]]++;
    }
  }
  vector<int> dp(N);
  int ans = 1;
  for (int i = 0; i < N; i++){
    dp[i] = ans;
    for (int j = 0; j < cnt[i]; j++){
      int x = px[i][j];
      int y = py[i][j];
      for (int k = 0; k < 4; k++){
        int x2 = x + dx[k];
        int y2 = y + dy[k];
        if (0 <= x2 && x2 < H && 0 <= y2 && y2 < W){
          if (C[x2][y2] < i){
            dp[i] = max(dp[i], dp[C[x2][y2]] + 1);
          }
        }
      }
    }
    ans = max(ans, dp[i]);
  }
  cout << ans << endl;
}
0