結果
| 問題 | No.1668 Grayscale | 
| コンテスト | |
| ユーザー |  Nachia | 
| 提出日時 | 2021-09-03 23:27:30 | 
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 647 ms / 4,000 ms | 
| コード長 | 976 bytes | 
| コンパイル時間 | 2,093 ms | 
| コンパイル使用メモリ | 143,260 KB | 
| 実行使用メモリ | 65,832 KB | 
| 最終ジャッジ日時 | 2024-12-15 18:21:19 | 
| 合計ジャッジ時間 | 4,353 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 22 | 
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <atcoder/string>
#include <atcoder/segtree>
using namespace std;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
#define rep(i,n) for(int i=0; i<(n); i++)
int H,W,N;
vector<vector<int>> G;
vector<vector<int>> E;
vector<int> D;
int main(){
  cin >> H >> W >> N;
  G.assign(H,vector<int>(W));
  rep(y,H) rep(x,W){ cin >> G[y][x]; G[y][x]--; }
  E.resize(N);
  rep(y,H) rep(x,W-1) if(G[y][x] != G[y][x+1]) E[min(G[y][x],G[y][x+1])].push_back(max(G[y][x],G[y][x+1]));
  rep(y,H-1) rep(x,W) if(G[y][x] != G[y+1][x]) E[min(G[y][x],G[y+1][x])].push_back(max(G[y][x],G[y+1][x]));
  D.assign(N+1,1);
  rep(i,N){
    for(int e : E[i]) D[e] = max(D[e], D[i] + 1);
    D[i+1] = max(D[i+1], D[i]);
  }
  cout << D.back() << endl;
  return 0;
}
struct ios_do_not_sync{
  ios_do_not_sync(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
  }
} ios_do_not_sync_instance;
            
            
            
        