AtCoder Grand Contest 014

Submission #1569680

Source codeソースコード

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,m,k; string f[805];
bool u[805][805];queue<P>que;int dist[805][805];
int main(){
	cin>>n>>m>>k;
	rep(i,805)rep(j,805)dist[i][j]=INF;
	rep(i,n){
		cin>>f[i];
		rep(j,m) if(f[i][j]=='S'){
			que.push(mp(i,j)); dist[i][j] = 0;
		}
	}
	while(!que.empty()){
		P p=que.front();que.pop();
		if(u[p.fi][p.sc])continue;u[p.fi][p.sc]=1;
		int dx[4]={0,1,0,-1};
		int dy[4]={1,0,-1,0};
		rep(k,4){
			int nx=p.fi+dx[k],ny=p.sc+dy[k];
			if(0<=nx&&nx<n&&0<=ny&&ny<m&&f[nx][ny]!='#'){
				dist[nx][ny] = min(dist[nx][ny],dist[p.fi][p.sc]+1);
				que.push(mp(nx,ny));
			}
		}
	}
	int ret = INF;
	rep(i,n)rep(j,m){
		if(dist[i][j]<=k){
			int x = min(min(i,n-1-i),min(j,m-1-j));
			ret = min(ret,1+(x+k-1)/k);
		}
	}
	cout<<ret<<endl;
}

Submission

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

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 25 ms 3584 KB
in10.txt AC 24 ms 3584 KB
in11.txt AC 24 ms 3584 KB
in12.txt AC 25 ms 3712 KB
in13.txt AC 25 ms 3584 KB
in14.txt AC 24 ms 3584 KB
in15.txt AC 24 ms 3584 KB
in16.txt AC 24 ms 3584 KB
in17.txt AC 25 ms 3584 KB
in18.txt AC 24 ms 3584 KB
in19.txt AC 24 ms 3584 KB
in2.txt AC 24 ms 3584 KB
in20.txt AC 3 ms 2816 KB
in21.txt AC 3 ms 2816 KB
in22.txt AC 3 ms 2816 KB
in23.txt AC 24 ms 3584 KB
in24.txt AC 25 ms 3584 KB
in25.txt AC 25 ms 3584 KB
in26.txt AC 52 ms 4224 KB
in27.txt AC 51 ms 4224 KB
in28.txt AC 52 ms 4224 KB
in29.txt AC 54 ms 4224 KB
in3.txt AC 24 ms 3712 KB
in30.txt AC 52 ms 4224 KB
in31.txt AC 50 ms 4224 KB
in32.txt AC 49 ms 4224 KB
in33.txt AC 58 ms 4224 KB
in34.txt AC 60 ms 4224 KB
in35.txt AC 58 ms 4352 KB
in36.txt AC 24 ms 3584 KB
in37.txt AC 24 ms 3584 KB
in38.txt AC 24 ms 3584 KB
in39.txt AC 54 ms 4224 KB
in4.txt AC 24 ms 3584 KB
in40.txt AC 54 ms 4224 KB
in5.txt AC 25 ms 3584 KB
in6.txt AC 24 ms 3584 KB
in7.txt AC 24 ms 3584 KB
in8.txt AC 25 ms 3584 KB
in9.txt AC 24 ms 3584 KB
sample1.txt AC 2 ms 2816 KB
sample2.txt AC 2 ms 2816 KB
sample3.txt AC 2 ms 2816 KB