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