Submission #240339

# Submission time Handle Problem Language Result Execution time Memory
240339 2020-06-19T13:07:13 Z blacktulip Awesome Arrowland Adventure (eJOI19_adventure) C++17
100 / 100
239 ms 44872 KB
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long lo;
typedef pair< lo,lo > PII;
typedef pair< lo,PII > PIII;
 
#define fi first
#define se second
#define mp make_pair
#define int long long
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)
 
const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 1000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;
 
int n,m,b[li],a[li],k,flag,t,vis[505][505],d[505][505];
int cev;
string s[li];
vector<int> v;

inline void sp(){
	priority_queue<PIII> pq;
	pq.push(mp(0,mp(1,0)));
	while(pq.size()){
		//~ cout<<"(*(\n"<<endl;
		int para=-pq.top().fi;
		int satir=pq.top().se.fi;
		int sutun=pq.top().se.se;
		pq.pop();
		if(satir<=0 || sutun<0 || satir>n || sutun>=m)continue ;
		if(vis[satir][sutun]==1)continue ;
		d[satir][sutun]=para;
		//~ if(s[satir][sutun]=='X')continue ;
		vis[satir][sutun]=1;
		if(s[satir][sutun]=='N'){
			pq.push(mp(-para,mp(satir-1,sutun)));
			pq.push(mp(-(para+1),mp(satir,sutun+1)));
			pq.push(mp(-(para+2),mp(satir+1,sutun)));
			pq.push(mp(-(para+3),mp(satir,sutun-1)));
		}
		if(s[satir][sutun]=='E'){
			pq.push(mp(-para,mp(satir,sutun+1)));
			pq.push(mp(-(para+1),mp(satir+1,sutun)));
			pq.push(mp(-(para+3),mp(satir-1,sutun)));
			pq.push(mp(-(para+2),mp(satir,sutun-1)));
		}
		if(s[satir][sutun]=='S'){
			pq.push(mp(-para,mp(satir+1,sutun)));
			pq.push(mp(-(para+3),mp(satir,sutun+1)));
			pq.push(mp(-(para+2),mp(satir-1,sutun)));
			pq.push(mp(-(para+1),mp(satir,sutun-1)));
		}
		if(s[satir][sutun]=='W'){
			pq.push(mp(-para,mp(satir,sutun-1)));
			pq.push(mp(-(para+2),mp(satir,sutun+1)));
			pq.push(mp(-(para+3),mp(satir+1,sutun)));
			pq.push(mp(-(para+1),mp(satir-1,sutun)));
		}
	}
}

main(void){
	memset(d,-1,sizeof(d));
	scanf("%lld %lld",&n,&m);
	FOR{
		cin>>s[i];
	}
	sp();
	printf("%lld\n",d[n][m-1]);
	return 0;
}

Compilation message

adventure.cpp:73:10: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(void){
          ^
adventure.cpp: In function 'int main()':
adventure.cpp:75:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld %lld",&n,&m);
  ~~~~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 15 ms 17920 KB Output is correct
2 Correct 14 ms 17920 KB Output is correct
3 Correct 17 ms 18048 KB Output is correct
4 Correct 17 ms 18048 KB Output is correct
5 Correct 16 ms 18048 KB Output is correct
6 Correct 16 ms 18048 KB Output is correct
7 Correct 15 ms 18048 KB Output is correct
8 Correct 16 ms 17920 KB Output is correct
9 Correct 15 ms 18048 KB Output is correct
10 Correct 14 ms 17920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 17920 KB Output is correct
2 Correct 14 ms 17920 KB Output is correct
3 Correct 17 ms 18048 KB Output is correct
4 Correct 17 ms 18048 KB Output is correct
5 Correct 16 ms 18048 KB Output is correct
6 Correct 16 ms 18048 KB Output is correct
7 Correct 15 ms 18048 KB Output is correct
8 Correct 16 ms 17920 KB Output is correct
9 Correct 15 ms 18048 KB Output is correct
10 Correct 14 ms 17920 KB Output is correct
11 Correct 15 ms 17920 KB Output is correct
12 Correct 15 ms 17920 KB Output is correct
13 Correct 15 ms 18048 KB Output is correct
14 Correct 15 ms 18048 KB Output is correct
15 Correct 15 ms 17920 KB Output is correct
16 Correct 15 ms 17920 KB Output is correct
17 Correct 15 ms 17920 KB Output is correct
18 Correct 14 ms 17920 KB Output is correct
19 Correct 15 ms 17920 KB Output is correct
20 Correct 15 ms 17920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 17920 KB Output is correct
2 Correct 15 ms 17920 KB Output is correct
3 Correct 17 ms 17920 KB Output is correct
4 Correct 14 ms 17920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 18048 KB Output is correct
2 Correct 15 ms 17920 KB Output is correct
3 Correct 15 ms 18048 KB Output is correct
4 Correct 15 ms 17920 KB Output is correct
5 Correct 15 ms 17920 KB Output is correct
6 Correct 15 ms 17944 KB Output is correct
7 Correct 15 ms 17920 KB Output is correct
8 Correct 15 ms 17920 KB Output is correct
9 Correct 17 ms 18048 KB Output is correct
10 Correct 16 ms 18048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 17920 KB Output is correct
2 Correct 14 ms 17920 KB Output is correct
3 Correct 17 ms 18048 KB Output is correct
4 Correct 17 ms 18048 KB Output is correct
5 Correct 16 ms 18048 KB Output is correct
6 Correct 16 ms 18048 KB Output is correct
7 Correct 15 ms 18048 KB Output is correct
8 Correct 16 ms 17920 KB Output is correct
9 Correct 15 ms 18048 KB Output is correct
10 Correct 14 ms 17920 KB Output is correct
11 Correct 15 ms 17920 KB Output is correct
12 Correct 15 ms 17920 KB Output is correct
13 Correct 15 ms 18048 KB Output is correct
14 Correct 15 ms 18048 KB Output is correct
15 Correct 15 ms 17920 KB Output is correct
16 Correct 15 ms 17920 KB Output is correct
17 Correct 15 ms 17920 KB Output is correct
18 Correct 14 ms 17920 KB Output is correct
19 Correct 15 ms 17920 KB Output is correct
20 Correct 15 ms 17920 KB Output is correct
21 Correct 16 ms 17920 KB Output is correct
22 Correct 15 ms 17920 KB Output is correct
23 Correct 17 ms 17920 KB Output is correct
24 Correct 14 ms 17920 KB Output is correct
25 Correct 15 ms 18048 KB Output is correct
26 Correct 15 ms 17920 KB Output is correct
27 Correct 15 ms 18048 KB Output is correct
28 Correct 15 ms 17920 KB Output is correct
29 Correct 15 ms 17920 KB Output is correct
30 Correct 15 ms 17944 KB Output is correct
31 Correct 15 ms 17920 KB Output is correct
32 Correct 15 ms 17920 KB Output is correct
33 Correct 17 ms 18048 KB Output is correct
34 Correct 16 ms 18048 KB Output is correct
35 Correct 27 ms 18304 KB Output is correct
36 Correct 15 ms 18048 KB Output is correct
37 Correct 31 ms 18560 KB Output is correct
38 Correct 17 ms 18048 KB Output is correct
39 Correct 175 ms 20920 KB Output is correct
40 Correct 172 ms 21048 KB Output is correct
41 Correct 29 ms 18688 KB Output is correct
42 Correct 176 ms 20968 KB Output is correct
43 Correct 239 ms 44872 KB Output is correct
44 Correct 29 ms 18688 KB Output is correct