답안 #243589

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
243589 2020-07-01T11:12:27 Z michao Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
240 ms 126676 KB
//              _      _                 
//             (_)    | |                
//    _ __ ___  _  ___| |__   __ _  ___  
//   | '_ ` _ \| |/ __| '_ \ / _` |/ _ \ 
//   | | | | | | | (__| | | | (_| | (_) |
//   |_| |_| |_|_|\___|_| |_|\__,_|\___/ 
//                                       
// 
#include <bits/stdc++.h>
#define int long long
#define mp make_pair
#define pb push_back
#define ld long double
#define pii pair<int,int>
#define sz(x) (int)x.size()
#define piii pair<pii,pii>
#define precise cout<<fixed<<setprecision(10)
#define st first
#define nd second
#define ins insert
#define vi vector<int>
#define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int MAX=30005;
const int inf=INT_MAX;
set<int>pos[MAX];
pii tab[MAX];
vector<pii>P[MAX];
int dp[MAX];
priority_queue<pii>q;
int32_t main()
{
  BOOST;
  int n,m;
  cin>>m>>n;
  for (int i=1;i<=n;i++)cin>>tab[i].st>>tab[i].nd,pos[tab[i].st].ins(tab[i].nd);
  
  for (int i=0;i<m;i++)
  {
  	for (auto it:pos[i])
  	{
  		for (int j=i+it;j<m;j+=it)
  		{
  			P[i].pb(mp(j,(j-i)/it));
  			if (pos[j].count(it))break;
  		}
  		
  		for (int j=i-it;j>=0;j-=it)
  		{
  			P[i].pb(mp(j,(i-j)/it));
  			if (pos[j].count(it))break;
  		}
  	}
  }
  	
  	for (int i=0;i<m;i++)dp[i]=inf;
  	dp[tab[1].st]=0;
  	q.push(mp(0,tab[1].st));
  	while (!q.empty())
  	{
  		pii akt=q.top();
  		q.pop();
  		akt.st=-akt.st;
  		if (dp[akt.nd]!=akt.st)continue;
  		for (auto it:P[akt.nd])
			{
  			if (akt.st+it.nd<dp[it.st])
  			{
  				dp[it.st]=akt.st+it.nd;
  				q.push(mp(-dp[it.st],it.st));
  			}
  		}
  	}
  if (dp[tab[2].st]==inf)dp[tab[2].st]=-1;
  cout<<dp[tab[2].st];
  return 0;
}

Compilation message

skyscraper.cpp:4:1: warning: multi-line comment [-Wcomment]
 //   | '_ ` _ \| |/ __| '_ \ / _` |/ _ \ 
 ^
skyscraper.cpp:24:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization ("O3")
 
skyscraper.cpp:25:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization ("unroll-loops")
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2432 KB Output is correct
2 Correct 6 ms 2432 KB Output is correct
3 Correct 6 ms 2432 KB Output is correct
4 Correct 6 ms 2432 KB Output is correct
5 Correct 6 ms 2432 KB Output is correct
6 Correct 8 ms 2560 KB Output is correct
7 Correct 6 ms 2432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2432 KB Output is correct
2 Correct 6 ms 2432 KB Output is correct
3 Correct 7 ms 2432 KB Output is correct
4 Correct 7 ms 2432 KB Output is correct
5 Correct 6 ms 2432 KB Output is correct
6 Correct 6 ms 2432 KB Output is correct
7 Correct 6 ms 2432 KB Output is correct
8 Correct 7 ms 2432 KB Output is correct
9 Correct 6 ms 2432 KB Output is correct
10 Correct 7 ms 2560 KB Output is correct
11 Correct 7 ms 2688 KB Output is correct
12 Correct 7 ms 2560 KB Output is correct
13 Correct 7 ms 2560 KB Output is correct
14 Correct 7 ms 2688 KB Output is correct
15 Correct 7 ms 2688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2468 KB Output is correct
2 Correct 6 ms 2432 KB Output is correct
3 Correct 7 ms 2560 KB Output is correct
4 Correct 6 ms 2432 KB Output is correct
5 Correct 7 ms 2432 KB Output is correct
6 Correct 7 ms 2432 KB Output is correct
7 Correct 6 ms 2432 KB Output is correct
8 Correct 6 ms 2432 KB Output is correct
9 Correct 6 ms 2432 KB Output is correct
10 Correct 6 ms 2560 KB Output is correct
11 Correct 7 ms 2688 KB Output is correct
12 Correct 6 ms 2560 KB Output is correct
13 Correct 7 ms 2560 KB Output is correct
14 Correct 7 ms 2688 KB Output is correct
15 Correct 7 ms 2688 KB Output is correct
16 Correct 7 ms 2560 KB Output is correct
17 Correct 8 ms 2944 KB Output is correct
18 Correct 7 ms 2688 KB Output is correct
19 Correct 7 ms 2560 KB Output is correct
20 Correct 7 ms 2688 KB Output is correct
21 Correct 7 ms 2560 KB Output is correct
22 Correct 7 ms 2688 KB Output is correct
23 Correct 7 ms 2688 KB Output is correct
24 Correct 8 ms 2944 KB Output is correct
25 Correct 8 ms 2816 KB Output is correct
26 Correct 8 ms 2816 KB Output is correct
27 Correct 7 ms 2688 KB Output is correct
28 Correct 8 ms 3072 KB Output is correct
29 Correct 10 ms 3968 KB Output is correct
30 Correct 7 ms 3072 KB Output is correct
31 Correct 8 ms 3456 KB Output is correct
32 Correct 8 ms 3200 KB Output is correct
33 Correct 11 ms 5016 KB Output is correct
34 Correct 11 ms 5016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2432 KB Output is correct
2 Correct 6 ms 2432 KB Output is correct
3 Correct 6 ms 2432 KB Output is correct
4 Correct 6 ms 2432 KB Output is correct
5 Correct 7 ms 2432 KB Output is correct
6 Correct 7 ms 2432 KB Output is correct
7 Correct 6 ms 2432 KB Output is correct
8 Correct 6 ms 2432 KB Output is correct
9 Correct 6 ms 2432 KB Output is correct
10 Correct 6 ms 2560 KB Output is correct
11 Correct 7 ms 2688 KB Output is correct
12 Correct 6 ms 2560 KB Output is correct
13 Correct 7 ms 2560 KB Output is correct
14 Correct 7 ms 2688 KB Output is correct
15 Correct 7 ms 2688 KB Output is correct
16 Correct 7 ms 2560 KB Output is correct
17 Correct 8 ms 2944 KB Output is correct
18 Correct 7 ms 2688 KB Output is correct
19 Correct 7 ms 2688 KB Output is correct
20 Correct 7 ms 2688 KB Output is correct
21 Correct 7 ms 2560 KB Output is correct
22 Correct 7 ms 2688 KB Output is correct
23 Correct 7 ms 2688 KB Output is correct
24 Correct 8 ms 2944 KB Output is correct
25 Correct 8 ms 2944 KB Output is correct
26 Correct 7 ms 2816 KB Output is correct
27 Correct 7 ms 2688 KB Output is correct
28 Correct 8 ms 3072 KB Output is correct
29 Correct 11 ms 3968 KB Output is correct
30 Correct 7 ms 3072 KB Output is correct
31 Correct 8 ms 3328 KB Output is correct
32 Correct 7 ms 3072 KB Output is correct
33 Correct 12 ms 5016 KB Output is correct
34 Correct 11 ms 5112 KB Output is correct
35 Correct 25 ms 6424 KB Output is correct
36 Correct 9 ms 3200 KB Output is correct
37 Correct 28 ms 8056 KB Output is correct
38 Correct 32 ms 8188 KB Output is correct
39 Correct 30 ms 8184 KB Output is correct
40 Correct 31 ms 8192 KB Output is correct
41 Correct 32 ms 8100 KB Output is correct
42 Correct 12 ms 3328 KB Output is correct
43 Correct 13 ms 3456 KB Output is correct
44 Correct 12 ms 3328 KB Output is correct
45 Correct 36 ms 12788 KB Output is correct
46 Correct 35 ms 12796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2432 KB Output is correct
2 Correct 6 ms 2432 KB Output is correct
3 Correct 7 ms 2432 KB Output is correct
4 Correct 6 ms 2432 KB Output is correct
5 Correct 6 ms 2432 KB Output is correct
6 Correct 6 ms 2432 KB Output is correct
7 Correct 7 ms 2432 KB Output is correct
8 Correct 6 ms 2432 KB Output is correct
9 Correct 6 ms 2432 KB Output is correct
10 Correct 6 ms 2560 KB Output is correct
11 Correct 8 ms 2688 KB Output is correct
12 Correct 6 ms 2560 KB Output is correct
13 Correct 7 ms 2560 KB Output is correct
14 Correct 7 ms 2688 KB Output is correct
15 Correct 7 ms 2688 KB Output is correct
16 Correct 7 ms 2688 KB Output is correct
17 Correct 8 ms 2944 KB Output is correct
18 Correct 7 ms 2688 KB Output is correct
19 Correct 7 ms 2688 KB Output is correct
20 Correct 7 ms 2688 KB Output is correct
21 Correct 7 ms 2560 KB Output is correct
22 Correct 7 ms 2688 KB Output is correct
23 Correct 7 ms 2688 KB Output is correct
24 Correct 8 ms 2944 KB Output is correct
25 Correct 8 ms 2816 KB Output is correct
26 Correct 7 ms 2816 KB Output is correct
27 Correct 7 ms 2688 KB Output is correct
28 Correct 8 ms 3072 KB Output is correct
29 Correct 9 ms 3840 KB Output is correct
30 Correct 8 ms 3072 KB Output is correct
31 Correct 8 ms 3328 KB Output is correct
32 Correct 8 ms 3072 KB Output is correct
33 Correct 12 ms 5016 KB Output is correct
34 Correct 11 ms 5016 KB Output is correct
35 Correct 25 ms 6400 KB Output is correct
36 Correct 10 ms 3200 KB Output is correct
37 Correct 28 ms 7936 KB Output is correct
38 Correct 33 ms 8192 KB Output is correct
39 Correct 32 ms 8312 KB Output is correct
40 Correct 32 ms 8184 KB Output is correct
41 Correct 32 ms 8064 KB Output is correct
42 Correct 12 ms 3456 KB Output is correct
43 Correct 12 ms 3328 KB Output is correct
44 Correct 12 ms 3328 KB Output is correct
45 Correct 35 ms 12796 KB Output is correct
46 Correct 34 ms 12796 KB Output is correct
47 Correct 65 ms 22000 KB Output is correct
48 Correct 29 ms 8704 KB Output is correct
49 Correct 24 ms 6912 KB Output is correct
50 Correct 20 ms 6544 KB Output is correct
51 Correct 52 ms 12176 KB Output is correct
52 Correct 60 ms 13464 KB Output is correct
53 Correct 29 ms 7800 KB Output is correct
54 Correct 9 ms 3580 KB Output is correct
55 Correct 10 ms 4600 KB Output is correct
56 Correct 20 ms 6136 KB Output is correct
57 Correct 50 ms 19952 KB Output is correct
58 Correct 15 ms 5364 KB Output is correct
59 Correct 18 ms 6008 KB Output is correct
60 Correct 20 ms 7288 KB Output is correct
61 Correct 18 ms 6008 KB Output is correct
62 Correct 37 ms 14712 KB Output is correct
63 Correct 96 ms 45804 KB Output is correct
64 Correct 103 ms 52724 KB Output is correct
65 Correct 136 ms 72168 KB Output is correct
66 Correct 235 ms 126660 KB Output is correct
67 Correct 240 ms 126676 KB Output is correct