Submission #1110710

# Submission time Handle Problem Language Result Execution time Memory
1110710 2024-11-10T08:48:57 Z nhphuc Jakarta Skyscrapers (APIO15_skyscraper) C++17
10 / 100
2 ms 4688 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define iii tuple<int, int, int>

const int N = 50007;
const int block = 316;

int n, m, b[N], v[N], pw[N], dp[N][block + 7], ans = -1;
priority_queue<iii, vector<iii>, greater<iii>> pq;

int32_t main (){
    ios::sync_with_stdio(false); cin.tie(nullptr);
    if (fopen("test.inp", "r")){
        freopen("test.inp", "r", stdin);
        freopen("test.out", "w", stdout);
    }
    cin >> n >> m;
    for (int i = 0; i < n; ++i)
        for (int j = 0; j <= block + 1; ++j)
            dp[i][j] = -1;
    for (int i = 1; i <= m; ++i){
        cin >> b[i] >> v[i];
        pw[b[i]] = v[i];
        if (i == 1)
            pq.push({0, b[i], v[i]});
    }
    while (pq.size()){
        auto P = pq.top(); pq.pop();
        int D = get<0>(P);
        int u = get<1>(P);
        int t = get<2>(P); t = min(t, block + 1);
        if (dp[u][t] != -1)
            continue;
        dp[u][t] = D;
        if (u == b[2])
            ans = min((ans == -1 ? (int)1e16 : ans), D);
        if (t <= block){
            if (u - t >= 0 && dp[u - t][t] == -1)
                pq.push(make_tuple(D + 1, u - t, t));
            if (u + t < n && dp[u + t][t] == -1)
                pq.push(make_tuple(D + 1, u + t, t));
        }
        int X = pw[u];
        if (X <= block){
            if (u - X >= 0 && dp[u - X][X] == -1)
                pq.push(make_tuple(D + 1, u - X, X));
            if (u + X < n && dp[u + X][X] == -1)
                pq.push(make_tuple(D + 1, u + X, X));
        } else {
            for (int i = u - X; i >= 0; i -= X)
                if (dp[i][block + 1] == -1)
                    pq.push(make_tuple(D + (u - i) / X, i, X));
            for (int i = u + X; i < n; i += X)
                if (dp[i][block + 1] == -1)
                    pq.push(make_tuple(D + (i - u) / X, i, X));
        }
    }
    cout << ans << "\n";
}

Compilation message

skyscraper.cpp: In function 'int32_t main()':
skyscraper.cpp:16:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |         freopen("test.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:17:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |         freopen("test.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2552 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 1 ms 2640 KB Output is correct
10 Correct 2 ms 4688 KB Output is correct
11 Incorrect 2 ms 4688 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 2 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2556 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 1 ms 2640 KB Output is correct
10 Correct 2 ms 4688 KB Output is correct
11 Incorrect 2 ms 4688 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 2 ms 2640 KB Output is correct
10 Correct 1 ms 4688 KB Output is correct
11 Incorrect 1 ms 4688 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 1 ms 2812 KB Output is correct
10 Correct 1 ms 4688 KB Output is correct
11 Incorrect 2 ms 4688 KB Output isn't correct
12 Halted 0 ms 0 KB -