답안 #1110743

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

const int N = 30007;
const int block = 157;

int n, m, b[N], v[N], dp[N], ans = -1;
bool vis[N][block + 100];
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)
        dp[i] = -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 (vis[u][t])
                continue;
            vis[u][t] = true;
            dp[u] = min((dp[u] == -1 ? (int)(1e9) : dp[u]), D);
            if (t <= block){
                if (u - t >= 0 && !vis[u - t][t])
                    Q[D + 1].push_back({u - t, t});
                if (u + t < n && !vis[u + t][t])
                    Q[D + 1].push_back({u + t, t});
            }
            for (int X : pw[u]){
                if (X <= block){
                    if (u - X >= 0 && !vis[u - X][X])
                        Q[D + 1].push_back({u - X, X});
                    if (u + X < n && !vis[u + X][X])
                        Q[D + 1].push_back({u + X, X});
                } else {
                    for (int i = u - X; i >= 0; i -= X)
                        if (!vis[i][block + 1])
                            Q[D + (u - i) / X].push_back({i, X});
                    for (int i = u + X; i < n; i += X)
                        if (!vis[i][block + 1])
                            Q[D + (i - u) / X].push_back({i, X});
                }
            }
        }
    }
    cout << dp[b[2]] << "\n";
}

Compilation message

skyscraper.cpp: In function 'int32_t main()':
skyscraper.cpp:15:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |         freopen("test.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
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.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 113480 KB Output is correct
2 Correct 48 ms 113488 KB Output is correct
3 Correct 40 ms 113480 KB Output is correct
4 Correct 45 ms 113448 KB Output is correct
5 Correct 46 ms 113480 KB Output is correct
6 Correct 48 ms 113456 KB Output is correct
7 Correct 51 ms 113312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 113488 KB Output is correct
2 Correct 55 ms 113480 KB Output is correct
3 Correct 48 ms 113488 KB Output is correct
4 Correct 50 ms 113480 KB Output is correct
5 Correct 51 ms 113484 KB Output is correct
6 Correct 52 ms 113480 KB Output is correct
7 Correct 55 ms 113480 KB Output is correct
8 Correct 50 ms 113488 KB Output is correct
9 Correct 53 ms 113504 KB Output is correct
10 Correct 63 ms 113480 KB Output is correct
11 Correct 54 ms 113736 KB Output is correct
12 Correct 54 ms 113484 KB Output is correct
13 Correct 51 ms 113500 KB Output is correct
14 Correct 55 ms 113736 KB Output is correct
15 Correct 55 ms 113744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 113440 KB Output is correct
2 Correct 56 ms 113480 KB Output is correct
3 Correct 58 ms 113480 KB Output is correct
4 Correct 56 ms 113300 KB Output is correct
5 Correct 60 ms 113492 KB Output is correct
6 Correct 59 ms 113476 KB Output is correct
7 Correct 56 ms 113480 KB Output is correct
8 Correct 54 ms 113488 KB Output is correct
9 Correct 58 ms 113320 KB Output is correct
10 Correct 57 ms 113480 KB Output is correct
11 Correct 70 ms 113644 KB Output is correct
12 Correct 62 ms 113532 KB Output is correct
13 Correct 59 ms 113480 KB Output is correct
14 Correct 62 ms 113644 KB Output is correct
15 Correct 65 ms 113688 KB Output is correct
16 Correct 61 ms 113520 KB Output is correct
17 Correct 57 ms 113480 KB Output is correct
18 Correct 57 ms 113544 KB Output is correct
19 Correct 55 ms 113480 KB Output is correct
20 Correct 59 ms 113480 KB Output is correct
21 Correct 59 ms 113488 KB Output is correct
22 Correct 67 ms 113480 KB Output is correct
23 Correct 58 ms 113492 KB Output is correct
24 Correct 55 ms 113588 KB Output is correct
25 Correct 52 ms 113488 KB Output is correct
26 Correct 49 ms 113724 KB Output is correct
27 Correct 55 ms 113736 KB Output is correct
28 Correct 52 ms 114000 KB Output is correct
29 Correct 58 ms 114248 KB Output is correct
30 Correct 50 ms 113676 KB Output is correct
31 Correct 56 ms 113744 KB Output is correct
32 Correct 53 ms 113648 KB Output is correct
33 Correct 54 ms 114768 KB Output is correct
34 Correct 63 ms 114556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 113480 KB Output is correct
2 Correct 50 ms 113488 KB Output is correct
3 Correct 48 ms 113504 KB Output is correct
4 Correct 43 ms 113480 KB Output is correct
5 Correct 51 ms 113480 KB Output is correct
6 Correct 46 ms 113264 KB Output is correct
7 Correct 46 ms 113488 KB Output is correct
8 Correct 42 ms 113480 KB Output is correct
9 Correct 54 ms 113508 KB Output is correct
10 Correct 47 ms 113492 KB Output is correct
11 Correct 44 ms 113744 KB Output is correct
12 Correct 50 ms 113480 KB Output is correct
13 Correct 54 ms 113488 KB Output is correct
14 Correct 58 ms 113712 KB Output is correct
15 Correct 63 ms 113744 KB Output is correct
16 Correct 53 ms 113292 KB Output is correct
17 Correct 53 ms 113488 KB Output is correct
18 Correct 52 ms 113480 KB Output is correct
19 Correct 52 ms 113556 KB Output is correct
20 Correct 55 ms 113652 KB Output is correct
21 Correct 63 ms 113480 KB Output is correct
22 Correct 64 ms 113480 KB Output is correct
23 Correct 57 ms 113480 KB Output is correct
24 Correct 59 ms 113480 KB Output is correct
25 Correct 60 ms 113484 KB Output is correct
26 Correct 57 ms 113736 KB Output is correct
27 Correct 50 ms 113592 KB Output is correct
28 Correct 49 ms 113992 KB Output is correct
29 Correct 50 ms 114248 KB Output is correct
30 Correct 49 ms 113736 KB Output is correct
31 Correct 62 ms 113736 KB Output is correct
32 Correct 54 ms 113744 KB Output is correct
33 Correct 56 ms 114760 KB Output is correct
34 Correct 62 ms 114532 KB Output is correct
35 Correct 66 ms 114468 KB Output is correct
36 Correct 52 ms 113744 KB Output is correct
37 Correct 77 ms 115028 KB Output is correct
38 Correct 76 ms 114964 KB Output is correct
39 Correct 74 ms 115044 KB Output is correct
40 Correct 74 ms 115112 KB Output is correct
41 Correct 84 ms 115036 KB Output is correct
42 Correct 60 ms 114308 KB Output is correct
43 Correct 60 ms 114636 KB Output is correct
44 Correct 54 ms 114308 KB Output is correct
45 Runtime error 357 ms 262144 KB Execution killed with signal 9
46 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 113488 KB Output is correct
2 Correct 56 ms 113488 KB Output is correct
3 Correct 55 ms 113480 KB Output is correct
4 Correct 58 ms 113424 KB Output is correct
5 Correct 52 ms 113492 KB Output is correct
6 Correct 56 ms 113480 KB Output is correct
7 Correct 59 ms 113488 KB Output is correct
8 Correct 66 ms 113480 KB Output is correct
9 Correct 62 ms 113444 KB Output is correct
10 Correct 52 ms 113480 KB Output is correct
11 Correct 67 ms 113736 KB Output is correct
12 Correct 58 ms 113480 KB Output is correct
13 Correct 58 ms 113480 KB Output is correct
14 Correct 61 ms 113740 KB Output is correct
15 Correct 61 ms 113736 KB Output is correct
16 Correct 57 ms 113492 KB Output is correct
17 Correct 62 ms 113488 KB Output is correct
18 Correct 57 ms 113464 KB Output is correct
19 Correct 54 ms 113480 KB Output is correct
20 Correct 57 ms 113480 KB Output is correct
21 Correct 55 ms 113340 KB Output is correct
22 Correct 55 ms 113324 KB Output is correct
23 Correct 55 ms 113448 KB Output is correct
24 Correct 56 ms 113516 KB Output is correct
25 Correct 55 ms 113488 KB Output is correct
26 Correct 54 ms 113744 KB Output is correct
27 Correct 61 ms 113568 KB Output is correct
28 Correct 60 ms 113992 KB Output is correct
29 Correct 61 ms 114248 KB Output is correct
30 Correct 53 ms 113736 KB Output is correct
31 Correct 54 ms 113744 KB Output is correct
32 Correct 64 ms 113820 KB Output is correct
33 Correct 51 ms 114768 KB Output is correct
34 Correct 57 ms 114768 KB Output is correct
35 Correct 66 ms 114504 KB Output is correct
36 Correct 55 ms 113528 KB Output is correct
37 Correct 71 ms 115368 KB Output is correct
38 Correct 75 ms 115076 KB Output is correct
39 Correct 73 ms 114916 KB Output is correct
40 Correct 83 ms 114892 KB Output is correct
41 Correct 81 ms 115036 KB Output is correct
42 Correct 53 ms 114248 KB Output is correct
43 Correct 53 ms 114628 KB Output is correct
44 Correct 54 ms 114256 KB Output is correct
45 Runtime error 381 ms 262144 KB Execution killed with signal 9
46 Halted 0 ms 0 KB -