結果

問題 No.1668 Grayscale
ユーザー tko919tko919
提出日時 2021-09-04 00:43:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 873 ms / 4,000 ms
コード長 1,097 bytes
コンパイル時間 2,384 ms
コンパイル使用メモリ 207,240 KB
実行使用メモリ 61,812 KB
最終ジャッジ日時 2023-08-22 03:26:49
合計ジャッジ時間 6,278 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 389 ms
61,812 KB
testcase_07 AC 388 ms
61,684 KB
testcase_08 AC 166 ms
15,720 KB
testcase_09 AC 873 ms
59,844 KB
testcase_10 AC 323 ms
18,868 KB
testcase_11 AC 2 ms
4,384 KB
testcase_12 AC 3 ms
4,384 KB
testcase_13 AC 28 ms
6,512 KB
testcase_14 AC 107 ms
13,032 KB
testcase_15 AC 60 ms
7,184 KB
testcase_16 AC 42 ms
5,712 KB
testcase_17 AC 19 ms
5,104 KB
testcase_18 AC 2 ms
4,384 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 3 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

//template
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
using ll=long long int;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}

int dx[]={1,-1,0,0},dy[]={0,0,1,-1};

int main(){
   int h,w,n;
   cin>>h>>w>>n;
   vector g(h,vector<int>(w));
   rep(i,0,h)rep(j,0,w)cin>>g[i][j];

   using P=pair<int,int>;
   vector col(n+1,vector<P>());
   rep(i,0,h)rep(j,0,w)col[g[i][j]].push_back(P{i,j});
   int cur=1,res=1;
   rep(c,1,n+1){
      for(auto& [x,y]:col[c]){
         rep(k,0,4){
            int tx=x+dx[k],ty=y+dy[k];
            if(tx<0 or tx>=h or ty<0 or ty>=w)continue;
            if(g[tx][ty]<c and cur<=g[tx][ty]){
               cur=c;
               res++;
               goto out;
            }
         }
      }
      out:;
   }
   cout<<res<<'\n';
   return 0;
}
0