답안 #124148

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
124148 2019-07-02T15:03:10 Z naderjemel Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
472 ms 112508 KB
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define INF 1e9
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<pair<int,int> > vii;

int n,m;
vector<vi> ns;
bitset<30001> dp[30001],vis;
queue<pair<ii,int> > q;
void solve(int pos, int u, int d, int p){
	if(pos<0 || pos>=n) return;
	if(dp[pos][p]) return;
	dp[pos][p]=true;
	q.push(mp(mp(d+1,pos),p));
	if(!vis[pos]){
		for(int i:ns[pos]) q.push(mp(mp(d+1,pos),i));
		vis[pos]=true;
	}
}
int main(){
	//printf("here\n");
	scanf("%d%d",&n,&m);
	ns.assign(n+2,vi());
	int n1;
	int nf;
	for(int i=0;i<m;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		if(!i) n1=x;
		if(i==1) nf=x;
		ns[x].pb(y);
		//jm[i]=y;
	}
	//for(int i=0;i<n;i++) printf("%d ", dis[n1][i]); printf("\n");	
	for(int i:ns[n1]){
		dp[n1][i]=true;
		q.push(mp(mp(0,n1),i));
	}
	while(!q.empty()){
		int u=q.front().fi.se;
		int d=q.front().fi.fi;
		int p=q.front().se;
		q.pop();
		if(u==nf){
			printf("%d\n", d);
			return 0;
		}
		solve(u+p,u,d,p);
		//printf("%d %d\n",u,p);
		solve(u-p,u,d,p);

	}
	//printf("%d %d\n", n1,nf);
	printf("-1\n");
	return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:29:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&m);
  ~~~~~^~~~~~~~~~~~~~
skyscraper.cpp:35:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",&x,&y);
   ~~~~~^~~~~~~~~~~~~~
skyscraper.cpp:42:17: warning: 'n1' may be used uninitialized in this function [-Wmaybe-uninitialized]
  for(int i:ns[n1]){
                 ^
skyscraper.cpp:51:3: warning: 'nf' may be used uninitialized in this function [-Wmaybe-uninitialized]
   if(u==nf){
   ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 504 KB Output is correct
10 Correct 2 ms 632 KB Output is correct
11 Correct 3 ms 632 KB Output is correct
12 Correct 3 ms 632 KB Output is correct
13 Correct 3 ms 760 KB Output is correct
14 Correct 3 ms 760 KB Output is correct
15 Correct 3 ms 760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 380 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 504 KB Output is correct
10 Correct 3 ms 632 KB Output is correct
11 Correct 3 ms 632 KB Output is correct
12 Correct 3 ms 632 KB Output is correct
13 Correct 3 ms 760 KB Output is correct
14 Correct 3 ms 760 KB Output is correct
15 Correct 3 ms 760 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 6 ms 3192 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 504 KB Output is correct
20 Correct 11 ms 7800 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 9 ms 5752 KB Output is correct
24 Correct 10 ms 6988 KB Output is correct
25 Correct 5 ms 1784 KB Output is correct
26 Correct 10 ms 6652 KB Output is correct
27 Correct 10 ms 7032 KB Output is correct
28 Correct 12 ms 7800 KB Output is correct
29 Correct 12 ms 7800 KB Output is correct
30 Correct 11 ms 7800 KB Output is correct
31 Correct 11 ms 7800 KB Output is correct
32 Correct 11 ms 7800 KB Output is correct
33 Correct 14 ms 7800 KB Output is correct
34 Correct 13 ms 7804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 380 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 3 ms 632 KB Output is correct
11 Correct 3 ms 632 KB Output is correct
12 Correct 3 ms 632 KB Output is correct
13 Correct 3 ms 760 KB Output is correct
14 Correct 3 ms 760 KB Output is correct
15 Correct 3 ms 760 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 6 ms 3192 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 504 KB Output is correct
20 Correct 11 ms 7800 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 9 ms 5752 KB Output is correct
24 Correct 10 ms 7032 KB Output is correct
25 Correct 4 ms 1912 KB Output is correct
26 Correct 10 ms 6748 KB Output is correct
27 Correct 10 ms 7032 KB Output is correct
28 Correct 12 ms 7800 KB Output is correct
29 Correct 12 ms 7672 KB Output is correct
30 Correct 11 ms 7672 KB Output is correct
31 Correct 11 ms 7800 KB Output is correct
32 Correct 11 ms 7672 KB Output is correct
33 Correct 14 ms 7800 KB Output is correct
34 Correct 13 ms 7800 KB Output is correct
35 Correct 17 ms 6264 KB Output is correct
36 Correct 6 ms 2936 KB Output is correct
37 Correct 17 ms 8000 KB Output is correct
38 Correct 21 ms 8440 KB Output is correct
39 Correct 11 ms 1260 KB Output is correct
40 Correct 13 ms 3448 KB Output is correct
41 Correct 19 ms 7928 KB Output is correct
42 Correct 15 ms 7060 KB Output is correct
43 Correct 15 ms 7592 KB Output is correct
44 Correct 18 ms 8340 KB Output is correct
45 Correct 30 ms 8696 KB Output is correct
46 Correct 24 ms 8696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 400 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 380 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 508 KB Output is correct
10 Correct 2 ms 632 KB Output is correct
11 Correct 3 ms 632 KB Output is correct
12 Correct 3 ms 632 KB Output is correct
13 Correct 3 ms 760 KB Output is correct
14 Correct 4 ms 760 KB Output is correct
15 Correct 3 ms 760 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 7 ms 3064 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 504 KB Output is correct
20 Correct 11 ms 7800 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 9 ms 5752 KB Output is correct
24 Correct 10 ms 7032 KB Output is correct
25 Correct 4 ms 1912 KB Output is correct
26 Correct 10 ms 6648 KB Output is correct
27 Correct 10 ms 7032 KB Output is correct
28 Correct 12 ms 7804 KB Output is correct
29 Correct 12 ms 7800 KB Output is correct
30 Correct 11 ms 7672 KB Output is correct
31 Correct 13 ms 7672 KB Output is correct
32 Correct 13 ms 7800 KB Output is correct
33 Correct 14 ms 7800 KB Output is correct
34 Correct 13 ms 7800 KB Output is correct
35 Correct 16 ms 6164 KB Output is correct
36 Correct 6 ms 2936 KB Output is correct
37 Correct 17 ms 8056 KB Output is correct
38 Correct 20 ms 8440 KB Output is correct
39 Correct 11 ms 1272 KB Output is correct
40 Correct 13 ms 3448 KB Output is correct
41 Correct 19 ms 7928 KB Output is correct
42 Correct 15 ms 7032 KB Output is correct
43 Correct 15 ms 7516 KB Output is correct
44 Correct 17 ms 8312 KB Output is correct
45 Correct 30 ms 8788 KB Output is correct
46 Correct 25 ms 8696 KB Output is correct
47 Correct 40 ms 25976 KB Output is correct
48 Correct 10 ms 1656 KB Output is correct
49 Correct 10 ms 1660 KB Output is correct
50 Correct 8 ms 1528 KB Output is correct
51 Correct 118 ms 85368 KB Output is correct
52 Correct 124 ms 90872 KB Output is correct
53 Correct 32 ms 17656 KB Output is correct
54 Correct 72 ms 61304 KB Output is correct
55 Correct 93 ms 77944 KB Output is correct
56 Correct 141 ms 112380 KB Output is correct
57 Correct 5 ms 2808 KB Output is correct
58 Correct 139 ms 111724 KB Output is correct
59 Correct 132 ms 103904 KB Output is correct
60 Correct 144 ms 104068 KB Output is correct
61 Correct 125 ms 99064 KB Output is correct
62 Correct 192 ms 112480 KB Output is correct
63 Correct 250 ms 111876 KB Output is correct
64 Correct 264 ms 111996 KB Output is correct
65 Correct 312 ms 112020 KB Output is correct
66 Correct 472 ms 112504 KB Output is correct
67 Correct 299 ms 112508 KB Output is correct