Submission #390282

# Submission time Handle Problem Language Result Execution time Memory
390282 2021-04-15T18:33:06 Z CSQ31 Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
110 ms 6552 KB
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(1e9+7)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);}
const int sq = 300;
vector<vector<bool>>has(30001,vector<bool>(300));
vii power(30001);
vector<int>dist(30001,1e9);
int main()
{
	owo
	int n,m;
	cin>>n>>m;
	vector<int>b(m),p(m);
	for(int i=0;i<m;i++){
		cin>>b[i]>>p[i];
		if(p[i] < sq){
			if(!has[b[i]][p[i]])power[b[i]].pb(p[i]);
			has[b[i]][p[i]] = 1;
		}else{
			power[b[i]].pb(p[i]);
		}
	}
	dist[b[0]] = 0;
	priority_queue<pii,vector<pii>,greater<pii>>pq;
	pq.push({0,b[0]});
	while(!pq.empty()){
		int v = pq.top().se;
		int d = pq.top().fi;
		pq.pop();
		if(d != dist[v])continue;
		if(v == b[1]){
			cout<<d;
			return 0;
		}
		//cout<<v<<" "<<d<<'\n';
		for(int p:power[v]){
			for(int x=v+p;x<n;x+=p){
				if(d + (x-v)/p < dist[x]){
					dist[x] = d + (x-v)/p;
					pq.push({dist[x],x});
				} 
				if(p < sq && has[x][p])break; //has power no need to look further
			} 
			for(int x=v-p;x>=0;x-=p){
				if(d + (v-x)/p < dist[x]){
					dist[x] = d + (v-x)/p;
					pq.push({dist[x],x});
				} 
				if(p < sq && has[x][p])break; //has power no need to look further
			} 
		}
		
	}
	cout<<-1;

	
	
}
# Verdict Execution time Memory Grader output
1 Correct 8 ms 3660 KB Output is correct
2 Correct 8 ms 3660 KB Output is correct
3 Correct 8 ms 3660 KB Output is correct
4 Correct 8 ms 3740 KB Output is correct
5 Correct 8 ms 3692 KB Output is correct
6 Correct 8 ms 3652 KB Output is correct
7 Correct 8 ms 3660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 3736 KB Output is correct
2 Correct 8 ms 3660 KB Output is correct
3 Correct 8 ms 3660 KB Output is correct
4 Correct 10 ms 3632 KB Output is correct
5 Correct 8 ms 3736 KB Output is correct
6 Correct 9 ms 3660 KB Output is correct
7 Correct 8 ms 3660 KB Output is correct
8 Correct 8 ms 3660 KB Output is correct
9 Correct 8 ms 3660 KB Output is correct
10 Correct 8 ms 3648 KB Output is correct
11 Correct 8 ms 3744 KB Output is correct
12 Correct 9 ms 3724 KB Output is correct
13 Correct 8 ms 3660 KB Output is correct
14 Correct 9 ms 3744 KB Output is correct
15 Correct 9 ms 3736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 3660 KB Output is correct
2 Correct 8 ms 3700 KB Output is correct
3 Correct 8 ms 3720 KB Output is correct
4 Correct 8 ms 3660 KB Output is correct
5 Correct 8 ms 3660 KB Output is correct
6 Correct 8 ms 3696 KB Output is correct
7 Correct 8 ms 3660 KB Output is correct
8 Correct 10 ms 3660 KB Output is correct
9 Correct 9 ms 3660 KB Output is correct
10 Correct 10 ms 3736 KB Output is correct
11 Correct 8 ms 3748 KB Output is correct
12 Correct 9 ms 3660 KB Output is correct
13 Correct 9 ms 3660 KB Output is correct
14 Correct 9 ms 3688 KB Output is correct
15 Correct 9 ms 3660 KB Output is correct
16 Correct 9 ms 3668 KB Output is correct
17 Correct 9 ms 3788 KB Output is correct
18 Correct 8 ms 3740 KB Output is correct
19 Correct 8 ms 3664 KB Output is correct
20 Correct 9 ms 3744 KB Output is correct
21 Correct 8 ms 3660 KB Output is correct
22 Correct 9 ms 3740 KB Output is correct
23 Correct 9 ms 3680 KB Output is correct
24 Correct 9 ms 3788 KB Output is correct
25 Correct 9 ms 3740 KB Output is correct
26 Correct 8 ms 3660 KB Output is correct
27 Correct 8 ms 3660 KB Output is correct
28 Correct 9 ms 3788 KB Output is correct
29 Correct 10 ms 3868 KB Output is correct
30 Correct 9 ms 3824 KB Output is correct
31 Correct 9 ms 3788 KB Output is correct
32 Correct 9 ms 3768 KB Output is correct
33 Correct 11 ms 3916 KB Output is correct
34 Correct 11 ms 3992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 3660 KB Output is correct
2 Correct 8 ms 3640 KB Output is correct
3 Correct 8 ms 3632 KB Output is correct
4 Correct 10 ms 3728 KB Output is correct
5 Correct 8 ms 3660 KB Output is correct
6 Correct 8 ms 3660 KB Output is correct
7 Correct 8 ms 3660 KB Output is correct
8 Correct 8 ms 3732 KB Output is correct
9 Correct 8 ms 3692 KB Output is correct
10 Correct 8 ms 3660 KB Output is correct
11 Correct 9 ms 3744 KB Output is correct
12 Correct 8 ms 3660 KB Output is correct
13 Correct 8 ms 3744 KB Output is correct
14 Correct 8 ms 3736 KB Output is correct
15 Correct 9 ms 3660 KB Output is correct
16 Correct 8 ms 3740 KB Output is correct
17 Correct 9 ms 3748 KB Output is correct
18 Correct 9 ms 3740 KB Output is correct
19 Correct 8 ms 3660 KB Output is correct
20 Correct 9 ms 3788 KB Output is correct
21 Correct 8 ms 3760 KB Output is correct
22 Correct 8 ms 3660 KB Output is correct
23 Correct 9 ms 3788 KB Output is correct
24 Correct 11 ms 3740 KB Output is correct
25 Correct 9 ms 3748 KB Output is correct
26 Correct 10 ms 3744 KB Output is correct
27 Correct 8 ms 3660 KB Output is correct
28 Correct 9 ms 3736 KB Output is correct
29 Correct 11 ms 3916 KB Output is correct
30 Correct 9 ms 3788 KB Output is correct
31 Correct 9 ms 3772 KB Output is correct
32 Correct 9 ms 3788 KB Output is correct
33 Correct 11 ms 3916 KB Output is correct
34 Correct 10 ms 3904 KB Output is correct
35 Correct 15 ms 4308 KB Output is correct
36 Correct 9 ms 3788 KB Output is correct
37 Correct 14 ms 4260 KB Output is correct
38 Correct 15 ms 4560 KB Output is correct
39 Correct 15 ms 4380 KB Output is correct
40 Correct 15 ms 4448 KB Output is correct
41 Correct 15 ms 4516 KB Output is correct
42 Correct 13 ms 4072 KB Output is correct
43 Correct 13 ms 4172 KB Output is correct
44 Correct 13 ms 4176 KB Output is correct
45 Correct 19 ms 4596 KB Output is correct
46 Correct 18 ms 4556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 3660 KB Output is correct
2 Correct 8 ms 3660 KB Output is correct
3 Correct 8 ms 3660 KB Output is correct
4 Correct 8 ms 3732 KB Output is correct
5 Correct 8 ms 3660 KB Output is correct
6 Correct 8 ms 3660 KB Output is correct
7 Correct 10 ms 3664 KB Output is correct
8 Correct 8 ms 3732 KB Output is correct
9 Correct 10 ms 3660 KB Output is correct
10 Correct 8 ms 3688 KB Output is correct
11 Correct 9 ms 3660 KB Output is correct
12 Correct 11 ms 3712 KB Output is correct
13 Correct 8 ms 3660 KB Output is correct
14 Correct 10 ms 3788 KB Output is correct
15 Correct 8 ms 3744 KB Output is correct
16 Correct 8 ms 3660 KB Output is correct
17 Correct 9 ms 3704 KB Output is correct
18 Correct 8 ms 3740 KB Output is correct
19 Correct 8 ms 3700 KB Output is correct
20 Correct 9 ms 3788 KB Output is correct
21 Correct 8 ms 3680 KB Output is correct
22 Correct 9 ms 3660 KB Output is correct
23 Correct 9 ms 3788 KB Output is correct
24 Correct 9 ms 3816 KB Output is correct
25 Correct 9 ms 3788 KB Output is correct
26 Correct 8 ms 3748 KB Output is correct
27 Correct 9 ms 3660 KB Output is correct
28 Correct 10 ms 3740 KB Output is correct
29 Correct 10 ms 3916 KB Output is correct
30 Correct 9 ms 3788 KB Output is correct
31 Correct 11 ms 3788 KB Output is correct
32 Correct 9 ms 3728 KB Output is correct
33 Correct 13 ms 3920 KB Output is correct
34 Correct 12 ms 3916 KB Output is correct
35 Correct 15 ms 4368 KB Output is correct
36 Correct 9 ms 3856 KB Output is correct
37 Correct 14 ms 4252 KB Output is correct
38 Correct 15 ms 4520 KB Output is correct
39 Correct 16 ms 4428 KB Output is correct
40 Correct 15 ms 4460 KB Output is correct
41 Correct 15 ms 4556 KB Output is correct
42 Correct 14 ms 4084 KB Output is correct
43 Correct 13 ms 4172 KB Output is correct
44 Correct 14 ms 4220 KB Output is correct
45 Correct 17 ms 4584 KB Output is correct
46 Correct 17 ms 4556 KB Output is correct
47 Correct 19 ms 5144 KB Output is correct
48 Correct 14 ms 4516 KB Output is correct
49 Correct 14 ms 4560 KB Output is correct
50 Correct 12 ms 4296 KB Output is correct
51 Correct 25 ms 5492 KB Output is correct
52 Correct 28 ms 5448 KB Output is correct
53 Correct 18 ms 5068 KB Output is correct
54 Correct 10 ms 3864 KB Output is correct
55 Correct 10 ms 3984 KB Output is correct
56 Correct 24 ms 5112 KB Output is correct
57 Correct 12 ms 4172 KB Output is correct
58 Correct 15 ms 4300 KB Output is correct
59 Correct 16 ms 4332 KB Output is correct
60 Correct 16 ms 4428 KB Output is correct
61 Correct 18 ms 4428 KB Output is correct
62 Correct 26 ms 5124 KB Output is correct
63 Correct 53 ms 5572 KB Output is correct
64 Correct 58 ms 5516 KB Output is correct
65 Correct 74 ms 6540 KB Output is correct
66 Correct 110 ms 6500 KB Output is correct
67 Correct 103 ms 6552 KB Output is correct