AtCoder Grand Contest 014

Submission #1590372

Source codeソースコード

#include <bits/stdc++.h>

using namespace std;

inline int read()
{
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
int H,W,vis[1000][1000],K;
int mps[1000][1000],lds;
char sd[1000];
int sx,sy,dir[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
inline void deal(int xx,int yy)
{
	lds=min(lds,xx-1);
	lds=min(lds,H-xx);
	lds=min(lds,yy-1);
	lds=min(lds,W-yy);
	
}
int main()
{
	H=read(); W=read(); K=read();
	lds=1000;
	for(int i=1;i<=H;i++)
	{
		scanf("%s",sd);
		for(int j=0;j<W;j++)
		{
			mps[i][j+1]=sd[j]=='#';
			if(sd[j]=='S') sx=i,sy=j+1;
		}
	}
	queue <int> q; while(!q.empty()) q.pop();
	//cerr << sx << " " << sy << endl;
	q.push(sx); q.push(sy); vis[sx][sy]=0;
	deal(sx,sy);
	while(!q.empty())
	{
		int lx=q.front(); q.pop();
		int ly=q.front(); q.pop();
		for(int i=0;i<4;i++)
		{
			int vx=lx+dir[i][0];
			int vy=ly+dir[i][1];
			if(vx<1||vy<1||vx>H||vy>W) continue;
			if(mps[vx][vy]) continue;
			if(!vis[vx][vy]&&vis[lx][ly]<K)
			{
				vis[vx][vy]=vis[lx][ly]+1;
				deal(vx,vy);
				q.push(vx); q.push(vy);
			}
		}
	}
	cout << 1+lds/K+(lds%K!=0) << endl;
	return 0;
}

Submission

Task問題 C - Closed Rooms
User nameユーザ名 wcz111
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 AC
Score得点 700
Source lengthソースコード長 1247 Byte
File nameファイル名
Exec time実行時間 23 ms
Memory usageメモリ使用量 7296 KB

Compiler messageコンパイルメッセージ

./Main.cpp: In function ‘int main()’:
./Main.cpp:30:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%s",sd);
^

Test case

Set

Set name Score得点 / Max score Cases
Sample - sample1.txt,sample2.txt,sample3.txt
All 700 / 700 sample1.txt,sample2.txt,sample3.txt,in1.txt,in10.txt,in11.txt,in12.txt,in13.txt,in14.txt,in15.txt,in16.txt,in17.txt,in18.txt,in19.txt,in2.txt,in20.txt,in21.txt,in22.txt,in23.txt,in24.txt,in25.txt,in26.txt,in27.txt,in28.txt,in29.txt,in3.txt,in30.txt,in31.txt,in32.txt,in33.txt,in34.txt,in35.txt,in36.txt,in37.txt,in38.txt,in39.txt,in4.txt,in40.txt,in5.txt,in6.txt,in7.txt,in8.txt,in9.txt,sample1.txt,sample2.txt,sample3.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
in1.txt AC 5 ms 4352 KB
in10.txt AC 5 ms 6400 KB
in11.txt AC 5 ms 4352 KB
in12.txt AC 5 ms 4352 KB
in13.txt AC 5 ms 6400 KB
in14.txt AC 5 ms 4352 KB
in15.txt AC 5 ms 6400 KB
in16.txt AC 5 ms 6400 KB
in17.txt AC 5 ms 4480 KB
in18.txt AC 6 ms 6400 KB
in19.txt AC 5 ms 6400 KB
in2.txt AC 5 ms 6400 KB
in20.txt AC 3 ms 6400 KB
in21.txt AC 2 ms 2304 KB
in22.txt AC 2 ms 2304 KB
in23.txt AC 5 ms 6400 KB
in24.txt AC 5 ms 6400 KB
in25.txt AC 5 ms 6400 KB
in26.txt AC 6 ms 6400 KB
in27.txt AC 5 ms 6400 KB
in28.txt AC 11 ms 6400 KB
in29.txt AC 18 ms 7296 KB
in3.txt AC 5 ms 4352 KB
in30.txt AC 7 ms 6400 KB
in31.txt AC 5 ms 4352 KB
in32.txt AC 5 ms 6400 KB
in33.txt AC 21 ms 7296 KB
in34.txt AC 23 ms 7296 KB
in35.txt AC 5 ms 6400 KB
in36.txt AC 5 ms 6400 KB
in37.txt AC 5 ms 4352 KB
in38.txt AC 5 ms 6400 KB
in39.txt AC 5 ms 4352 KB
in4.txt AC 5 ms 6400 KB
in40.txt AC 5 ms 4352 KB
in5.txt AC 6 ms 6400 KB
in6.txt AC 5 ms 4352 KB
in7.txt AC 5 ms 6400 KB
in8.txt AC 5 ms 6400 KB
in9.txt AC 5 ms 4352 KB
sample1.txt AC 2 ms 2304 KB
sample2.txt AC 2 ms 2304 KB
sample3.txt AC 2 ms 2304 KB