답안 #41514

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
41514 2018-02-18T02:51:03 Z wzy Jakarta Skyscrapers (APIO15_skyscraper) C++14
0 / 100
20 ms 21720 KB
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
vector<pii> adj[300005];
int  n, m;
set<int> p[300005];
long long d[300005];

int main(){
	scanf("%d%d" ,  &n,  &m);
	for(int i = 0 ; i <m ; i ++){
		int  b, x;
		scanf("%d%d" , &b , &x);
		p[b].insert(x);
	}
	for(int i = 0 ; i < n; i++){
		for(auto t : p[i]){
			for(int j = 1  ; j*t + i < n ; j++){
				adj[i].pb(pii(j , j*t+i));
				if(p[j*t + i].count(t)) break;
			}
			for(int j = 1 ; i - j*t >=0 ; j++){
				adj[i].pb(pii(j , i-j*t));
				if(p[i - j*t].count(t)) break;

			}	
		}
	}
	priority_queue<pii , vector<pii> , greater<pii> > pq;
	pq.push(pii(0 , 0));
	for(int i = 0 ; i< n; i++) d[i] = (long long) 1e18;
	d[0] = 0;
	while(!pq.empty()){
		pii u = pq.top();
		pq.pop();
		if(d[u.S] != u.F) continue;
		d[u.S] = u.F;
		for(int i = 0 ; i < adj[u.S].size() ; i++){
			pii v = adj[u.S][i];
			if(d[v.S] > u.F + v.F){
				d[v.S] = u.F + v.F;
				pq.push(pii(u.F + v.F , v.S));
			}
		}
	}
	if(d[1] == (int) 1e18) printf("%d\n" , -1);
	else{
		printf("%lld\n" , d[1]);
	}
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:42:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0 ; i < adj[u.S].size() ; i++){
                     ^
skyscraper.cpp:14:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d" ,  &n,  &m);
                          ^
skyscraper.cpp:17:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d" , &b , &x);
                          ^
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 21368 KB Output is correct
2 Correct 19 ms 21412 KB Output is correct
3 Incorrect 19 ms 21508 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 21524 KB Output is correct
2 Correct 18 ms 21576 KB Output is correct
3 Incorrect 19 ms 21708 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 21708 KB Output is correct
2 Correct 18 ms 21708 KB Output is correct
3 Incorrect 20 ms 21708 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 21708 KB Output is correct
2 Correct 19 ms 21708 KB Output is correct
3 Incorrect 19 ms 21720 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 21720 KB Output is correct
2 Correct 18 ms 21720 KB Output is correct
3 Incorrect 18 ms 21720 KB Output isn't correct
4 Halted 0 ms 0 KB -