Submission #1777197
Source Code Expand
#include"bits/stdc++.h"
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(ll x = (l);x<=(u);x++)
#define RREP(x,l,u) for(ll x = (l);x>=(u);x--)
#define mst(x,a) memset(x,a,sizeof(x))
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define se second
#define fi first
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
#define sz(x) ((int)x.size())
#define cl(x) x.clear()
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;
const int maxn = 810;
const int mod = 1e9+7;
const int MAX = 1000000010;
const double eps = 1e-6;
const double PI = acos(-1);
template<typename T> inline void read(T &x){
x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}
template<typename A,typename B> inline void read(A&x,B&y){read(x);read(y);}
template<typename A,typename B,typename C> inline void read(A&x,B&y,C&z){read(x);read(y);read(z);}
template<typename A,typename B,typename C,typename D> inline void read(A&x,B&y,C&z,D&w){read(x);read(y);read(z);read(w);}
template<typename A,typename B> inline A fexp(A x,B p){A ans=1;for(;p;p>>=1,x=1LL*x*x%mod)if(p&1)ans=1LL*ans*x%mod;return ans;}
template<typename A,typename B> inline A fexp(A x,B p,A mo){A ans=1;for(;p;p>>=1,x=1LL*x*x%mo)if(p&1)ans=1LL*ans*x%mo;return ans;}
int n,m,K;
char st[maxn][maxn];
int d[maxn][maxn];
queue<PII> Q;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
void Work(){
REP(i,1,n)REP(j,1,m)d[i][j]=K+1;
REP(i,1,n)REP(j,1,m)if(st[i][j]=='S'){
d[i][j]=0;
Q.push(MP(i,j));
}
while(!Q.empty()){
int x=Q.front().fi,y=Q.front().se;Q.pop();
REP(k,0,3){
int tx=x+dx[k],ty=y+dy[k];
if(st[tx][ty]!='.')continue;
if(d[tx][ty]>d[x][y]+1){
d[tx][ty]=d[x][y]+1;
Q.push(MP(tx,ty));
}
}
}
int ans=n+m;
REP(i,1,n)REP(j,1,m)if(d[i][j]<=K){
int x=min(min(i-1,j-1),min(n-i,m-j));
ans=min(ans,(x+K-1)/K+1);
}
iout(ans);
}
void Init(){
read(n,m,K);
REP(i,1,n)scanf("%s",st[i]+1);
}
int main(){
Init();
Work();
return 0;
}
Submission Info
Submission Time
2017-11-16 17:26:12+0900
Task
C - Closed Rooms
User
yanQval
Language
C++14 (GCC 5.4.1)
Score
700
Code Size
2373 Byte
Status
AC
Exec Time
20 ms
Memory
3456 KB
Compile Error
./Main.cpp: In function ‘void Init()’:
./Main.cpp:84:31: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
REP(i,1,n)scanf("%s",st[i]+1);
^
Judge Result
Set Name
Sample
All
Score / Max Score
0 / 0
700 / 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
AC
5 ms
3456 KB
in10.txt
AC
5 ms
3456 KB
in11.txt
AC
5 ms
3456 KB
in12.txt
AC
5 ms
3456 KB
in13.txt
AC
5 ms
3456 KB
in14.txt
AC
5 ms
3456 KB
in15.txt
AC
5 ms
3456 KB
in16.txt
AC
5 ms
3456 KB
in17.txt
AC
5 ms
3456 KB
in18.txt
AC
5 ms
3456 KB
in19.txt
AC
5 ms
3456 KB
in2.txt
AC
5 ms
3456 KB
in20.txt
AC
3 ms
3456 KB
in21.txt
AC
1 ms
256 KB
in22.txt
AC
1 ms
256 KB
in23.txt
AC
5 ms
3456 KB
in24.txt
AC
5 ms
3456 KB
in25.txt
AC
5 ms
3456 KB
in26.txt
AC
6 ms
3456 KB
in27.txt
AC
5 ms
3456 KB
in28.txt
AC
11 ms
3456 KB
in29.txt
AC
18 ms
3456 KB
in3.txt
AC
5 ms
3456 KB
in30.txt
AC
7 ms
3456 KB
in31.txt
AC
5 ms
3456 KB
in32.txt
AC
5 ms
3456 KB
in33.txt
AC
19 ms
3456 KB
in34.txt
AC
20 ms
3456 KB
in35.txt
AC
5 ms
3456 KB
in36.txt
AC
5 ms
3456 KB
in37.txt
AC
5 ms
3456 KB
in38.txt
AC
5 ms
3456 KB
in39.txt
AC
5 ms
3456 KB
in4.txt
AC
5 ms
3456 KB
in40.txt
AC
5 ms
3456 KB
in5.txt
AC
5 ms
3456 KB
in6.txt
AC
5 ms
3456 KB
in7.txt
AC
5 ms
3456 KB
in8.txt
AC
5 ms
3456 KB
in9.txt
AC
5 ms
3456 KB
sample1.txt
AC
1 ms
256 KB
sample2.txt
AC
1 ms
256 KB
sample3.txt
AC
1 ms
256 KB