Submission #969817

# Submission time Handle Problem Language Result Execution time Memory
969817 2024-04-25T15:57:50 Z pcc Jakarta Skyscrapers (APIO15_skyscraper) C++17
22 / 100
137 ms 197504 KB
#include <bits/stdc++.h>
using namespace std;

#pragma GCC target("avx2,popcnt,sse4")
#pragma GCC optimize("O3,unroll-loops")
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>


const int inf = 1e9;
const int mxn = 3e4+10;
const int mxe = mxn*sqrt(mxn)*3;
const int mxv = mxe;

map<pii,vector<int>> mp;
int N,M;
int ecnt,vcnt;
int to[mxe],nid[mxe];
bool wei[mxe];
int head[mxv];
int dist[mxv];
int S,T;
int ts;

void add_edge(int a,int b,int w){
	ecnt++;
	nid[ecnt] = head[a];
	to[ecnt] = b;
	wei[ecnt] = w;
	head[a] = ecnt;
}

bitset<mxv> done;
deque<int> dq;

void BFS(){
	dq.resize(mxv*2);
	fill(dist,dist+mxv,inf);
	dist[S] = 0;
	dq.push_back(S);
	while(!dq.empty()){
		int now = dq.front();
		dq.pop_front();
		if(done[now])continue;
		if(now == T)break;
		done[now] = true;
		for(int eid = head[now];eid;eid = nid[eid]){
			int nxt = to[eid],w = wei[eid];
			//cout<<now<<' '<<nxt<<":"<<dist[now]+w<<' '<<dist[nxt]<<endl;
			if(!w){
				if(dist[nxt]>dist[now]){
					dist[nxt] = dist[now];
					dq.push_front(nxt);
				}
			}
			else{
				if(dist[nxt]>dist[now]+w){
					dist[nxt] = dist[now]+w;
					dq.push_back(nxt);
				}
			}
		}
	}
	return;
}


int main(){
	ts = clock();
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>N>>M;
	for(int i = 0;i<M;i++){
		pii tmp;
		cin>>tmp.fs>>tmp.sc;
		mp[pii(tmp.sc,tmp.fs%tmp.sc)].push_back(tmp.fs);
		if(!i)S = tmp.fs;
		if(i == 1)T = tmp.fs;
	}
	vcnt = N-1;
	for(auto &i:mp){
		sort(i.sc.rbegin(),i.sc.rend());
		for(int j = i.fs.sc;j<N;j+=i.fs.fs){
			vcnt++;
			add_edge(vcnt,j,0);
			while(!i.sc.empty()&&i.sc.back() == j){
				add_edge(i.sc.back(),vcnt,0);
				i.sc.pop_back();
			}
			if(j != i.fs.sc){
				add_edge(vcnt-1,vcnt,1);
				add_edge(vcnt,vcnt-1,1);
			}
		}
	}
	BFS();
	cout<<(dist[T]>=inf?-1:dist[T])<<'\n';
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 114 ms 197204 KB Output is correct
2 Correct 82 ms 196944 KB Output is correct
3 Correct 74 ms 197200 KB Output is correct
4 Correct 129 ms 196952 KB Output is correct
5 Correct 111 ms 197144 KB Output is correct
6 Correct 119 ms 197032 KB Output is correct
7 Correct 108 ms 197148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 118 ms 197204 KB Output is correct
2 Correct 83 ms 197172 KB Output is correct
3 Correct 82 ms 197360 KB Output is correct
4 Correct 111 ms 197196 KB Output is correct
5 Correct 112 ms 197160 KB Output is correct
6 Correct 126 ms 196956 KB Output is correct
7 Correct 111 ms 197164 KB Output is correct
8 Correct 110 ms 197204 KB Output is correct
9 Correct 113 ms 197204 KB Output is correct
10 Correct 125 ms 197184 KB Output is correct
11 Correct 114 ms 197336 KB Output is correct
12 Correct 109 ms 197200 KB Output is correct
13 Correct 109 ms 197196 KB Output is correct
14 Correct 112 ms 197216 KB Output is correct
15 Correct 122 ms 197204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 109 ms 196944 KB Output is correct
2 Correct 83 ms 197144 KB Output is correct
3 Correct 75 ms 196944 KB Output is correct
4 Correct 109 ms 197204 KB Output is correct
5 Correct 137 ms 197204 KB Output is correct
6 Correct 109 ms 197112 KB Output is correct
7 Correct 111 ms 196948 KB Output is correct
8 Correct 113 ms 197308 KB Output is correct
9 Correct 111 ms 197200 KB Output is correct
10 Correct 120 ms 197200 KB Output is correct
11 Correct 111 ms 197204 KB Output is correct
12 Correct 115 ms 197200 KB Output is correct
13 Correct 108 ms 197064 KB Output is correct
14 Correct 111 ms 197204 KB Output is correct
15 Correct 113 ms 197200 KB Output is correct
16 Correct 125 ms 197456 KB Output is correct
17 Correct 114 ms 197356 KB Output is correct
18 Correct 109 ms 197312 KB Output is correct
19 Correct 111 ms 197200 KB Output is correct
20 Correct 119 ms 197208 KB Output is correct
21 Correct 109 ms 197204 KB Output is correct
22 Correct 108 ms 197052 KB Output is correct
23 Correct 109 ms 197284 KB Output is correct
24 Correct 111 ms 197460 KB Output is correct
25 Correct 110 ms 197200 KB Output is correct
26 Correct 111 ms 197036 KB Output is correct
27 Correct 109 ms 197200 KB Output is correct
28 Incorrect 77 ms 197504 KB Output isn't correct
29 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 116 ms 197152 KB Output is correct
2 Correct 76 ms 197152 KB Output is correct
3 Correct 76 ms 197204 KB Output is correct
4 Correct 110 ms 196948 KB Output is correct
5 Correct 110 ms 197200 KB Output is correct
6 Correct 109 ms 196948 KB Output is correct
7 Correct 109 ms 196940 KB Output is correct
8 Correct 108 ms 197196 KB Output is correct
9 Correct 109 ms 197028 KB Output is correct
10 Correct 113 ms 197240 KB Output is correct
11 Correct 110 ms 197204 KB Output is correct
12 Correct 110 ms 197200 KB Output is correct
13 Correct 110 ms 197156 KB Output is correct
14 Correct 109 ms 197388 KB Output is correct
15 Correct 110 ms 197204 KB Output is correct
16 Correct 109 ms 197304 KB Output is correct
17 Correct 109 ms 197200 KB Output is correct
18 Correct 109 ms 197204 KB Output is correct
19 Correct 113 ms 197208 KB Output is correct
20 Correct 108 ms 197200 KB Output is correct
21 Correct 110 ms 197204 KB Output is correct
22 Correct 111 ms 197220 KB Output is correct
23 Correct 111 ms 197292 KB Output is correct
24 Correct 109 ms 197216 KB Output is correct
25 Correct 111 ms 197456 KB Output is correct
26 Correct 110 ms 197200 KB Output is correct
27 Correct 111 ms 197228 KB Output is correct
28 Incorrect 76 ms 197456 KB Output isn't correct
29 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 108 ms 196948 KB Output is correct
2 Correct 77 ms 197156 KB Output is correct
3 Correct 76 ms 197160 KB Output is correct
4 Correct 111 ms 197200 KB Output is correct
5 Correct 110 ms 197204 KB Output is correct
6 Correct 108 ms 196948 KB Output is correct
7 Correct 112 ms 197196 KB Output is correct
8 Correct 109 ms 197064 KB Output is correct
9 Correct 111 ms 197196 KB Output is correct
10 Correct 109 ms 197052 KB Output is correct
11 Correct 109 ms 197200 KB Output is correct
12 Correct 113 ms 197072 KB Output is correct
13 Correct 111 ms 197200 KB Output is correct
14 Correct 110 ms 197204 KB Output is correct
15 Correct 112 ms 197392 KB Output is correct
16 Correct 121 ms 197460 KB Output is correct
17 Correct 112 ms 197204 KB Output is correct
18 Correct 109 ms 197204 KB Output is correct
19 Correct 110 ms 197204 KB Output is correct
20 Correct 109 ms 197120 KB Output is correct
21 Correct 108 ms 197200 KB Output is correct
22 Correct 110 ms 197264 KB Output is correct
23 Correct 108 ms 197236 KB Output is correct
24 Correct 109 ms 197472 KB Output is correct
25 Correct 111 ms 197468 KB Output is correct
26 Correct 111 ms 197204 KB Output is correct
27 Correct 114 ms 197260 KB Output is correct
28 Incorrect 77 ms 197460 KB Output isn't correct
29 Halted 0 ms 0 KB -