結果

問題 No.1668 Grayscale
ユーザー 沙耶花
提出日時 2021-09-03 22:22:46
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,171 bytes
コンパイル時間 4,726 ms
コンパイル使用メモリ 257,868 KB
最終ジャッジ日時 2025-01-24 06:07:34
ジャッジサーバーID
(参考情報)
judge1 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 7 WA * 15
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:18:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   18 |                         scanf("%d",&A[i][j]);
      |                         ~~~~~^~~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000001

int main(){
	
	int H,W,N;
	cin>>H>>W>>N;
	
	vector A(H,vector<int>(W));
	rep(i,H){
		rep(j,W){
			scanf("%d",&A[i][j]);
		}
	}
	
	vector dx = {0,0,1,-1},dy = {1,-1,0,0};
	
	scc_graph S(H*W);
	
	rep(i,H){
		rep(j,W){
			rep(k,4){
				int ii = i+dx[k],jj = j+dy[k];
				if(ii<0||ii>=H||jj<0||jj>=W)continue;
				if(A[i][j] <= A[ii][jj]){
					S.add_edge(i*W+j,ii*W+jj);
				}
			}
		}
	}
	
	auto s = S.scc();
	vector<vector<int>> pos(H,vector<int>(W));
	rep(i,s.size()){
		rep(j,s[i].size()){
			pos[s[i][j]/W][s[i][j]%W] = i;
		}
	}
	
	vector dp(s.size(),1);
	
	rep(i,s.size()){
		rep(j,s[i].size()){
			int y = s[i][j]/W,x = s[i][j]%W;
			rep(k,4){
				int yy = y+dx[k],xx = x+dy[k];
				if(yy<0||yy>=H||xx<0||xx>=W)continue;
				if(pos[yy][xx]<=pos[y][x])continue;
				dp[pos[yy][xx]] = max(dp[pos[yy][xx]],dp[pos[y][x]]+1);
			}
		}
	}
	
	int ans = 0;
	rep(i,dp.size()){
	//	cout<<dp[i]<<endl;
		ans = max(ans,dp[i]);
	}
	
	cout<<ans<<endl;
	
	return 0;
}
0