Submission #400527

# Submission time Handle Problem Language Result Execution time Memory
400527 2021-05-08T09:07:55 Z Falcon Jakarta Skyscrapers (APIO15_skyscraper) C++17
57 / 100
1000 ms 2244 KB
#pragma GCC optimize("O2")

#include <bits/stdc++.h>

#ifdef DEBUG
#include "debug.hpp"
#endif

using namespace std;

#define all(c)              (c).begin(), (c).end()
#define rall(c)             (c).rbegin(), (c).rend()
#define traverse(c, it)     for(auto it = (c).begin(); it != (c).end(); ++it)
#define rep(i, N)           for(int i = 0; i < (N); ++i)
#define rrep(i, N)          for(int i = (N) - 1; i >= 0; --i)
#define rep1(i, N)          for(int i = 1; i <= (N); ++i)
#define rep2(i, s, e)       for(int i = (s); i <= (e); ++i)
#define rep3(i, s, e, d)    for(int i = (s); (d) >= 0 ? i <= (e) : i >= (e); i += (d))

#ifdef DEBUG
#define debug(x...)         { \
                            ++dbg::depth; \
                            string dbg_vals = dbg::to_string(x); \
                            --dbg::depth; \
                            dbg::fprint(__func__, __LINE__, #x, dbg_vals); \
                            }

#define light_debug(x)      { \
                            dbg::light = true; \
                            dbg::dout << __func__ << ":" << __LINE__; \
                            dbg::dout << "  " << #x << " = " << x << endl; \
                            dbg::light = false; \
                            }
#else
#define debug(x...)         42
#define light_debug(x)      42
#endif


using ll = long long;

template<typename T>
inline T& ckmin(T& a, T b) { return a = a > b ? b : a; }

template<typename T>
inline T& ckmax(T& a, T b) { return a = a < b ? b : a; }


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    #ifdef DEBUG
    freopen("debug", "w", stderr);
    #endif

    int N, M; cin >> N >> M;
    vector<int> P(M), B(M);
    rep(i, M) cin >> B[i] >> P[i];
    vector<vector<int>> B_t(N);
    rep(i, M) B_t[B[i]].push_back(i);

    vector<int> dist(N, -1); dist[B[0]] = 0;
    vector<bool> vis(N);
    

    while(!vis[B[1]]) {
        int u = -1;
        rep(i, N)
            if(!vis[i] && dist[i] != -1 && (u == -1 || dist[i] < dist[u]))
                u = i;

        debug(u);
        if(u == -1) break;

        int d = dist[u];
        vis[u] = true;

        for(int v : B_t[u]) {
            for(int p = u % P[v]; p < N; p += P[v]) {
                debug(u, v, p);
                if(!vis[p]) {
                    int dp = d + abs(p - u)/ P[v];
                    if(dist[p] == -1 || dist[p] > dp)
                        dist[p] = dp;
                }
            }
        }
    }

    
    cout << (vis[B[1]] ? dist[B[1]] : -1) << '\n';

    #ifdef DEBUG
    dbg::dout << "\nExecution time: " << clock() * 1000 / CLOCKS_PER_SEC  << "ms" << endl;
    #endif

    return 0;
}


Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:35:29: warning: statement has no effect [-Wunused-value]
   35 | #define debug(x...)         42
      |                             ^~
skyscraper.cpp:73:9: note: in expansion of macro 'debug'
   73 |         debug(u);
      |         ^~~~~
skyscraper.cpp:35:29: warning: statement has no effect [-Wunused-value]
   35 | #define debug(x...)         42
      |                             ^~
skyscraper.cpp:81:17: note: in expansion of macro 'debug'
   81 |                 debug(u, v, p);
      |                 ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 2 ms 316 KB Output is correct
13 Correct 2 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 312 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 2 ms 332 KB Output is correct
14 Correct 1 ms 324 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 1 ms 324 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 26 ms 460 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 6 ms 332 KB Output is correct
24 Correct 8 ms 332 KB Output is correct
25 Correct 3 ms 332 KB Output is correct
26 Correct 5 ms 332 KB Output is correct
27 Correct 15 ms 412 KB Output is correct
28 Correct 8 ms 452 KB Output is correct
29 Correct 10 ms 392 KB Output is correct
30 Correct 10 ms 380 KB Output is correct
31 Correct 9 ms 332 KB Output is correct
32 Correct 10 ms 388 KB Output is correct
33 Correct 10 ms 332 KB Output is correct
34 Correct 10 ms 416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 2 ms 332 KB Output is correct
13 Correct 2 ms 336 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 26 ms 460 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 6 ms 332 KB Output is correct
24 Correct 8 ms 336 KB Output is correct
25 Correct 3 ms 344 KB Output is correct
26 Correct 5 ms 340 KB Output is correct
27 Correct 15 ms 460 KB Output is correct
28 Correct 9 ms 460 KB Output is correct
29 Correct 11 ms 392 KB Output is correct
30 Correct 9 ms 332 KB Output is correct
31 Correct 9 ms 332 KB Output is correct
32 Correct 10 ms 332 KB Output is correct
33 Correct 10 ms 332 KB Output is correct
34 Correct 10 ms 332 KB Output is correct
35 Correct 11 ms 844 KB Output is correct
36 Correct 3 ms 460 KB Output is correct
37 Correct 12 ms 884 KB Output is correct
38 Correct 11 ms 1100 KB Output is correct
39 Correct 8 ms 1100 KB Output is correct
40 Correct 8 ms 1048 KB Output is correct
41 Correct 9 ms 1100 KB Output is correct
42 Correct 10 ms 1052 KB Output is correct
43 Correct 164 ms 1032 KB Output is correct
44 Correct 115 ms 972 KB Output is correct
45 Correct 17 ms 976 KB Output is correct
46 Correct 18 ms 1036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 2 ms 332 KB Output is correct
13 Correct 2 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 3 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 27 ms 336 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 6 ms 332 KB Output is correct
24 Correct 8 ms 332 KB Output is correct
25 Correct 3 ms 332 KB Output is correct
26 Correct 6 ms 332 KB Output is correct
27 Correct 15 ms 332 KB Output is correct
28 Correct 7 ms 460 KB Output is correct
29 Correct 10 ms 388 KB Output is correct
30 Correct 9 ms 332 KB Output is correct
31 Correct 9 ms 316 KB Output is correct
32 Correct 9 ms 332 KB Output is correct
33 Correct 12 ms 412 KB Output is correct
34 Correct 11 ms 332 KB Output is correct
35 Correct 11 ms 844 KB Output is correct
36 Correct 3 ms 448 KB Output is correct
37 Correct 12 ms 884 KB Output is correct
38 Correct 11 ms 1020 KB Output is correct
39 Correct 9 ms 1100 KB Output is correct
40 Correct 8 ms 1016 KB Output is correct
41 Correct 10 ms 1100 KB Output is correct
42 Correct 10 ms 972 KB Output is correct
43 Correct 166 ms 972 KB Output is correct
44 Correct 115 ms 1016 KB Output is correct
45 Correct 17 ms 972 KB Output is correct
46 Correct 17 ms 972 KB Output is correct
47 Correct 187 ms 1424 KB Output is correct
48 Correct 8 ms 1740 KB Output is correct
49 Correct 7 ms 1880 KB Output is correct
50 Correct 6 ms 1612 KB Output is correct
51 Execution timed out 1091 ms 2244 KB Time limit exceeded
52 Halted 0 ms 0 KB -