Submission #470353

# Submission time Handle Problem Language Result Execution time Memory
470353 2021-09-03T15:14:32 Z robell Jakarta Skyscrapers (APIO15_skyscraper) C++17
36 / 100
1000 ms 64700 KB
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef long long ll;
#define int long long
#define pb push_back
#define eb emplace_back
#define countbits __builtin_popcount
#define beg0 __builtin_clz
#define terminal0 __builtin_ctz
int mod = 1e9+7;
void setIO(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
}
void setIO(string f){
	freopen((f+".in").c_str(),"r",stdin);
	freopen((f+".out").c_str(),"w",stdout);
	setIO();
}
int N, M;
vector<vector<pair<int,int>>> l;
vector<pair<int,int>> m;
int32_t main(){
	setIO();
	cin >> N >> M;
	for (int i=0;i<M;i++) l.pb(vector<pair<int,int>>());
	for (int i=0;i<M;i++){
		int pos; cin >> pos;
		int moves; cin >> moves;
		m.pb({pos,moves});
	}
	for (int i=0;i<M;i++){
		for (int j=0;j<M;j++){
			if (i==j) continue;
			if (abs(m[j].first-m[i].first)%m[i].second==0){
				l[i].pb({j,abs(m[j].first-m[i].first)/m[i].second});
			}
		}
	}
	int dp[M];
	for (int i=0;i<M;i++){dp[i]=1e9;}
	priority_queue<pair<int,int>> pq;
	pq.push({0,0});
	while (!pq.empty()){
		int dist = -pq.top().first;
		int ind = pq.top().second;
		pq.pop();
		for (pair<int,int> a:l[ind]){
			if (dp[a.first]>a.second+dist){
				dp[a.first]=a.second+dist;
				pq.push({-(a.second+dist),a.first});
			}
		}
	}
	if (dp[1]==1e9){
		cout << "-1\n";
	}else cout << dp[1] << "\n";
}

Compilation message

skyscraper.cpp: In function 'void setIO(std::string)':
skyscraper.cpp:20:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |  freopen((f+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:21:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |  freopen((f+".out").c_str(),"w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 1 ms 312 KB Output is correct
7 Correct 1 ms 312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 308 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 2 ms 460 KB Output is correct
11 Correct 32 ms 4684 KB Output is correct
12 Correct 81 ms 64200 KB Output is correct
13 Correct 78 ms 64532 KB Output is correct
14 Correct 28 ms 3260 KB Output is correct
15 Correct 28 ms 3280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 308 KB Output is correct
7 Correct 1 ms 312 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 2 ms 460 KB Output is correct
11 Correct 29 ms 4676 KB Output is correct
12 Correct 77 ms 64220 KB Output is correct
13 Correct 89 ms 64636 KB Output is correct
14 Correct 32 ms 3252 KB Output is correct
15 Correct 28 ms 3276 KB Output is correct
16 Correct 5 ms 844 KB Output is correct
17 Correct 24 ms 1708 KB Output is correct
18 Correct 7 ms 332 KB Output is correct
19 Correct 2 ms 332 KB Output is correct
20 Correct 78 ms 64700 KB Output is correct
21 Correct 8 ms 460 KB Output is correct
22 Correct 4 ms 312 KB Output is correct
23 Correct 7 ms 460 KB Output is correct
24 Correct 22 ms 680 KB Output is correct
25 Correct 24 ms 700 KB Output is correct
26 Correct 74 ms 58512 KB Output is correct
27 Correct 75 ms 60228 KB Output is correct
28 Correct 24 ms 844 KB Output is correct
29 Correct 5 ms 844 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 3 ms 460 KB Output is correct
32 Correct 2 ms 460 KB Output is correct
33 Correct 28 ms 3304 KB Output is correct
34 Correct 28 ms 3268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 316 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 2 ms 440 KB Output is correct
11 Correct 32 ms 4676 KB Output is correct
12 Correct 81 ms 64248 KB Output is correct
13 Correct 84 ms 64636 KB Output is correct
14 Correct 28 ms 3264 KB Output is correct
15 Correct 28 ms 3276 KB Output is correct
16 Correct 6 ms 844 KB Output is correct
17 Correct 21 ms 1660 KB Output is correct
18 Correct 6 ms 456 KB Output is correct
19 Correct 3 ms 324 KB Output is correct
20 Correct 88 ms 64636 KB Output is correct
21 Correct 8 ms 460 KB Output is correct
22 Correct 4 ms 332 KB Output is correct
23 Correct 6 ms 460 KB Output is correct
24 Correct 21 ms 692 KB Output is correct
25 Correct 23 ms 680 KB Output is correct
26 Correct 76 ms 58692 KB Output is correct
27 Correct 83 ms 60276 KB Output is correct
28 Correct 25 ms 800 KB Output is correct
29 Correct 5 ms 844 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 3 ms 460 KB Output is correct
32 Correct 2 ms 460 KB Output is correct
33 Correct 29 ms 3268 KB Output is correct
34 Correct 27 ms 3268 KB Output is correct
35 Execution timed out 1093 ms 19072 KB Time limit exceeded
36 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 316 KB Output is correct
10 Correct 2 ms 460 KB Output is correct
11 Correct 30 ms 4688 KB Output is correct
12 Correct 80 ms 64196 KB Output is correct
13 Correct 81 ms 64580 KB Output is correct
14 Correct 32 ms 3316 KB Output is correct
15 Correct 28 ms 3340 KB Output is correct
16 Correct 6 ms 856 KB Output is correct
17 Correct 21 ms 1584 KB Output is correct
18 Correct 6 ms 332 KB Output is correct
19 Correct 3 ms 332 KB Output is correct
20 Correct 78 ms 64596 KB Output is correct
21 Correct 8 ms 448 KB Output is correct
22 Correct 4 ms 332 KB Output is correct
23 Correct 6 ms 460 KB Output is correct
24 Correct 21 ms 736 KB Output is correct
25 Correct 26 ms 704 KB Output is correct
26 Correct 80 ms 58604 KB Output is correct
27 Correct 76 ms 60296 KB Output is correct
28 Correct 24 ms 836 KB Output is correct
29 Correct 5 ms 844 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 3 ms 460 KB Output is correct
32 Correct 2 ms 460 KB Output is correct
33 Correct 31 ms 3268 KB Output is correct
34 Correct 28 ms 3344 KB Output is correct
35 Execution timed out 1074 ms 19424 KB Time limit exceeded
36 Halted 0 ms 0 KB -