Submission #389094

# Submission time Handle Problem Language Result Execution time Memory
389094 2021-04-13T15:49:41 Z talant117408 Jakarta Skyscrapers (APIO15_skyscraper) C++17
100 / 100
447 ms 112588 KB
/*
    Code written by Talant I.D.
*/
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
 
#define precision(n) fixed << setprecision(n)
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define eps (double)1e-9
#define PI 2*acos(0.0)
#define endl "\n"
#define sz(v) int((v).size())
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define OK cout << "OK" << endl;
 
const int mod = 998244353;
 
ll mode(ll a) {
    a %= mod;
    if (a < 0) a += mod;
    return a;
}
 
ll subt(ll a, ll b) {
    return mode(mode(a)-mode(b));
}
 
ll add(ll a, ll b) {
    return mode(mode(a)+mode(b));
}
 
ll mult(ll a, ll b) {
    return mode(mode(a)*mode(b));
}
 
ll binpow(ll a, ll b) {
    ll res = 1;
    while (b) {
        if (b&1) res = mult(res, a);
        a = mult(a, a);
        b >>= 1;
    }
    return res;
}

const int N = 3e4+7;
bitset <N> used, vis[N];
vector <int> powers[N];

int main() {
    do_not_disturb
    
    int n, m;
    cin >> n >> m;
    int b[m], p[m];
    for (int i = 0; i < m; i++) {
		cin >> b[i] >> p[i];
		powers[b[i]].pb(p[i]);
	}
    
    deque <array<int, 3>> K;
    K.pb({b[0], p[0], 0});
    
    while (!K.empty()) {
		auto v = K.front(); K.pop_front();
		vis[v[0]][v[1]] = 1;
		if (v[0] == b[1]) {
			cout << v[2] << endl;
			return 0;
		}
		if (!used[v[0]]) {
			for (auto to : powers[v[0]]) {
				if (vis[v[0]][to]) continue;
				vis[v[0]][to] = 1;
				K.push_front({v[0], to, v[2]});
			}
		}
		used[v[0]] = 1;
		if (v[0]+v[1] < n && vis[v[0]+v[1]][v[1]] == 0) {
			K.pb({v[0]+v[1], v[1], v[2]+1});
		}
		if (v[0]-v[1] >= 0 && vis[v[0]-v[1]][v[1]] == 0) {
			K.pb({v[0]-v[1], v[1], v[2]+1});
		}
	}
	cout << -1;
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 976 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
3 Correct 1 ms 972 KB Output is correct
4 Correct 1 ms 972 KB Output is correct
5 Correct 1 ms 1028 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 1 ms 972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 1 ms 1000 KB Output is correct
3 Correct 1 ms 972 KB Output is correct
4 Correct 1 ms 972 KB Output is correct
5 Correct 1 ms 972 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 1 ms 972 KB Output is correct
8 Correct 1 ms 972 KB Output is correct
9 Correct 1 ms 1032 KB Output is correct
10 Correct 1 ms 1156 KB Output is correct
11 Correct 1 ms 1072 KB Output is correct
12 Correct 1 ms 1300 KB Output is correct
13 Correct 1 ms 1356 KB Output is correct
14 Correct 2 ms 1356 KB Output is correct
15 Correct 1 ms 1356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
3 Correct 1 ms 972 KB Output is correct
4 Correct 1 ms 972 KB Output is correct
5 Correct 1 ms 1100 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 1 ms 972 KB Output is correct
8 Correct 1 ms 972 KB Output is correct
9 Correct 1 ms 1032 KB Output is correct
10 Correct 1 ms 1156 KB Output is correct
11 Correct 1 ms 1100 KB Output is correct
12 Correct 2 ms 1292 KB Output is correct
13 Correct 1 ms 1356 KB Output is correct
14 Correct 2 ms 1356 KB Output is correct
15 Correct 1 ms 1356 KB Output is correct
16 Correct 1 ms 1036 KB Output is correct
17 Correct 3 ms 3404 KB Output is correct
18 Correct 1 ms 972 KB Output is correct
19 Correct 1 ms 1036 KB Output is correct
20 Correct 6 ms 8396 KB Output is correct
21 Correct 1 ms 972 KB Output is correct
22 Correct 1 ms 972 KB Output is correct
23 Correct 5 ms 6348 KB Output is correct
24 Correct 6 ms 7500 KB Output is correct
25 Correct 2 ms 2452 KB Output is correct
26 Correct 5 ms 7372 KB Output is correct
27 Correct 6 ms 7628 KB Output is correct
28 Correct 7 ms 8472 KB Output is correct
29 Correct 7 ms 8396 KB Output is correct
30 Correct 6 ms 8268 KB Output is correct
31 Correct 6 ms 8396 KB Output is correct
32 Correct 7 ms 8268 KB Output is correct
33 Correct 10 ms 8396 KB Output is correct
34 Correct 8 ms 8396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
3 Correct 1 ms 972 KB Output is correct
4 Correct 1 ms 1036 KB Output is correct
5 Correct 1 ms 972 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 1 ms 972 KB Output is correct
8 Correct 1 ms 1032 KB Output is correct
9 Correct 1 ms 1100 KB Output is correct
10 Correct 1 ms 1100 KB Output is correct
11 Correct 1 ms 1100 KB Output is correct
12 Correct 1 ms 1296 KB Output is correct
13 Correct 2 ms 1356 KB Output is correct
14 Correct 2 ms 1356 KB Output is correct
15 Correct 1 ms 1296 KB Output is correct
16 Correct 1 ms 972 KB Output is correct
17 Correct 3 ms 3356 KB Output is correct
18 Correct 1 ms 972 KB Output is correct
19 Correct 1 ms 1100 KB Output is correct
20 Correct 6 ms 8344 KB Output is correct
21 Correct 1 ms 972 KB Output is correct
22 Correct 1 ms 972 KB Output is correct
23 Correct 6 ms 6360 KB Output is correct
24 Correct 6 ms 7512 KB Output is correct
25 Correct 2 ms 2392 KB Output is correct
26 Correct 7 ms 7384 KB Output is correct
27 Correct 6 ms 7632 KB Output is correct
28 Correct 7 ms 8408 KB Output is correct
29 Correct 8 ms 8360 KB Output is correct
30 Correct 6 ms 8268 KB Output is correct
31 Correct 7 ms 8268 KB Output is correct
32 Correct 6 ms 8268 KB Output is correct
33 Correct 9 ms 8400 KB Output is correct
34 Correct 8 ms 8396 KB Output is correct
35 Correct 12 ms 7036 KB Output is correct
36 Correct 3 ms 2196 KB Output is correct
37 Correct 9 ms 6732 KB Output is correct
38 Correct 11 ms 5016 KB Output is correct
39 Correct 8 ms 1740 KB Output is correct
40 Correct 9 ms 2764 KB Output is correct
41 Correct 9 ms 3328 KB Output is correct
42 Correct 9 ms 8012 KB Output is correct
43 Correct 10 ms 8268 KB Output is correct
44 Correct 11 ms 9036 KB Output is correct
45 Correct 24 ms 9368 KB Output is correct
46 Correct 17 ms 9224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
3 Correct 1 ms 1032 KB Output is correct
4 Correct 1 ms 972 KB Output is correct
5 Correct 1 ms 984 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 1 ms 972 KB Output is correct
8 Correct 1 ms 972 KB Output is correct
9 Correct 1 ms 1036 KB Output is correct
10 Correct 1 ms 1100 KB Output is correct
11 Correct 1 ms 1100 KB Output is correct
12 Correct 1 ms 1300 KB Output is correct
13 Correct 1 ms 1356 KB Output is correct
14 Correct 2 ms 1356 KB Output is correct
15 Correct 1 ms 1356 KB Output is correct
16 Correct 1 ms 972 KB Output is correct
17 Correct 3 ms 3404 KB Output is correct
18 Correct 1 ms 972 KB Output is correct
19 Correct 1 ms 1000 KB Output is correct
20 Correct 6 ms 8396 KB Output is correct
21 Correct 1 ms 972 KB Output is correct
22 Correct 1 ms 972 KB Output is correct
23 Correct 5 ms 6352 KB Output is correct
24 Correct 6 ms 7500 KB Output is correct
25 Correct 2 ms 2380 KB Output is correct
26 Correct 5 ms 7384 KB Output is correct
27 Correct 6 ms 7640 KB Output is correct
28 Correct 7 ms 8408 KB Output is correct
29 Correct 7 ms 8408 KB Output is correct
30 Correct 6 ms 8280 KB Output is correct
31 Correct 6 ms 8336 KB Output is correct
32 Correct 6 ms 8280 KB Output is correct
33 Correct 9 ms 8408 KB Output is correct
34 Correct 7 ms 8408 KB Output is correct
35 Correct 11 ms 6996 KB Output is correct
36 Correct 3 ms 2252 KB Output is correct
37 Correct 12 ms 6696 KB Output is correct
38 Correct 13 ms 5068 KB Output is correct
39 Correct 8 ms 1816 KB Output is correct
40 Correct 9 ms 2740 KB Output is correct
41 Correct 9 ms 3404 KB Output is correct
42 Correct 9 ms 7956 KB Output is correct
43 Correct 10 ms 8268 KB Output is correct
44 Correct 10 ms 8984 KB Output is correct
45 Correct 24 ms 9296 KB Output is correct
46 Correct 17 ms 9208 KB Output is correct
47 Correct 16 ms 10480 KB Output is correct
48 Correct 7 ms 1868 KB Output is correct
49 Correct 7 ms 1816 KB Output is correct
50 Correct 5 ms 1612 KB Output is correct
51 Correct 66 ms 81972 KB Output is correct
52 Correct 72 ms 90052 KB Output is correct
53 Correct 20 ms 18880 KB Output is correct
54 Correct 38 ms 61124 KB Output is correct
55 Correct 49 ms 77740 KB Output is correct
56 Correct 77 ms 112588 KB Output is correct
57 Correct 3 ms 2636 KB Output is correct
58 Correct 74 ms 111736 KB Output is correct
59 Correct 73 ms 104072 KB Output is correct
60 Correct 72 ms 103964 KB Output is correct
61 Correct 71 ms 98884 KB Output is correct
62 Correct 119 ms 112584 KB Output is correct
63 Correct 215 ms 111972 KB Output is correct
64 Correct 243 ms 111940 KB Output is correct
65 Correct 280 ms 112172 KB Output is correct
66 Correct 447 ms 112080 KB Output is correct
67 Correct 294 ms 112060 KB Output is correct