답안 #1110740

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1110740 2024-11-10T09:49:49 Z nhphuc Jakarta Skyscrapers (APIO15_skyscraper) C++17
57 / 100
330 ms 262144 KB
#include <bits/stdc++.h>
using namespace std;

#define iii tuple<int, int, int>

const int N = 30500;
const int block = 200;

int n, m, b[N], v[N], dp[N][block + 7], ans = -1;
vector<int> pw[N];
vector<pair<int, int>> Q[N * block];

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]].push_back(v[i]);
        if (i == 1)
            Q[0].push_back({b[i], v[i]});
    }
    for (int D = 0; D < N * block; ++D){
        for (pair<int, int> it : Q[D]){
            int u = it.first;
            int t = it.second; 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)
                    Q[D + 1].push_back({u - t, t});
                if (u + t < n && dp[u + t][t] == -1)
                    Q[D + 1].push_back({u + t, t});
            }
            for (int X : pw[u]){
                if (X <= block){
                    if (u - X >= 0 && dp[u - X][X] == -1)
                        Q[D + 1].push_back({u - X, X});
                    if (u + X < n && dp[u + X][X] == -1)
                        Q[D + 1].push_back({u + X, X});
                } else {
                    for (int i = u - X; i >= 0; i -= X)
                        if (dp[i][block + 1] == -1)
                            Q[D + (u - i) / X].push_back({i, X});
                    for (int i = u + X; i < n; i += X)
                        if (dp[i][block + 1] == -1)
                            Q[D + (i - u) / X].push_back({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);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 61 ms 146256 KB Output is correct
2 Correct 66 ms 146248 KB Output is correct
3 Correct 71 ms 146196 KB Output is correct
4 Correct 73 ms 146248 KB Output is correct
5 Correct 71 ms 146244 KB Output is correct
6 Correct 82 ms 146260 KB Output is correct
7 Correct 81 ms 146248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 146248 KB Output is correct
2 Correct 68 ms 146248 KB Output is correct
3 Correct 75 ms 146116 KB Output is correct
4 Correct 69 ms 146248 KB Output is correct
5 Correct 69 ms 146208 KB Output is correct
6 Correct 69 ms 146084 KB Output is correct
7 Correct 67 ms 146260 KB Output is correct
8 Correct 67 ms 146248 KB Output is correct
9 Correct 81 ms 146296 KB Output is correct
10 Correct 79 ms 146248 KB Output is correct
11 Correct 85 ms 146504 KB Output is correct
12 Correct 67 ms 146344 KB Output is correct
13 Correct 75 ms 146224 KB Output is correct
14 Correct 75 ms 146504 KB Output is correct
15 Correct 77 ms 146608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 69 ms 146248 KB Output is correct
2 Correct 86 ms 146248 KB Output is correct
3 Correct 88 ms 146248 KB Output is correct
4 Correct 79 ms 146176 KB Output is correct
5 Correct 74 ms 146316 KB Output is correct
6 Correct 70 ms 146248 KB Output is correct
7 Correct 73 ms 146156 KB Output is correct
8 Correct 74 ms 146296 KB Output is correct
9 Correct 69 ms 146144 KB Output is correct
10 Correct 69 ms 146300 KB Output is correct
11 Correct 73 ms 146508 KB Output is correct
12 Correct 100 ms 146352 KB Output is correct
13 Correct 94 ms 146248 KB Output is correct
14 Correct 79 ms 146412 KB Output is correct
15 Correct 85 ms 146544 KB Output is correct
16 Correct 74 ms 146248 KB Output is correct
17 Correct 85 ms 146508 KB Output is correct
18 Correct 80 ms 146248 KB Output is correct
19 Correct 82 ms 146156 KB Output is correct
20 Correct 80 ms 146248 KB Output is correct
21 Correct 81 ms 146248 KB Output is correct
22 Correct 73 ms 146260 KB Output is correct
23 Correct 83 ms 146504 KB Output is correct
24 Correct 77 ms 146504 KB Output is correct
25 Correct 78 ms 146252 KB Output is correct
26 Correct 82 ms 146504 KB Output is correct
27 Correct 86 ms 146548 KB Output is correct
28 Correct 82 ms 146764 KB Output is correct
29 Correct 96 ms 147028 KB Output is correct
30 Correct 81 ms 146396 KB Output is correct
31 Correct 80 ms 146760 KB Output is correct
32 Correct 79 ms 146504 KB Output is correct
33 Correct 75 ms 147532 KB Output is correct
34 Correct 71 ms 147528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 146252 KB Output is correct
2 Correct 78 ms 146092 KB Output is correct
3 Correct 68 ms 146248 KB Output is correct
4 Correct 69 ms 146248 KB Output is correct
5 Correct 86 ms 146316 KB Output is correct
6 Correct 68 ms 146256 KB Output is correct
7 Correct 77 ms 146248 KB Output is correct
8 Correct 72 ms 146248 KB Output is correct
9 Correct 73 ms 146096 KB Output is correct
10 Correct 70 ms 146248 KB Output is correct
11 Correct 76 ms 146396 KB Output is correct
12 Correct 78 ms 146248 KB Output is correct
13 Correct 72 ms 146248 KB Output is correct
14 Correct 81 ms 146504 KB Output is correct
15 Correct 80 ms 146512 KB Output is correct
16 Correct 77 ms 146248 KB Output is correct
17 Correct 71 ms 146448 KB Output is correct
18 Correct 70 ms 146256 KB Output is correct
19 Correct 72 ms 146248 KB Output is correct
20 Correct 68 ms 146248 KB Output is correct
21 Correct 69 ms 146248 KB Output is correct
22 Correct 76 ms 146284 KB Output is correct
23 Correct 84 ms 146276 KB Output is correct
24 Correct 81 ms 146264 KB Output is correct
25 Correct 92 ms 146328 KB Output is correct
26 Correct 86 ms 146380 KB Output is correct
27 Correct 85 ms 146544 KB Output is correct
28 Correct 85 ms 146760 KB Output is correct
29 Correct 87 ms 147016 KB Output is correct
30 Correct 78 ms 146500 KB Output is correct
31 Correct 85 ms 146676 KB Output is correct
32 Correct 78 ms 146504 KB Output is correct
33 Correct 79 ms 147528 KB Output is correct
34 Correct 74 ms 147532 KB Output is correct
35 Correct 104 ms 147396 KB Output is correct
36 Correct 84 ms 146488 KB Output is correct
37 Correct 92 ms 148244 KB Output is correct
38 Correct 99 ms 147908 KB Output is correct
39 Correct 93 ms 148020 KB Output is correct
40 Correct 93 ms 147964 KB Output is correct
41 Correct 117 ms 147764 KB Output is correct
42 Correct 77 ms 147148 KB Output is correct
43 Correct 75 ms 147396 KB Output is correct
44 Correct 73 ms 147192 KB Output is correct
45 Correct 330 ms 247272 KB Output is correct
46 Correct 307 ms 247100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 62 ms 146248 KB Output is correct
2 Correct 71 ms 146256 KB Output is correct
3 Correct 63 ms 146248 KB Output is correct
4 Correct 59 ms 146292 KB Output is correct
5 Correct 61 ms 146256 KB Output is correct
6 Correct 63 ms 146252 KB Output is correct
7 Correct 68 ms 146216 KB Output is correct
8 Correct 74 ms 146256 KB Output is correct
9 Correct 81 ms 146256 KB Output is correct
10 Correct 73 ms 146248 KB Output is correct
11 Correct 76 ms 146504 KB Output is correct
12 Correct 84 ms 146300 KB Output is correct
13 Correct 69 ms 146248 KB Output is correct
14 Correct 75 ms 146600 KB Output is correct
15 Correct 75 ms 146504 KB Output is correct
16 Correct 78 ms 146124 KB Output is correct
17 Correct 75 ms 146496 KB Output is correct
18 Correct 76 ms 146180 KB Output is correct
19 Correct 86 ms 146252 KB Output is correct
20 Correct 85 ms 146256 KB Output is correct
21 Correct 63 ms 146132 KB Output is correct
22 Correct 77 ms 146244 KB Output is correct
23 Correct 91 ms 146248 KB Output is correct
24 Correct 84 ms 146388 KB Output is correct
25 Correct 69 ms 146248 KB Output is correct
26 Correct 75 ms 146508 KB Output is correct
27 Correct 75 ms 146336 KB Output is correct
28 Correct 79 ms 146924 KB Output is correct
29 Correct 69 ms 146988 KB Output is correct
30 Correct 68 ms 146424 KB Output is correct
31 Correct 75 ms 146560 KB Output is correct
32 Correct 69 ms 146468 KB Output is correct
33 Correct 74 ms 147528 KB Output is correct
34 Correct 79 ms 147376 KB Output is correct
35 Correct 96 ms 147472 KB Output is correct
36 Correct 95 ms 146504 KB Output is correct
37 Correct 107 ms 148140 KB Output is correct
38 Correct 101 ms 147908 KB Output is correct
39 Correct 94 ms 148020 KB Output is correct
40 Correct 97 ms 147988 KB Output is correct
41 Correct 92 ms 147896 KB Output is correct
42 Correct 87 ms 147140 KB Output is correct
43 Correct 93 ms 147396 KB Output is correct
44 Correct 80 ms 147140 KB Output is correct
45 Correct 311 ms 248408 KB Output is correct
46 Correct 321 ms 246912 KB Output is correct
47 Correct 141 ms 160728 KB Output is correct
48 Correct 93 ms 163916 KB Output is correct
49 Correct 78 ms 165448 KB Output is correct
50 Correct 80 ms 167340 KB Output is correct
51 Correct 107 ms 172616 KB Output is correct
52 Correct 139 ms 172360 KB Output is correct
53 Correct 107 ms 170824 KB Output is correct
54 Correct 82 ms 169032 KB Output is correct
55 Correct 98 ms 169296 KB Output is correct
56 Correct 93 ms 170816 KB Output is correct
57 Correct 95 ms 173384 KB Output is correct
58 Correct 106 ms 171156 KB Output is correct
59 Correct 101 ms 171972 KB Output is correct
60 Correct 109 ms 172228 KB Output is correct
61 Correct 99 ms 171816 KB Output is correct
62 Correct 126 ms 179016 KB Output is correct
63 Correct 114 ms 180456 KB Output is correct
64 Correct 157 ms 182116 KB Output is correct
65 Runtime error 291 ms 262144 KB Execution killed with signal 9
66 Halted 0 ms 0 KB -