답안 #925649

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
925649 2024-02-12T06:52:09 Z Baizho Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
185 ms 63308 KB
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
 
 #pragma GCC optimize("Ofast,unroll-loops,fast-math")
 #pragma GCC target("popcnt")
 
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pll;
 
#define sz size()
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define pb push_back
 
const int mod = ll(1e9)+7; //(b + (a%b)) % b (to mod -1%(10^9+7) correctly in c++ its -1 but its suppose to be 10^9+6
const ll MOD = 998244353;  // (a%mod)*(binpow(b,mod-2,mod) = (a/b)%mod
const int N = ll(3e4)+100;
const int M = ll(2e5) + 100;
const long long inf = 5e18;
const long double eps = 1e-15L;
 
ll lcm(ll a, ll b) { return (a / __gcd(a,b))*b; }
 
ll binpow(ll a, ll b, ll m) { ll res=1; a %= m; while(b>0){ if(b&1)res=(res * a) % m; a=(a * a) % m; b/=2; } return res%m;}
 
void Freopen(string Key){ freopen((Key+".in").c_str(), "r", stdin); freopen((Key+".out").c_str(), "w", stdout); }

int n, m, dis[N], b[N];
vector<pair<int, int> > g[N];
set<int> po[N];

void Baizho() {
	cin>>n>>m;
	for(int i = 0; i < m; i ++) {
		int p; cin>>b[i]>>p;
		po[b[i]].insert(p);
	}
	for(int i = 0; i < n; i ++) {
		for(auto p : po[i]) {
			int pos = i + p, cur = 1;
			while(pos < n) {
				g[i].pb({pos, cur});
				if(po[pos].find(p) != po[pos].end()) break;
				pos += p; cur += 1;
			}
			pos = i - p, cur = 1;
			while(pos >= 0) {
				g[i].pb({pos, cur});
				if(po[pos].find(p) != po[pos].end()) break;
				pos -= p; cur += 1;
			}
		}
	}
	for(int i = 0; i <= n; i ++) dis[i] = 1e9;
	dis[b[0]] = 0;
	set<pair<int, int> > st;
	st.insert({dis[b[0]], b[0]});
	while(!st.empty()) {
		int v = (*st.begin()).ss;
		st.erase(st.begin());
		for(auto got: g[v]) {
			int to = got.ff, w = got.ss;
			if(dis[to] > dis[v] + w) {
				if(dis[to] != 1e9) st.erase({dis[to], to});
				dis[to] = dis[v] + w;
				st.insert({dis[to], to});
			}
		}
	}
	if(dis[b[1]] == 1e9) dis[b[1]] = -1;
	cout<<dis[b[1]];
}
 
signed main() {		
// 	Freopen("nondec");
    ios_base::sync_with_stdio(false);   
    cin.tie(0);cout.tie(0); 
//   	precalc();
   	
    int ttt = 1;
//    cin>>ttt;
 
    for(int i=1; i<=ttt; i++) {Baizho(); }
}

Compilation message

skyscraper.cpp: In function 'void Freopen(std::string)':
skyscraper.cpp:35:34: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 | void Freopen(string Key){ freopen((Key+".in").c_str(), "r", stdin); freopen((Key+".out").c_str(), "w", stdout); }
      |                           ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:35:76: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 | void Freopen(string Key){ freopen((Key+".in").c_str(), "r", stdin); freopen((Key+".out").c_str(), "w", stdout); }
      |                                                                     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2648 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2648 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2648 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2648 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 2 ms 2648 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 2 ms 2652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2648 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2900 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 2 ms 2652 KB Output is correct
15 Correct 1 ms 2648 KB Output is correct
16 Correct 1 ms 2652 KB Output is correct
17 Correct 2 ms 2904 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 1 ms 2652 KB Output is correct
20 Correct 1 ms 2648 KB Output is correct
21 Correct 1 ms 2648 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
23 Correct 1 ms 2652 KB Output is correct
24 Correct 2 ms 2908 KB Output is correct
25 Correct 2 ms 2908 KB Output is correct
26 Correct 1 ms 2652 KB Output is correct
27 Correct 1 ms 2652 KB Output is correct
28 Correct 2 ms 2908 KB Output is correct
29 Correct 4 ms 3164 KB Output is correct
30 Correct 2 ms 2908 KB Output is correct
31 Correct 3 ms 3164 KB Output is correct
32 Correct 2 ms 2908 KB Output is correct
33 Correct 6 ms 3976 KB Output is correct
34 Correct 6 ms 3984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 2 ms 2652 KB Output is correct
15 Correct 1 ms 2652 KB Output is correct
16 Correct 1 ms 2652 KB Output is correct
17 Correct 2 ms 2908 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 1 ms 2652 KB Output is correct
20 Correct 1 ms 2648 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
23 Correct 1 ms 2652 KB Output is correct
24 Correct 2 ms 2908 KB Output is correct
25 Correct 2 ms 2764 KB Output is correct
26 Correct 1 ms 2652 KB Output is correct
27 Correct 1 ms 2652 KB Output is correct
28 Correct 1 ms 2908 KB Output is correct
29 Correct 4 ms 3208 KB Output is correct
30 Correct 2 ms 2908 KB Output is correct
31 Correct 2 ms 2908 KB Output is correct
32 Correct 2 ms 2904 KB Output is correct
33 Correct 6 ms 3932 KB Output is correct
34 Correct 6 ms 3988 KB Output is correct
35 Correct 12 ms 4956 KB Output is correct
36 Correct 3 ms 3060 KB Output is correct
37 Correct 13 ms 5724 KB Output is correct
38 Correct 16 ms 5980 KB Output is correct
39 Correct 16 ms 6148 KB Output is correct
40 Correct 17 ms 5980 KB Output is correct
41 Correct 19 ms 5992 KB Output is correct
42 Correct 5 ms 2908 KB Output is correct
43 Correct 4 ms 2908 KB Output is correct
44 Correct 4 ms 2908 KB Output is correct
45 Correct 18 ms 8284 KB Output is correct
46 Correct 18 ms 8284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2648 KB Output is correct
10 Correct 1 ms 2648 KB Output is correct
11 Correct 1 ms 2648 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 1 ms 2652 KB Output is correct
16 Correct 1 ms 2652 KB Output is correct
17 Correct 2 ms 2908 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 1 ms 2648 KB Output is correct
20 Correct 1 ms 2652 KB Output is correct
21 Correct 1 ms 2648 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
23 Correct 1 ms 2652 KB Output is correct
24 Correct 2 ms 2916 KB Output is correct
25 Correct 2 ms 2916 KB Output is correct
26 Correct 1 ms 2660 KB Output is correct
27 Correct 1 ms 2660 KB Output is correct
28 Correct 2 ms 2916 KB Output is correct
29 Correct 4 ms 3428 KB Output is correct
30 Correct 3 ms 2916 KB Output is correct
31 Correct 2 ms 3172 KB Output is correct
32 Correct 2 ms 2908 KB Output is correct
33 Correct 6 ms 3932 KB Output is correct
34 Correct 6 ms 3932 KB Output is correct
35 Correct 12 ms 4936 KB Output is correct
36 Correct 3 ms 2908 KB Output is correct
37 Correct 15 ms 5716 KB Output is correct
38 Correct 16 ms 5980 KB Output is correct
39 Correct 16 ms 5980 KB Output is correct
40 Correct 17 ms 6064 KB Output is correct
41 Correct 16 ms 5956 KB Output is correct
42 Correct 4 ms 2908 KB Output is correct
43 Correct 4 ms 2908 KB Output is correct
44 Correct 4 ms 2908 KB Output is correct
45 Correct 18 ms 8320 KB Output is correct
46 Correct 18 ms 8536 KB Output is correct
47 Correct 45 ms 13136 KB Output is correct
48 Correct 11 ms 6360 KB Output is correct
49 Correct 9 ms 5468 KB Output is correct
50 Correct 8 ms 5144 KB Output is correct
51 Correct 43 ms 9176 KB Output is correct
52 Correct 42 ms 9308 KB Output is correct
53 Correct 16 ms 6612 KB Output is correct
54 Correct 3 ms 3672 KB Output is correct
55 Correct 4 ms 4052 KB Output is correct
56 Correct 8 ms 5212 KB Output is correct
57 Correct 49 ms 11956 KB Output is correct
58 Correct 7 ms 4308 KB Output is correct
59 Correct 8 ms 4824 KB Output is correct
60 Correct 9 ms 5336 KB Output is correct
61 Correct 9 ms 4828 KB Output is correct
62 Correct 16 ms 9444 KB Output is correct
63 Correct 70 ms 25756 KB Output is correct
64 Correct 82 ms 29260 KB Output is correct
65 Correct 93 ms 38348 KB Output is correct
66 Correct 185 ms 63292 KB Output is correct
67 Correct 179 ms 63308 KB Output is correct