Submission #1796091
Source Code Expand
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
int h,w,k,d[888][888],dx[]={-1,1,0,0},dy[]={0,0,-1,1};
char a[888][888];
void bfs(int x,int y)
{
queue<pii> q;
d[x][y]=0; q.push(pii(x,y));
while(!q.empty())
{
pii s=q.front(); q.pop();
for(int g=0;g<4;++g)
{
pii w=s; w.fi+=dx[g]; w.se+=dy[g];
if(d[w.fi][w.se]<=d[s.fi][s.se]+1||a[w.fi][w.se]!='.') continue;
d[w.fi][w.se]=d[s.fi][s.se]+1; q.push(w);
}
}
}
int main()
{
memset(d,127/3,sizeof d);
scanf("%d%d%d",&h,&w,&k);
int sx,sy;
for(int i=1;i<=h;++i)
{
scanf("%s",a[i]+1);
for(int j=1;j<=w;++j)
if(a[i][j]=='S') sx=i,sy=j,a[i][j]='.';
}
bfs(sx,sy);
int ans=1e9;
for(int i=1;i<=h;++i)
for(int j=1;j<=w;++j) if(d[i][j]<=k)
{
int g=min(min(i-1,h-1),min(j-1,w-j));
ans=min(ans,(g+k-1)/k);
}
printf("%d\n",ans+1);
}
Submission Info
Submission Time
2017-11-21 18:40:36+0900
Task
C - Closed Rooms
User
fjzzq2002
Language
C++14 (GCC 5.4.1)
Score
0
Code Size
1844 Byte
Status
WA
Exec Time
23 ms
Memory
4096 KB
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:52:26: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d",&h,&w,&k);
^
./Main.cpp:56:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%s",a[i]+1);
^
Judge Result
Set Name
Sample
All
Score / Max Score
0 / 0
0 / 700
Status
Set Name
Test Cases
Sample
sample1.txt, sample2.txt, sample3.txt
All
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
Case Name
Status
Exec Time
Memory
in1.txt
WA
5 ms
3968 KB
in10.txt
AC
5 ms
3968 KB
in11.txt
AC
5 ms
3968 KB
in12.txt
AC
5 ms
3968 KB
in13.txt
AC
5 ms
3968 KB
in14.txt
WA
5 ms
3968 KB
in15.txt
AC
5 ms
3968 KB
in16.txt
AC
5 ms
3968 KB
in17.txt
WA
5 ms
3968 KB
in18.txt
AC
5 ms
3968 KB
in19.txt
AC
5 ms
3968 KB
in2.txt
AC
5 ms
3968 KB
in20.txt
AC
3 ms
3968 KB
in21.txt
AC
3 ms
3328 KB
in22.txt
AC
2 ms
3328 KB
in23.txt
AC
5 ms
3968 KB
in24.txt
WA
5 ms
3968 KB
in25.txt
AC
5 ms
3968 KB
in26.txt
AC
21 ms
3968 KB
in27.txt
AC
21 ms
3968 KB
in28.txt
AC
22 ms
3968 KB
in29.txt
AC
23 ms
3968 KB
in3.txt
WA
5 ms
3968 KB
in30.txt
AC
21 ms
3968 KB
in31.txt
WA
20 ms
3968 KB
in32.txt
AC
20 ms
3968 KB
in33.txt
AC
17 ms
3968 KB
in34.txt
AC
18 ms
3968 KB
in35.txt
AC
16 ms
4096 KB
in36.txt
AC
5 ms
3968 KB
in37.txt
WA
5 ms
3968 KB
in38.txt
AC
5 ms
3968 KB
in39.txt
WA
17 ms
3968 KB
in4.txt
AC
5 ms
3968 KB
in40.txt
WA
17 ms
3968 KB
in5.txt
AC
5 ms
3968 KB
in6.txt
WA
5 ms
3968 KB
in7.txt
AC
5 ms
3968 KB
in8.txt
AC
5 ms
3968 KB
in9.txt
WA
5 ms
3968 KB
sample1.txt
AC
2 ms
3328 KB
sample2.txt
AC
2 ms
3328 KB
sample3.txt
AC
2 ms
3328 KB