답안 #409700

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
409700 2021-05-21T11:14:28 Z victoriad Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
942 ms 52064 KB
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <utility>
#include <queue>
#include <map>
#include <iomanip>
#include <stack>
#include <fstream>
using namespace std;
int n,m;
int N=3e4+5;
vector<vector<pair<int,int> > >g(N);
vector<vector<int> >pos(N);

struct nodo{
	int dis,bu,po;
	nodo(int dis=0,int bu=0,int po=0):dis(dis),bu(bu),po(po){

	}
};

bool operator<(const nodo& d,const nodo& i){
	if(d.dis!=i.dis)return d.dis<i.dis;
	if(d.bu!=i.bu)return d.bu<i.bu;
	return d.po<i.po;
}

bool operator>(const nodo& d,const nodo& i){
	if(d.dis!=i.dis)return d.dis>i.dis;
	if(d.bu!=i.bu)return d.bu>i.bu;
	return d.po>i.po;
}


int solve(int raiz,vector<int>&b,vector<int>&p){

priority_queue<nodo,vector<nodo>, greater<nodo> >pq;
vector<vector<int> >dist(N);
vector<int>r(raiz+1,1e9);
for(int i=0;i<N;i++)dist[i]=r;

dist[b[0]][0]=0;
pq.push(nodo(dist[b[0]][0],b[0],0));

while(!pq.empty()){
	nodo no=pq.top();
	pq.pop();
	if(dist[no.bu][no.po]<no.dis)continue;

	//if(no.bu==b[1])return no.dis;

	if(no.po!=0){

		if(dist[no.bu][0]>no.dis){
			dist[no.bu][0]=no.dis;
			pq.push(nodo(dist[no.bu][0],no.bu,0));
		}

		if(no.bu+no.po<=n-1){
			if(dist[no.bu+no.po][no.po]>no.dis+1){
				dist[no.bu+no.po][no.po]=no.dis+1;
				pq.push(nodo(dist[no.bu+no.po][no.po],no.bu+no.po,no.po));
			}
		}

		if(no.bu-no.po>=0){
			if(dist[no.bu-no.po][no.po]>no.dis+1){
				dist[no.bu-no.po][no.po]=no.dis+1;
				pq.push(nodo(dist[no.bu-no.po][no.po],no.bu-no.po,no.po));
			}
		}
	}
	else{

		for(int i=0;i<g[no.bu].size();i++){
		if(dist[g[no.bu][i].first][0]>no.dis+g[no.bu][i].second){
			dist[g[no.bu][i].first][0]=no.dis+g[no.bu][i].second;
			pq.push(nodo(dist[g[no.bu][i].first][0],g[no.bu][i].first,0));
		}	
		}

		for(int i=0;i<pos[no.bu].size();i++){
			if(dist[no.bu][pos[no.bu][i]]>no.dis){
				dist[no.bu][pos[no.bu][i]]=no.dis;
				pq.push(nodo(dist[no.bu][pos[no.bu][i]],no.bu,pos[no.bu][i]));
			}
		}

	}
}
if(dist[b[1]][0]==1e9)return -1;
return dist[b[1]][0];

}

void todascon(int power,int inicio){
int u=power+inicio,d=1;
while(u<=n-1){
	g[inicio].push_back(make_pair(u,d));
	u+=power;
	d++;
}
u=inicio-power;
d=1;
while(u>=0){
	g[inicio].push_back(make_pair(u,d));
	u-=power;
	d++;
}
}

int main(){
  ios::sync_with_stdio(false);
   cin.tie(NULL);
	cin>>n>>m;
	vector<int>b(m);
	vector<int>p(m);

	for(int i=0;i<m;i++)cin>>b[i]>>p[i];
	
	int raiz=sqrt(3e4+5);
	for(int i=0;i<m;i++){
		if(p[i]>raiz){
			todascon(p[i],b[i]);
		}
		else{
			pos[b[i]].push_back(p[i]);
		}
	}

	cout<<solve(raiz,b,p);
	 
  return 0;
}

Compilation message

skyscraper.cpp: In function 'int solve(int, std::vector<int>&, std::vector<int>&)':
skyscraper.cpp:78:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |   for(int i=0;i<g[no.bu].size();i++){
      |               ~^~~~~~~~~~~~~~~~
skyscraper.cpp:85:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |   for(int i=0;i<pos[no.bu].size();i++){
      |               ~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 22988 KB Output is correct
2 Correct 12 ms 22988 KB Output is correct
3 Correct 12 ms 23104 KB Output is correct
4 Correct 12 ms 23072 KB Output is correct
5 Correct 12 ms 23076 KB Output is correct
6 Correct 12 ms 23024 KB Output is correct
7 Correct 12 ms 23008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23108 KB Output is correct
2 Correct 13 ms 23012 KB Output is correct
3 Correct 12 ms 23028 KB Output is correct
4 Correct 12 ms 23040 KB Output is correct
5 Correct 12 ms 22988 KB Output is correct
6 Correct 13 ms 22988 KB Output is correct
7 Correct 14 ms 23044 KB Output is correct
8 Correct 13 ms 23092 KB Output is correct
9 Correct 13 ms 22988 KB Output is correct
10 Correct 13 ms 23112 KB Output is correct
11 Correct 14 ms 23148 KB Output is correct
12 Correct 13 ms 23108 KB Output is correct
13 Correct 13 ms 23124 KB Output is correct
14 Correct 14 ms 23124 KB Output is correct
15 Correct 14 ms 23124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 22996 KB Output is correct
2 Correct 14 ms 23084 KB Output is correct
3 Correct 12 ms 23044 KB Output is correct
4 Correct 14 ms 23100 KB Output is correct
5 Correct 13 ms 22988 KB Output is correct
6 Correct 12 ms 23068 KB Output is correct
7 Correct 12 ms 23064 KB Output is correct
8 Correct 12 ms 22988 KB Output is correct
9 Correct 12 ms 22988 KB Output is correct
10 Correct 13 ms 23104 KB Output is correct
11 Correct 14 ms 23116 KB Output is correct
12 Correct 13 ms 23116 KB Output is correct
13 Correct 13 ms 23116 KB Output is correct
14 Correct 13 ms 23100 KB Output is correct
15 Correct 16 ms 23096 KB Output is correct
16 Correct 14 ms 23136 KB Output is correct
17 Correct 19 ms 23116 KB Output is correct
18 Correct 13 ms 23116 KB Output is correct
19 Correct 13 ms 23116 KB Output is correct
20 Correct 14 ms 23112 KB Output is correct
21 Correct 13 ms 23136 KB Output is correct
22 Correct 13 ms 23116 KB Output is correct
23 Correct 14 ms 23116 KB Output is correct
24 Correct 15 ms 23168 KB Output is correct
25 Correct 14 ms 23128 KB Output is correct
26 Correct 13 ms 23116 KB Output is correct
27 Correct 14 ms 23156 KB Output is correct
28 Correct 15 ms 23132 KB Output is correct
29 Correct 19 ms 23120 KB Output is correct
30 Correct 14 ms 23096 KB Output is correct
31 Correct 17 ms 23132 KB Output is correct
32 Correct 15 ms 23116 KB Output is correct
33 Correct 26 ms 23196 KB Output is correct
34 Correct 26 ms 23116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 22988 KB Output is correct
2 Correct 13 ms 22988 KB Output is correct
3 Correct 12 ms 22976 KB Output is correct
4 Correct 13 ms 22988 KB Output is correct
5 Correct 14 ms 22988 KB Output is correct
6 Correct 13 ms 22988 KB Output is correct
7 Correct 13 ms 22988 KB Output is correct
8 Correct 13 ms 23068 KB Output is correct
9 Correct 13 ms 22988 KB Output is correct
10 Correct 13 ms 23116 KB Output is correct
11 Correct 15 ms 23096 KB Output is correct
12 Correct 13 ms 23116 KB Output is correct
13 Correct 13 ms 23028 KB Output is correct
14 Correct 14 ms 23088 KB Output is correct
15 Correct 14 ms 23156 KB Output is correct
16 Correct 14 ms 23080 KB Output is correct
17 Correct 15 ms 23116 KB Output is correct
18 Correct 13 ms 23116 KB Output is correct
19 Correct 13 ms 23116 KB Output is correct
20 Correct 13 ms 23172 KB Output is correct
21 Correct 13 ms 23116 KB Output is correct
22 Correct 13 ms 23120 KB Output is correct
23 Correct 14 ms 23032 KB Output is correct
24 Correct 15 ms 23116 KB Output is correct
25 Correct 14 ms 23184 KB Output is correct
26 Correct 14 ms 23116 KB Output is correct
27 Correct 14 ms 23080 KB Output is correct
28 Correct 17 ms 23060 KB Output is correct
29 Correct 20 ms 23116 KB Output is correct
30 Correct 15 ms 23108 KB Output is correct
31 Correct 16 ms 23116 KB Output is correct
32 Correct 15 ms 23116 KB Output is correct
33 Correct 25 ms 23196 KB Output is correct
34 Correct 25 ms 23116 KB Output is correct
35 Correct 27 ms 23944 KB Output is correct
36 Correct 16 ms 23244 KB Output is correct
37 Correct 35 ms 24384 KB Output is correct
38 Correct 37 ms 24444 KB Output is correct
39 Correct 33 ms 24384 KB Output is correct
40 Correct 34 ms 24436 KB Output is correct
41 Correct 37 ms 24380 KB Output is correct
42 Correct 23 ms 23628 KB Output is correct
43 Correct 18 ms 23684 KB Output is correct
44 Correct 18 ms 23608 KB Output is correct
45 Correct 79 ms 25800 KB Output is correct
46 Correct 71 ms 25808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23080 KB Output is correct
2 Correct 14 ms 23068 KB Output is correct
3 Correct 13 ms 23040 KB Output is correct
4 Correct 13 ms 22988 KB Output is correct
5 Correct 13 ms 22988 KB Output is correct
6 Correct 13 ms 23036 KB Output is correct
7 Correct 13 ms 22988 KB Output is correct
8 Correct 12 ms 23016 KB Output is correct
9 Correct 13 ms 23116 KB Output is correct
10 Correct 13 ms 23020 KB Output is correct
11 Correct 15 ms 23136 KB Output is correct
12 Correct 13 ms 23148 KB Output is correct
13 Correct 13 ms 23148 KB Output is correct
14 Correct 14 ms 23196 KB Output is correct
15 Correct 17 ms 23116 KB Output is correct
16 Correct 13 ms 23100 KB Output is correct
17 Correct 15 ms 23116 KB Output is correct
18 Correct 13 ms 23136 KB Output is correct
19 Correct 13 ms 23104 KB Output is correct
20 Correct 13 ms 23084 KB Output is correct
21 Correct 13 ms 23128 KB Output is correct
22 Correct 13 ms 23016 KB Output is correct
23 Correct 14 ms 23116 KB Output is correct
24 Correct 15 ms 23116 KB Output is correct
25 Correct 14 ms 23116 KB Output is correct
26 Correct 14 ms 23144 KB Output is correct
27 Correct 13 ms 23116 KB Output is correct
28 Correct 15 ms 23176 KB Output is correct
29 Correct 19 ms 23228 KB Output is correct
30 Correct 15 ms 23052 KB Output is correct
31 Correct 16 ms 23104 KB Output is correct
32 Correct 15 ms 23116 KB Output is correct
33 Correct 26 ms 23116 KB Output is correct
34 Correct 25 ms 23136 KB Output is correct
35 Correct 28 ms 23916 KB Output is correct
36 Correct 15 ms 23236 KB Output is correct
37 Correct 34 ms 24340 KB Output is correct
38 Correct 33 ms 24460 KB Output is correct
39 Correct 34 ms 24384 KB Output is correct
40 Correct 35 ms 24336 KB Output is correct
41 Correct 34 ms 24356 KB Output is correct
42 Correct 18 ms 23556 KB Output is correct
43 Correct 18 ms 23680 KB Output is correct
44 Correct 18 ms 23620 KB Output is correct
45 Correct 76 ms 25792 KB Output is correct
46 Correct 71 ms 25788 KB Output is correct
47 Correct 107 ms 27740 KB Output is correct
48 Correct 21 ms 24568 KB Output is correct
49 Correct 20 ms 24444 KB Output is correct
50 Correct 19 ms 24108 KB Output is correct
51 Correct 64 ms 25732 KB Output is correct
52 Correct 70 ms 25776 KB Output is correct
53 Correct 24 ms 23756 KB Output is correct
54 Correct 13 ms 23108 KB Output is correct
55 Correct 13 ms 23108 KB Output is correct
56 Correct 24 ms 24456 KB Output is correct
57 Correct 85 ms 23228 KB Output is correct
58 Correct 21 ms 23532 KB Output is correct
59 Correct 23 ms 23616 KB Output is correct
60 Correct 30 ms 23948 KB Output is correct
61 Correct 30 ms 23844 KB Output is correct
62 Correct 51 ms 25996 KB Output is correct
63 Correct 106 ms 46612 KB Output is correct
64 Correct 128 ms 51980 KB Output is correct
65 Correct 342 ms 52064 KB Output is correct
66 Correct 942 ms 48128 KB Output is correct
67 Correct 918 ms 48056 KB Output is correct