結果

問題 No.1668 Grayscale
ユーザー 👑 NachiaNachia
提出日時 2021-09-03 21:44:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 747 ms / 4,000 ms
コード長 977 bytes
コンパイル時間 1,950 ms
コンパイル使用メモリ 101,548 KB
実行使用メモリ 65,568 KB
最終ジャッジ日時 2023-08-21 20:50:04
合計ジャッジ時間 4,974 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 221 ms
65,568 KB
testcase_07 AC 224 ms
65,564 KB
testcase_08 AC 60 ms
6,912 KB
testcase_09 AC 747 ms
57,992 KB
testcase_10 AC 144 ms
20,992 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 19 ms
6,444 KB
testcase_14 AC 69 ms
12,992 KB
testcase_15 AC 34 ms
7,608 KB
testcase_16 AC 23 ms
6,004 KB
testcase_17 AC 13 ms
5,216 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,384 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;




0