# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
657944 | 2022-11-11T17:56:16 Z | ssense | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 1000 ms | 2648 KB |
#include <bits/stdc++.h> #define startt ios_base::sync_with_stdio(false);cin.tie(0); typedef long long ll; using namespace std; #define vint vector<int> #define all(v) v.begin(), v.end() #define MOD 1000000007 #define MOD2 998244353 #define MX 1000000000 #define MXL 1000000000000000000 #define PI (ld)2*acos(0.0) #define pb push_back #define sc second #define fr first #define int long long #define endl '\n' #define ld long double #define NO cout << "NO" << endl #define YES cout << "YES" << endl int ceildiv(int one, int two) {if (one % two == 0) {return one / two;}else {return one / two + 1;}} int power(int n, int pow, int m) {if (pow == 0) return 1;if (pow % 2 == 0) {ll x = power(n, pow / 2, m);return (x * x) % m;}else return (power(n, pow - 1, m) * n) % m;} int gcd(int a, int b) { if (!b)return a; return gcd(b, a % b);} int factorial(int n, int mod) {if (n > 1)return (n * factorial(n - 1, mod)) % mod; else return 1;} int lcm(int a, int b) {return (a * b) / gcd(a, b);} vector<int> read(int n) {vector<int> a; for (int i = 0; i < n; i++) { int x; cin >> x; a.pb(x);} return a;}struct prefix_sum{vint pref;void build(vint a){pref.pb(0);for(int i = 0; i < a.size(); i++){pref.pb(pref.back()+a[i]);}}int get(int l, int r){return pref[r]-pref[l-1];}};//mesanu void solve() { int n, m; cin >> n >> m; vector<vector<int>> a(n, vector<int>()); vint p(m); vector<int> dist(n, MX); int fin = 0; for(int i = 0; i < m; i++) { int x, b; cin >> x >> b; p[i] = b; a[x].pb(i); if(i == 0) { dist[x] = 0; } if(i == 1) { fin = x; } } for(int bruh = 0; bruh <= n; bruh++) { int changes = 0; for(int i = 0; i < n; i++) { for(int j = 0; j < a[i].size(); j++) { if(j == 0 || p[a[i][j]] != p[a[i][j-1]]) { for(int now = i%p[a[i][j]]; now < n; now+=p[a[i][j]]) { if(dist[i]+abs(now-i)/p[a[i][j]] < dist[now]) { changes++; dist[now] = dist[i]+abs(now-i)/p[a[i][j]]; } } } } } if(changes == 0) { break; } } if(dist[fin] == MX) { cout << -1 << endl; } else { cout << dist[fin] << endl; } } int32_t main(){ startt int t = 1; //cin >> t; while (t--) { solve(); } } /* 5 3 0 2 1 1 4 1 */
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 1 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 212 KB | Output is correct |
11 | Correct | 1 ms | 340 KB | Output is correct |
12 | Correct | 1 ms | 340 KB | Output is correct |
13 | Correct | 1 ms | 340 KB | Output is correct |
14 | Correct | 1 ms | 340 KB | Output is correct |
15 | Correct | 1 ms | 340 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 256 KB | Output is correct |
10 | Correct | 1 ms | 212 KB | Output is correct |
11 | Correct | 2 ms | 340 KB | Output is correct |
12 | Correct | 1 ms | 340 KB | Output is correct |
13 | Correct | 1 ms | 348 KB | Output is correct |
14 | Correct | 1 ms | 340 KB | Output is correct |
15 | Correct | 1 ms | 340 KB | Output is correct |
16 | Correct | 1 ms | 340 KB | Output is correct |
17 | Correct | 2 ms | 340 KB | Output is correct |
18 | Correct | 1 ms | 340 KB | Output is correct |
19 | Correct | 1 ms | 340 KB | Output is correct |
20 | Correct | 47 ms | 444 KB | Output is correct |
21 | Correct | 1 ms | 328 KB | Output is correct |
22 | Correct | 1 ms | 340 KB | Output is correct |
23 | Correct | 1 ms | 340 KB | Output is correct |
24 | Correct | 2 ms | 420 KB | Output is correct |
25 | Correct | 2 ms | 460 KB | Output is correct |
26 | Correct | 2 ms | 340 KB | Output is correct |
27 | Correct | 2 ms | 340 KB | Output is correct |
28 | Correct | 67 ms | 456 KB | Output is correct |
29 | Correct | 1 ms | 340 KB | Output is correct |
30 | Correct | 1 ms | 340 KB | Output is correct |
31 | Correct | 1 ms | 340 KB | Output is correct |
32 | Correct | 1 ms | 340 KB | Output is correct |
33 | Correct | 3 ms | 340 KB | Output is correct |
34 | Correct | 2 ms | 340 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 340 KB | Output is correct |
10 | Correct | 1 ms | 212 KB | Output is correct |
11 | Correct | 1 ms | 340 KB | Output is correct |
12 | Correct | 1 ms | 340 KB | Output is correct |
13 | Correct | 1 ms | 340 KB | Output is correct |
14 | Correct | 1 ms | 340 KB | Output is correct |
15 | Correct | 1 ms | 340 KB | Output is correct |
16 | Correct | 1 ms | 340 KB | Output is correct |
17 | Correct | 2 ms | 340 KB | Output is correct |
18 | Correct | 1 ms | 340 KB | Output is correct |
19 | Correct | 1 ms | 340 KB | Output is correct |
20 | Correct | 48 ms | 440 KB | Output is correct |
21 | Correct | 1 ms | 340 KB | Output is correct |
22 | Correct | 1 ms | 340 KB | Output is correct |
23 | Correct | 1 ms | 340 KB | Output is correct |
24 | Correct | 2 ms | 340 KB | Output is correct |
25 | Correct | 2 ms | 340 KB | Output is correct |
26 | Correct | 2 ms | 452 KB | Output is correct |
27 | Correct | 2 ms | 328 KB | Output is correct |
28 | Correct | 70 ms | 468 KB | Output is correct |
29 | Correct | 1 ms | 340 KB | Output is correct |
30 | Correct | 1 ms | 316 KB | Output is correct |
31 | Correct | 1 ms | 352 KB | Output is correct |
32 | Correct | 1 ms | 324 KB | Output is correct |
33 | Correct | 2 ms | 340 KB | Output is correct |
34 | Correct | 2 ms | 340 KB | Output is correct |
35 | Correct | 9 ms | 1108 KB | Output is correct |
36 | Correct | 2 ms | 468 KB | Output is correct |
37 | Correct | 12 ms | 968 KB | Output is correct |
38 | Correct | 12 ms | 1236 KB | Output is correct |
39 | Correct | 12 ms | 1248 KB | Output is correct |
40 | Correct | 12 ms | 1240 KB | Output is correct |
41 | Correct | 14 ms | 1248 KB | Output is correct |
42 | Correct | 5 ms | 1248 KB | Output is correct |
43 | Correct | 6 ms | 1120 KB | Output is correct |
44 | Correct | 54 ms | 1216 KB | Output is correct |
45 | Correct | 10 ms | 1236 KB | Output is correct |
46 | Correct | 10 ms | 1240 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 224 KB | Output is correct |
2 | Correct | 1 ms | 224 KB | Output is correct |
3 | Correct | 1 ms | 224 KB | Output is correct |
4 | Correct | 0 ms | 224 KB | Output is correct |
5 | Correct | 1 ms | 224 KB | Output is correct |
6 | Correct | 1 ms | 224 KB | Output is correct |
7 | Correct | 1 ms | 224 KB | Output is correct |
8 | Correct | 1 ms | 224 KB | Output is correct |
9 | Correct | 1 ms | 224 KB | Output is correct |
10 | Correct | 0 ms | 224 KB | Output is correct |
11 | Correct | 1 ms | 352 KB | Output is correct |
12 | Correct | 1 ms | 352 KB | Output is correct |
13 | Correct | 1 ms | 352 KB | Output is correct |
14 | Correct | 1 ms | 344 KB | Output is correct |
15 | Correct | 1 ms | 340 KB | Output is correct |
16 | Correct | 1 ms | 352 KB | Output is correct |
17 | Correct | 2 ms | 352 KB | Output is correct |
18 | Correct | 1 ms | 352 KB | Output is correct |
19 | Correct | 1 ms | 352 KB | Output is correct |
20 | Correct | 55 ms | 348 KB | Output is correct |
21 | Correct | 1 ms | 348 KB | Output is correct |
22 | Correct | 1 ms | 336 KB | Output is correct |
23 | Correct | 1 ms | 352 KB | Output is correct |
24 | Correct | 2 ms | 352 KB | Output is correct |
25 | Correct | 2 ms | 352 KB | Output is correct |
26 | Correct | 2 ms | 352 KB | Output is correct |
27 | Correct | 2 ms | 352 KB | Output is correct |
28 | Correct | 70 ms | 480 KB | Output is correct |
29 | Correct | 2 ms | 332 KB | Output is correct |
30 | Correct | 1 ms | 336 KB | Output is correct |
31 | Correct | 1 ms | 316 KB | Output is correct |
32 | Correct | 1 ms | 340 KB | Output is correct |
33 | Correct | 3 ms | 340 KB | Output is correct |
34 | Correct | 2 ms | 340 KB | Output is correct |
35 | Correct | 9 ms | 1056 KB | Output is correct |
36 | Correct | 2 ms | 468 KB | Output is correct |
37 | Correct | 11 ms | 976 KB | Output is correct |
38 | Correct | 12 ms | 1236 KB | Output is correct |
39 | Correct | 13 ms | 1236 KB | Output is correct |
40 | Correct | 12 ms | 1236 KB | Output is correct |
41 | Correct | 12 ms | 1236 KB | Output is correct |
42 | Correct | 5 ms | 1228 KB | Output is correct |
43 | Correct | 8 ms | 1272 KB | Output is correct |
44 | Correct | 53 ms | 1236 KB | Output is correct |
45 | Correct | 10 ms | 1236 KB | Output is correct |
46 | Correct | 10 ms | 1144 KB | Output is correct |
47 | Correct | 53 ms | 1500 KB | Output is correct |
48 | Correct | 9 ms | 1888 KB | Output is correct |
49 | Correct | 8 ms | 1956 KB | Output is correct |
50 | Correct | 6 ms | 1760 KB | Output is correct |
51 | Correct | 48 ms | 2460 KB | Output is correct |
52 | Correct | 56 ms | 2400 KB | Output is correct |
53 | Correct | 15 ms | 2392 KB | Output is correct |
54 | Correct | 1 ms | 1248 KB | Output is correct |
55 | Correct | 3 ms | 1224 KB | Output is correct |
56 | Execution timed out | 1073 ms | 2648 KB | Time limit exceeded |
57 | Halted | 0 ms | 0 KB | - |