結果

問題 No.1668 Grayscale
ユーザー kotatsugamekotatsugame
提出日時 2021-09-03 22:32:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 755 bytes
コンパイル時間 768 ms
コンパイル使用メモリ 77,556 KB
実行使用メモリ 71,108 KB
最終ジャッジ日時 2023-08-21 23:19:49
合計ジャッジ時間 4,791 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 11 ms
33,888 KB
testcase_02 AC 12 ms
34,012 KB
testcase_03 AC 11 ms
32,044 KB
testcase_04 WA -
testcase_05 AC 11 ms
31,896 KB
testcase_06 WA -
testcase_07 AC 416 ms
71,080 KB
testcase_08 AC 150 ms
33,964 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 12 ms
34,016 KB
testcase_19 AC 10 ms
34,092 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 11 ms
34,032 KB
testcase_23 AC 11 ms
33,892 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:11:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   11 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<vector>
#include<queue>
using namespace std;
int H,W,N;
vector<int>G[1<<20];
int indeg[1<<20];
int C[1000][1000];
int d[5]={0,1,0,-1};
int dist[1<<20];
main()
{
	cin>>H>>W>>N;
	for(int i=0;i<H;i++)for(int j=0;j<W;j++)cin>>C[i][j],C[i][j]--;
	for(int i=0;i<H;i++)for(int j=0;j<W;j++)
	{
		for(int r=0;r<4;r++)
		{
			int x=i+d[r],y=j+d[r+1];
			if(x<0||y<0||x>=H||y>=W||C[x][y]<=C[i][j])continue;
			G[C[i][j]].push_back(C[x][y]);
			indeg[C[x][y]]++;
		}
	}
	queue<int>Q;
	for(int i=0;i<N;i++)if(!indeg[i])Q.push(i);
	int mx=0;
	while(!Q.empty())
	{
		int u=Q.front();Q.pop();
		if(mx<dist[u])mx=dist[u];
		for(int v:G[u])
		{
			if(dist[v]<dist[u]+1)dist[v]=dist[u]+1;
			if(!--indeg[v])Q.push(v);
		}
	}
	cout<<mx+1<<endl;
}
0