답안 #1110719

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1110719 2024-11-10T09:14:29 Z hungnt Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
488 ms 5576 KB
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define BIT(x, k) (((x) >> (k)) & 1)
#define on(x, k) ((x) ^ (1ll << (k)))
#define pii pair<int, int>
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define ll long long
using namespace std;

const int N = 50002;

int n, m;
int a[N];
vector<int> adj[N];
ll dp[N];

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    #define TASK "TASK"
    if (fopen(TASK".INP", "r"))
    {
        freopen(TASK".INP", "r", stdin);
        freopen(TASK".OUT", "w", stdout);
    }
    cin >> n >> m;
    for(int i = 0, x; i < m; i++)
    {
        cin >> a[i] >> x;
        adj[a[i]].push_back(x);
    }
	priority_queue<pii, vector<pii>, greater<pii>> pq;
    memset(dp, 0x3f, sizeof dp);
    dp[a[0]] = 0;
    pq.push({0, a[0]});
    while(!pq.empty())
    {
        pii tmp = pq.top();pq.pop();
        int u = tmp.se;
        if(dp[u] != tmp.fi) continue;
        for(auto &step : adj[u])
        {
            int w = tmp.fi;
            for(int v = u + step; v < n; v += step)
            {
                if (dp[v] > ++w)
                {
                    dp[v] = w;
                    pq.push({dp[v], v});
                }
            }
            w = tmp.fi;
            for(int v = u - step; v >= 0; v -= step)
            {
                if (dp[v] > ++w)
                {
                    dp[v] = w;
                    pq.push({dp[v], v});
                }
            }
        }
    }
    if(dp[a[1]] < dp[n]) cout << dp[a[1]];
    else cout << -1;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:26:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |         freopen(TASK".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:27:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |         freopen(TASK".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1872 KB Output is correct
2 Correct 2 ms 1872 KB Output is correct
3 Correct 2 ms 1872 KB Output is correct
4 Correct 2 ms 1872 KB Output is correct
5 Correct 2 ms 1872 KB Output is correct
6 Correct 2 ms 1872 KB Output is correct
7 Correct 2 ms 1896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1872 KB Output is correct
2 Correct 2 ms 1872 KB Output is correct
3 Correct 2 ms 1872 KB Output is correct
4 Correct 2 ms 1872 KB Output is correct
5 Correct 2 ms 1872 KB Output is correct
6 Correct 2 ms 1884 KB Output is correct
7 Correct 2 ms 1872 KB Output is correct
8 Correct 2 ms 1872 KB Output is correct
9 Correct 2 ms 1872 KB Output is correct
10 Correct 2 ms 1872 KB Output is correct
11 Correct 2 ms 1872 KB Output is correct
12 Correct 3 ms 1872 KB Output is correct
13 Correct 3 ms 1872 KB Output is correct
14 Correct 2 ms 1872 KB Output is correct
15 Correct 2 ms 1872 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2044 KB Output is correct
2 Correct 2 ms 1872 KB Output is correct
3 Correct 2 ms 1872 KB Output is correct
4 Correct 2 ms 1872 KB Output is correct
5 Correct 2 ms 1872 KB Output is correct
6 Correct 2 ms 1872 KB Output is correct
7 Correct 2 ms 2124 KB Output is correct
8 Correct 2 ms 1872 KB Output is correct
9 Correct 2 ms 1872 KB Output is correct
10 Correct 2 ms 1872 KB Output is correct
11 Correct 2 ms 1872 KB Output is correct
12 Correct 2 ms 1872 KB Output is correct
13 Correct 2 ms 1872 KB Output is correct
14 Correct 2 ms 1872 KB Output is correct
15 Correct 2 ms 1872 KB Output is correct
16 Correct 3 ms 1872 KB Output is correct
17 Correct 2 ms 1872 KB Output is correct
18 Correct 2 ms 1872 KB Output is correct
19 Correct 2 ms 1872 KB Output is correct
20 Correct 4 ms 2128 KB Output is correct
21 Correct 2 ms 1872 KB Output is correct
22 Correct 2 ms 1872 KB Output is correct
23 Correct 2 ms 1872 KB Output is correct
24 Correct 3 ms 1872 KB Output is correct
25 Correct 3 ms 2128 KB Output is correct
26 Correct 4 ms 2112 KB Output is correct
27 Correct 4 ms 1872 KB Output is correct
28 Correct 2 ms 1872 KB Output is correct
29 Correct 3 ms 2128 KB Output is correct
30 Correct 3 ms 2128 KB Output is correct
31 Correct 3 ms 2128 KB Output is correct
32 Correct 2 ms 2128 KB Output is correct
33 Correct 3 ms 2128 KB Output is correct
34 Correct 4 ms 2128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1872 KB Output is correct
2 Correct 2 ms 1872 KB Output is correct
3 Correct 2 ms 1872 KB Output is correct
4 Correct 2 ms 2040 KB Output is correct
5 Correct 2 ms 2036 KB Output is correct
6 Correct 2 ms 1872 KB Output is correct
7 Correct 2 ms 1872 KB Output is correct
8 Correct 2 ms 1872 KB Output is correct
9 Correct 2 ms 1872 KB Output is correct
10 Correct 3 ms 1872 KB Output is correct
11 Correct 2 ms 1872 KB Output is correct
12 Correct 2 ms 1872 KB Output is correct
13 Correct 2 ms 1872 KB Output is correct
14 Correct 2 ms 1872 KB Output is correct
15 Correct 2 ms 1872 KB Output is correct
16 Correct 2 ms 1900 KB Output is correct
17 Correct 3 ms 1872 KB Output is correct
18 Correct 2 ms 1872 KB Output is correct
19 Correct 3 ms 1872 KB Output is correct
20 Correct 5 ms 2380 KB Output is correct
21 Correct 2 ms 1872 KB Output is correct
22 Correct 3 ms 1884 KB Output is correct
23 Correct 3 ms 1872 KB Output is correct
24 Correct 3 ms 2124 KB Output is correct
25 Correct 3 ms 2128 KB Output is correct
26 Correct 4 ms 1872 KB Output is correct
27 Correct 4 ms 1872 KB Output is correct
28 Correct 2 ms 2068 KB Output is correct
29 Correct 4 ms 2300 KB Output is correct
30 Correct 3 ms 2128 KB Output is correct
31 Correct 3 ms 2128 KB Output is correct
32 Correct 2 ms 2128 KB Output is correct
33 Correct 3 ms 2128 KB Output is correct
34 Correct 3 ms 2132 KB Output is correct
35 Correct 6 ms 2384 KB Output is correct
36 Correct 3 ms 2128 KB Output is correct
37 Correct 5 ms 2384 KB Output is correct
38 Correct 7 ms 2384 KB Output is correct
39 Correct 6 ms 2384 KB Output is correct
40 Correct 6 ms 2384 KB Output is correct
41 Correct 6 ms 2384 KB Output is correct
42 Correct 32 ms 2384 KB Output is correct
43 Correct 32 ms 2400 KB Output is correct
44 Correct 34 ms 2384 KB Output is correct
45 Correct 9 ms 2556 KB Output is correct
46 Correct 6 ms 2384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1872 KB Output is correct
2 Correct 2 ms 1920 KB Output is correct
3 Correct 2 ms 1872 KB Output is correct
4 Correct 2 ms 1984 KB Output is correct
5 Correct 2 ms 1872 KB Output is correct
6 Correct 2 ms 1872 KB Output is correct
7 Correct 2 ms 1872 KB Output is correct
8 Correct 2 ms 1872 KB Output is correct
9 Correct 2 ms 1872 KB Output is correct
10 Correct 2 ms 2044 KB Output is correct
11 Correct 2 ms 1872 KB Output is correct
12 Correct 2 ms 1872 KB Output is correct
13 Correct 2 ms 1872 KB Output is correct
14 Correct 2 ms 1872 KB Output is correct
15 Correct 2 ms 1872 KB Output is correct
16 Correct 2 ms 1872 KB Output is correct
17 Correct 2 ms 1872 KB Output is correct
18 Correct 2 ms 1872 KB Output is correct
19 Correct 2 ms 1872 KB Output is correct
20 Correct 4 ms 2128 KB Output is correct
21 Correct 2 ms 1872 KB Output is correct
22 Correct 2 ms 1872 KB Output is correct
23 Correct 2 ms 1872 KB Output is correct
24 Correct 3 ms 2040 KB Output is correct
25 Correct 2 ms 2128 KB Output is correct
26 Correct 4 ms 2040 KB Output is correct
27 Correct 4 ms 1872 KB Output is correct
28 Correct 2 ms 1872 KB Output is correct
29 Correct 3 ms 2132 KB Output is correct
30 Correct 3 ms 2296 KB Output is correct
31 Correct 3 ms 2128 KB Output is correct
32 Correct 2 ms 2128 KB Output is correct
33 Correct 3 ms 2128 KB Output is correct
34 Correct 3 ms 2128 KB Output is correct
35 Correct 6 ms 2384 KB Output is correct
36 Correct 3 ms 2128 KB Output is correct
37 Correct 6 ms 2384 KB Output is correct
38 Correct 7 ms 2384 KB Output is correct
39 Correct 6 ms 2384 KB Output is correct
40 Correct 7 ms 2384 KB Output is correct
41 Correct 6 ms 2552 KB Output is correct
42 Correct 32 ms 2384 KB Output is correct
43 Correct 34 ms 2384 KB Output is correct
44 Correct 34 ms 2384 KB Output is correct
45 Correct 6 ms 2384 KB Output is correct
46 Correct 6 ms 2384 KB Output is correct
47 Correct 12 ms 3020 KB Output is correct
48 Correct 6 ms 2552 KB Output is correct
49 Correct 6 ms 2384 KB Output is correct
50 Correct 5 ms 2384 KB Output is correct
51 Correct 21 ms 3780 KB Output is correct
52 Correct 19 ms 3276 KB Output is correct
53 Correct 11 ms 3276 KB Output is correct
54 Correct 3 ms 2128 KB Output is correct
55 Correct 4 ms 2128 KB Output is correct
56 Correct 488 ms 3408 KB Output is correct
57 Correct 42 ms 5316 KB Output is correct
58 Correct 459 ms 2384 KB Output is correct
59 Correct 457 ms 2392 KB Output is correct
60 Correct 458 ms 2396 KB Output is correct
61 Correct 396 ms 2384 KB Output is correct
62 Correct 8 ms 2896 KB Output is correct
63 Correct 24 ms 3536 KB Output is correct
64 Correct 25 ms 5456 KB Output is correct
65 Correct 30 ms 5576 KB Output is correct
66 Correct 40 ms 5316 KB Output is correct
67 Correct 43 ms 5572 KB Output is correct