답안 #45533

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
45533 2018-04-15T05:12:08 Z gnoor Jakarta Skyscrapers (APIO15_skyscraper) C++17
10 / 100
764 ms 262144 KB
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>

using namespace std;

vector<int> pth[30100];
int dis[30100];

struct ei {
	int x,dis;
};

bool operator< (const ei &a, const ei &b) {
	return a.dis>b.dis;
}

int main () {
	int n,m;
	scanf("%d%d",&n,&m);
	int a,b;
	int s,t;
	for (int i=0;i<m;i++) {
		scanf("%d%d",&a,&b);
		pth[a].push_back(b);
		if (i==0) s=a;
		if (i==1) t=a;
	}
	for (int i=0;i<n;i++) {
		sort(pth[i].begin(),pth[i].end());
		pth[i].erase(unique(pth[i].begin(),pth[i].end()),pth[i].end());
	}
	memset(dis,63,sizeof(dis));
	dis[s]=0;
	priority_queue<ei> q;
	q.push(ei{s,0});
	int now,nowdis;
	while (!q.empty()) {
		now = q.top().x;
		nowdis = q.top().dis;
		q.pop();
		if (dis[now]<nowdis) continue;
		if (now==t) {
			printf("%d\n",dis[now]);
			return 0;
		}
		for (auto p:pth[now]) {
			for (int i=1;now+i*p<n;i++) {
				if (dis[now+i*p]<nowdis+i) continue;
				dis[now+i*p]=nowdis+i;
				q.push(ei{now+i*p,nowdis+i});
			}
			for (int i=1;now-i*p>=0;i++) {
				if (dis[now-i*p]<nowdis+i) continue;
				dis[now-i*p]=nowdis+i;
				q.push(ei{now-i*p,nowdis+i});
			}
		}
	}
	printf("-1\n");
	return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:22: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:26:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",&a,&b);
   ~~~~~^~~~~~~~~~~~~~
skyscraper.cpp:45:3: warning: 't' may be used uninitialized in this function [-Wmaybe-uninitialized]
   if (now==t) {
   ^~
skyscraper.cpp:38:9: warning: 's' may be used uninitialized in this function [-Wmaybe-uninitialized]
  q.push(ei{s,0});
         ^~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1144 KB Output is correct
2 Correct 2 ms 1144 KB Output is correct
3 Correct 2 ms 1176 KB Output is correct
4 Correct 2 ms 1252 KB Output is correct
5 Correct 2 ms 1300 KB Output is correct
6 Correct 2 ms 1328 KB Output is correct
7 Correct 2 ms 1328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1328 KB Output is correct
2 Correct 2 ms 1328 KB Output is correct
3 Correct 3 ms 1328 KB Output is correct
4 Correct 2 ms 1380 KB Output is correct
5 Correct 2 ms 1380 KB Output is correct
6 Correct 2 ms 1380 KB Output is correct
7 Correct 2 ms 1380 KB Output is correct
8 Correct 2 ms 1380 KB Output is correct
9 Correct 2 ms 1380 KB Output is correct
10 Correct 2 ms 1508 KB Output is correct
11 Correct 3 ms 1508 KB Output is correct
12 Correct 3 ms 1508 KB Output is correct
13 Runtime error 724 ms 262144 KB Execution killed with signal 11 (could be triggered by violating memory limits)
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 262144 KB Output is correct
2 Correct 2 ms 262144 KB Output is correct
3 Correct 3 ms 262144 KB Output is correct
4 Correct 2 ms 262144 KB Output is correct
5 Correct 2 ms 262144 KB Output is correct
6 Correct 2 ms 262144 KB Output is correct
7 Correct 2 ms 262144 KB Output is correct
8 Correct 2 ms 262144 KB Output is correct
9 Correct 2 ms 262144 KB Output is correct
10 Correct 3 ms 262144 KB Output is correct
11 Correct 4 ms 262144 KB Output is correct
12 Correct 3 ms 262144 KB Output is correct
13 Runtime error 764 ms 262144 KB Execution killed with signal 11 (could be triggered by violating memory limits)
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 262144 KB Output is correct
2 Correct 2 ms 262144 KB Output is correct
3 Correct 2 ms 262144 KB Output is correct
4 Correct 2 ms 262144 KB Output is correct
5 Correct 2 ms 262144 KB Output is correct
6 Correct 2 ms 262144 KB Output is correct
7 Correct 2 ms 262144 KB Output is correct
8 Correct 3 ms 262144 KB Output is correct
9 Correct 2 ms 262144 KB Output is correct
10 Correct 3 ms 262144 KB Output is correct
11 Correct 3 ms 262144 KB Output is correct
12 Correct 3 ms 262144 KB Output is correct
13 Runtime error 715 ms 262144 KB Execution killed with signal 11 (could be triggered by violating memory limits)
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 262144 KB Output is correct
2 Correct 2 ms 262144 KB Output is correct
3 Correct 2 ms 262144 KB Output is correct
4 Correct 3 ms 262144 KB Output is correct
5 Correct 3 ms 262144 KB Output is correct
6 Correct 3 ms 262144 KB Output is correct
7 Correct 2 ms 262144 KB Output is correct
8 Correct 2 ms 262144 KB Output is correct
9 Correct 2 ms 262144 KB Output is correct
10 Correct 2 ms 262144 KB Output is correct
11 Correct 3 ms 262144 KB Output is correct
12 Correct 3 ms 262144 KB Output is correct
13 Runtime error 730 ms 262144 KB Execution killed with signal 11 (could be triggered by violating memory limits)
14 Halted 0 ms 0 KB -