Submission #2109753


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
}
//}}}
const ll maxn=505;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=2000000000;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;
/*
ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) a=a*a%MOD;
		else res=res*a%MOD;
		b>>=1;
	}
	res=res*a%mod;
	return res;
}
*/
bool a[maxn][maxn];
const pii dir[]={{0,1},{0,-1},{1,0},{-1,0}};
pii operator+(pii a,pii b){
	return {a.F+b.F,a.S+b.S};
}

bool vis[maxn][maxn];
int dis[maxn][maxn];
vector<pii> q;
int pt=0;

int main()
{
	//IOS;
	int n,m;
	cin>>n>>m;
	REP(i,n){
		string s;
		cin>>s;
		REP(j,m){
			if(s[j]=='.') a[i+1][j+1]=1;
		}
	}
	int cnt=0;
	REP(i,n) REP(j,m) if(a[i+1][j+1]) cnt++;

	{
		q.pb({1,1});
		vis[1][1]=0;
		while(pt<q.size()){
			pii cur=q[pt++];
			REP(I,4){
				pii nxt=cur+dir[I];
				if(!a[nxt.F][nxt.S]||vis[nxt.F][nxt.S]) continue;
				dis[nxt.F][nxt.S]=dis[cur.F][cur.S]+1;
				vis[nxt.F][nxt.S]=1;
				q.pb(nxt);
			}
		}
	}
	if(vis[n][m]){
		cout<<cnt-dis[n][m]-1;
	}
	else cout<<-1;

	return 0;
}

Submission Info

Submission Time
Task D - Grid Repainting
User iloveUtaha
Language C++14 (GCC 5.4.1)
Score 400
Code Size 2126 Byte
Status
Exec Time 1 ms
Memory 512 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 s1.txt, s2.txt
All 400 / 400 in01.txt, in02.txt, in03.txt, in04.txt, in05.txt, in06.txt, in07.txt, in08.txt, in09.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, s1.txt, s2.txt
Case Name Status Exec Time Memory
in01.txt 1 ms 256 KB
in02.txt 1 ms 256 KB
in03.txt 1 ms 256 KB
in04.txt 1 ms 256 KB
in05.txt 1 ms 256 KB
in06.txt 1 ms 256 KB
in07.txt 1 ms 256 KB
in08.txt 1 ms 256 KB
in09.txt 1 ms 256 KB
in10.txt 1 ms 256 KB
in11.txt 1 ms 256 KB
in12.txt 1 ms 256 KB
in13.txt 1 ms 256 KB
in14.txt 1 ms 256 KB
in15.txt 1 ms 384 KB
in16.txt 1 ms 512 KB
in17.txt 1 ms 384 KB
in18.txt 1 ms 384 KB
s1.txt 1 ms 256 KB
s2.txt 1 ms 256 KB