結果
| 問題 |
No.1668 Grayscale
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-09-04 14:49:52 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 890 ms / 4,000 ms |
| コード長 | 1,085 bytes |
| コンパイル時間 | 2,314 ms |
| コンパイル使用メモリ | 201,304 KB |
| 最終ジャッジ日時 | 2025-01-24 07:50:15 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 22 |
ソースコード
#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;
}