結果
| 問題 | No.1668 Grayscale |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-09-03 23:18:38 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,615 bytes |
| 記録 | |
| コンパイル時間 | 4,427 ms |
| コンパイル使用メモリ | 261,804 KB |
| 最終ジャッジ日時 | 2025-01-24 07:09:40 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 8 WA * 14 |
ソースコード
/**
* author: Sooh
* created: 03.09.2021 23:00:58
**/
#include<bits/stdc++.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
//using mint = modint998244353;
//using mint = modint1000000007;
#endif
#pragma region template
using ll = long long;
template <class T> using V = vector<T>;
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define debug(var) do{std::cerr << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cerr << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cerr << e << " "; } std::cerr << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){cerr << endl;int cnt = 0;for(const auto& v : vv){cerr << cnt << "th : "; view(v); cnt++;} cerr << endl;}
ll power(ll a, ll p){ll ret = 1; while(p){if(p & 1){ret = ret * a;} a = a * a; p >>= 1;} return ret;}
ll modpow(ll a, ll p, ll mod){ll ret = 1; while(p){if(p & 1){ret = ret * a % mod;} a = a * a % mod; p >>= 1;} return ret;}
ll modinv(ll a, ll m) {ll b = m, u = 1, v = 0; while (b) {ll t = a / b ;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}
template<class T, class K>bool chmax(T &a, const K b) { if (a<b) { a=b; return 1; } return 0; }
template<class T, class K>bool chmin(T &a, const K b) { if (b<a) { a=b; return 1; } return 0; }
#pragma endregion
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
const int inf = 1001001001;
const ll INF = 1001001001001001001ll;
//const double pi = acos(-1);
//const ll mod = 998244353;
const ll mod = 1000000007;
vector<int> topological_sort(vector<set<int>> &G, vector<int> &indegree){
int V = G.size();
vector<int> ret;
queue<int> que;
for(int i = 0; i < V; i++){
if(indegree[i] == 0) que.push(i);
}
while(!que.empty()){
int v = que.front(); que.pop();
for(int nv : G[v]){
indegree[nv]--;
if(indegree[nv] == 0) que.push(nv);
}
ret.push_back(v);
}
return ret;
}
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
//cout << fixed << setprecision(20);
int h,w, n; cin >> h >> w >> n;
V<set<int>> G(n);
V<V<int>> c(h, V<int>(w));
rep(i,h) rep(j,w) cin >> c[i][j], --c[i][j];
V<int> indeg(n);
rep(i,h) rep(j,w){
if(i >= 1 && c[i - 1][j] > c[i][j]){
if(!G[c[i][j]].count(c[i - 1][j])){
indeg[c[i - 1][j]]++;
G[c[i][j]].insert(c[i - 1][j]);
}
}
if(j >= 1 && c[i][j - 1] > c[i][j]){
if(!G[c[i][j]].count(c[i][j - 1])){
indeg[c[i][j - 1]]++;
G[c[i][j]].insert(c[i][j - 1]);
}
}
if(i < h - 1 && c[i + 1][j] > c[i][j]){
if(!G[c[i][j]].count(c[i + 1][j])){
indeg[c[i + 1][j]]++;
G[c[i][j]].insert(c[i + 1][j]);
}
}
if(j < w - 1 && c[i][j + 1] > c[i][j]){
if(!G[c[i][j]].count(c[i][j + 1])){
indeg[c[i][j + 1]]++;
G[c[i][j]].insert(c[i][j + 1]);
}
}
}
auto res = topological_sort(G, indeg);
V<int> dp(n + 1, 0);
for(int v : res){
if(dp[v] == 0) dp[v] = 1;
for(int nv : G[v]){
chmax(dp[nv], dp[v] + 1);
}
}
cout << *max_element(all(dp)) << endl;
}