답안 #995499

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
995499 2024-06-09T07:34:43 Z Baytoro Jakarta Skyscrapers (APIO15_skyscraper) C++17
100 / 100
476 ms 5840 KB
#include <bits/stdc++.h>
using namespace std;
#define fr first
#define sc second
#define pb push_back
//#define int long long 
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
void fopn(string name){
	freopen((name+".in").c_str(),"r",stdin);
	freopen((name+".out").c_str(),"w",stdout);
}
#define ll long long
const int N=3e4+5;
set<int> g[N];
bool used[N];
int dist[N];
int n,m;
void solve(){
	int n,m;cin>>n>>m;
	vector<int> b(m),p(m);
	for(int i=0;i<N;i++) dist[i]=1e9;
	for(int i=0;i<m;i++){
		cin>>b[i]>>p[i];
		g[b[i]].insert(-p[i]);
	}
	priority_queue<pair<int,int>, vector<pair<int,int> >, greater<pair<int,int> > > pq;
	pq.push(make_pair(0,b[0]));
	dist[b[0]]=0;
	while(!pq.empty()){
		int d=pq.top().fr;
		int v=pq.top().sc;
		pq.pop();
		if(dist[v]!=d) continue;
		for(auto it: g[v]){
			for(int j=1;v+j*-it<n;j++){
				if(dist[v+j*-it]>d+j){
					dist[v+j*-it]=d+j;
					pq.push(make_pair(d+j,v+j*-it));
				}
			}
			for(int j=1;v-j*-it>=0;j++){
				if(dist[v-j*-it]>d+j){
					dist[v-j*-it]=d+j;
					pq.push(make_pair(d+j,v-j*-it));
				}
			}
		}
	}
	if(dist[b[1]]==1e9) dist[b[1]]=-1;
	cout<<dist[b[1]];
}
signed main(){
	//fopn("paint");
	int t=1;//cin>>t;
	while(t--) solve();
}

Compilation message

skyscraper.cpp: In function 'void fopn(std::string)':
skyscraper.cpp:10:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |  freopen((name+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:11:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |  freopen((name+".out").c_str(),"w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1884 KB Output is correct
2 Correct 1 ms 1884 KB Output is correct
3 Correct 1 ms 1884 KB Output is correct
4 Correct 1 ms 1884 KB Output is correct
5 Correct 1 ms 1884 KB Output is correct
6 Correct 1 ms 1884 KB Output is correct
7 Correct 1 ms 1884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1884 KB Output is correct
2 Correct 1 ms 1884 KB Output is correct
3 Correct 1 ms 1884 KB Output is correct
4 Correct 1 ms 1884 KB Output is correct
5 Correct 1 ms 2136 KB Output is correct
6 Correct 1 ms 1880 KB Output is correct
7 Correct 1 ms 1884 KB Output is correct
8 Correct 1 ms 1884 KB Output is correct
9 Correct 1 ms 1884 KB Output is correct
10 Correct 1 ms 1884 KB Output is correct
11 Correct 1 ms 1884 KB Output is correct
12 Correct 1 ms 1884 KB Output is correct
13 Correct 1 ms 1884 KB Output is correct
14 Correct 2 ms 1992 KB Output is correct
15 Correct 1 ms 1884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1884 KB Output is correct
2 Correct 1 ms 1884 KB Output is correct
3 Correct 1 ms 1884 KB Output is correct
4 Correct 2 ms 2136 KB Output is correct
5 Correct 1 ms 1884 KB Output is correct
6 Correct 1 ms 1884 KB Output is correct
7 Correct 1 ms 1884 KB Output is correct
8 Correct 1 ms 1884 KB Output is correct
9 Correct 1 ms 1884 KB Output is correct
10 Correct 1 ms 1884 KB Output is correct
11 Correct 1 ms 1884 KB Output is correct
12 Correct 2 ms 1884 KB Output is correct
13 Correct 1 ms 1884 KB Output is correct
14 Correct 2 ms 1932 KB Output is correct
15 Correct 2 ms 1884 KB Output is correct
16 Correct 1 ms 1884 KB Output is correct
17 Correct 2 ms 1884 KB Output is correct
18 Correct 1 ms 1884 KB Output is correct
19 Correct 1 ms 1884 KB Output is correct
20 Correct 4 ms 2100 KB Output is correct
21 Correct 1 ms 1884 KB Output is correct
22 Correct 1 ms 1884 KB Output is correct
23 Correct 1 ms 1884 KB Output is correct
24 Correct 2 ms 1884 KB Output is correct
25 Correct 2 ms 1884 KB Output is correct
26 Correct 1 ms 1884 KB Output is correct
27 Correct 2 ms 1884 KB Output is correct
28 Correct 2 ms 1884 KB Output is correct
29 Correct 2 ms 1884 KB Output is correct
30 Correct 1 ms 1884 KB Output is correct
31 Correct 2 ms 1880 KB Output is correct
32 Correct 2 ms 1884 KB Output is correct
33 Correct 2 ms 2140 KB Output is correct
34 Correct 3 ms 2140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1884 KB Output is correct
2 Correct 1 ms 1884 KB Output is correct
3 Correct 1 ms 1884 KB Output is correct
4 Correct 1 ms 1884 KB Output is correct
5 Correct 1 ms 1884 KB Output is correct
6 Correct 1 ms 1948 KB Output is correct
7 Correct 1 ms 1884 KB Output is correct
8 Correct 1 ms 1784 KB Output is correct
9 Correct 1 ms 1884 KB Output is correct
10 Correct 1 ms 1884 KB Output is correct
11 Correct 1 ms 1884 KB Output is correct
12 Correct 2 ms 1884 KB Output is correct
13 Correct 1 ms 1884 KB Output is correct
14 Correct 2 ms 1880 KB Output is correct
15 Correct 2 ms 1880 KB Output is correct
16 Correct 1 ms 1884 KB Output is correct
17 Correct 2 ms 1884 KB Output is correct
18 Correct 1 ms 1884 KB Output is correct
19 Correct 1 ms 1884 KB Output is correct
20 Correct 4 ms 1884 KB Output is correct
21 Correct 1 ms 1880 KB Output is correct
22 Correct 1 ms 1968 KB Output is correct
23 Correct 1 ms 1880 KB Output is correct
24 Correct 2 ms 1884 KB Output is correct
25 Correct 2 ms 1884 KB Output is correct
26 Correct 2 ms 1884 KB Output is correct
27 Correct 2 ms 1884 KB Output is correct
28 Correct 1 ms 1884 KB Output is correct
29 Correct 2 ms 1884 KB Output is correct
30 Correct 1 ms 1884 KB Output is correct
31 Correct 2 ms 1884 KB Output is correct
32 Correct 2 ms 1884 KB Output is correct
33 Correct 2 ms 2392 KB Output is correct
34 Correct 2 ms 2140 KB Output is correct
35 Correct 13 ms 3288 KB Output is correct
36 Correct 4 ms 2136 KB Output is correct
37 Correct 9 ms 3088 KB Output is correct
38 Correct 15 ms 3676 KB Output is correct
39 Correct 16 ms 3700 KB Output is correct
40 Correct 14 ms 3676 KB Output is correct
41 Correct 14 ms 3672 KB Output is correct
42 Correct 8 ms 2140 KB Output is correct
43 Correct 8 ms 2124 KB Output is correct
44 Correct 13 ms 2140 KB Output is correct
45 Correct 14 ms 3676 KB Output is correct
46 Correct 15 ms 3632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1880 KB Output is correct
2 Correct 1 ms 2136 KB Output is correct
3 Correct 1 ms 1884 KB Output is correct
4 Correct 1 ms 1884 KB Output is correct
5 Correct 1 ms 1884 KB Output is correct
6 Correct 1 ms 1884 KB Output is correct
7 Correct 1 ms 1880 KB Output is correct
8 Correct 1 ms 1884 KB Output is correct
9 Correct 1 ms 1884 KB Output is correct
10 Correct 1 ms 1884 KB Output is correct
11 Correct 1 ms 1884 KB Output is correct
12 Correct 1 ms 1884 KB Output is correct
13 Correct 1 ms 1884 KB Output is correct
14 Correct 1 ms 1884 KB Output is correct
15 Correct 1 ms 1884 KB Output is correct
16 Correct 1 ms 1884 KB Output is correct
17 Correct 2 ms 1884 KB Output is correct
18 Correct 1 ms 1884 KB Output is correct
19 Correct 1 ms 1884 KB Output is correct
20 Correct 4 ms 1884 KB Output is correct
21 Correct 1 ms 1884 KB Output is correct
22 Correct 1 ms 1884 KB Output is correct
23 Correct 1 ms 1880 KB Output is correct
24 Correct 2 ms 1884 KB Output is correct
25 Correct 2 ms 1884 KB Output is correct
26 Correct 1 ms 1884 KB Output is correct
27 Correct 2 ms 1884 KB Output is correct
28 Correct 1 ms 1884 KB Output is correct
29 Correct 2 ms 1884 KB Output is correct
30 Correct 1 ms 1884 KB Output is correct
31 Correct 1 ms 1884 KB Output is correct
32 Correct 1 ms 1884 KB Output is correct
33 Correct 3 ms 2140 KB Output is correct
34 Correct 2 ms 2140 KB Output is correct
35 Correct 14 ms 3420 KB Output is correct
36 Correct 3 ms 2140 KB Output is correct
37 Correct 10 ms 2904 KB Output is correct
38 Correct 15 ms 3704 KB Output is correct
39 Correct 16 ms 3580 KB Output is correct
40 Correct 14 ms 3668 KB Output is correct
41 Correct 15 ms 3596 KB Output is correct
42 Correct 8 ms 2140 KB Output is correct
43 Correct 8 ms 2140 KB Output is correct
44 Correct 10 ms 2140 KB Output is correct
45 Correct 14 ms 3676 KB Output is correct
46 Correct 15 ms 3676 KB Output is correct
47 Correct 17 ms 3808 KB Output is correct
48 Correct 10 ms 3164 KB Output is correct
49 Correct 9 ms 3088 KB Output is correct
50 Correct 7 ms 2652 KB Output is correct
51 Correct 26 ms 4580 KB Output is correct
52 Correct 27 ms 4564 KB Output is correct
53 Correct 18 ms 4568 KB Output is correct
54 Correct 2 ms 2140 KB Output is correct
55 Correct 2 ms 2140 KB Output is correct
56 Correct 476 ms 4188 KB Output is correct
57 Correct 34 ms 4200 KB Output is correct
58 Correct 8 ms 2392 KB Output is correct
59 Correct 10 ms 2692 KB Output is correct
60 Correct 11 ms 2652 KB Output is correct
61 Correct 11 ms 2596 KB Output is correct
62 Correct 13 ms 3928 KB Output is correct
63 Correct 30 ms 4820 KB Output is correct
64 Correct 30 ms 4820 KB Output is correct
65 Correct 34 ms 5840 KB Output is correct
66 Correct 50 ms 5828 KB Output is correct
67 Correct 44 ms 5832 KB Output is correct