답안 #238138

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
238138 2020-06-10T02:11:51 Z HellAngel Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
190 ms 69600 KB
#include <bits/stdc++.h>
using namespace std;

const int maxn = 50007;

int n, m, a[maxn], start[maxn], len[maxn], dist[maxn];
set<int> st[maxn];
vector<pair<int, int>> vt[maxn];
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;

bool Inside(int x)
{
    return (x >= 0 && x < n);
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen("test.inp", "r")) freopen("test.inp", "r", stdin), freopen("test.out", "w", stdout);
    cin >> n >> m;
    if(m == 1)
    {
        cout << -1;
        return 0;
    }
    fill_n(dist, n, 1e9);
    for(int i = 1; i <= m; i++)
    {
        cin >> start[i] >> len[i];
        st[start[i]].insert(len[i]);
    }
    for(int i = 0; i < n; i++)
    {
        for(auto j: st[i])
        {
            for(int cnt = 1;;cnt++)
            {
                int nxt = i - cnt * j;
                if(nxt < 0) break;
                vt[i].emplace_back(nxt, cnt);
                if(st[nxt].count(j)) break;
            }
            for(int cnt = 1;;cnt++)
            {
                int nxt = i + cnt * j;
                if(nxt >= n) break;
                vt[i].emplace_back(nxt, cnt);
                if(st[nxt].count(j)) break;
            }
        }
    }
    dist[start[1]] = 0;
    pq.emplace(0, start[1]);
    while(pq.size())
    {
        pair<int, int> p = pq.top();
        pq.pop();
        if(p.first != dist[p.second]) continue;
        int u = p.second;
        if(u == start[2])
        {
            cout << dist[u];
            exit(0);
        }
        for(auto i: vt[u])
        {
            int v = i.first;
            int w = i.second;
            if(dist[v] > dist[u] + w)
            {
                dist[v] = dist[u] + w;
                pq.emplace(dist[v], v);
            }
        }
    }
    cout << -1;
}

Compilation message

skyscraper.cpp: In function 'int32_t main()':
skyscraper.cpp:20:63: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     if(fopen("test.inp", "r")) freopen("test.inp", "r", stdin), freopen("test.out", "w", stdout);
                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:20:63: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 3840 KB Output is correct
2 Correct 7 ms 3840 KB Output is correct
3 Correct 6 ms 3840 KB Output is correct
4 Correct 7 ms 3840 KB Output is correct
5 Correct 6 ms 3840 KB Output is correct
6 Correct 6 ms 3840 KB Output is correct
7 Correct 6 ms 3840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 3840 KB Output is correct
2 Correct 7 ms 3840 KB Output is correct
3 Correct 7 ms 3840 KB Output is correct
4 Correct 6 ms 3840 KB Output is correct
5 Correct 6 ms 3840 KB Output is correct
6 Correct 6 ms 3712 KB Output is correct
7 Correct 7 ms 3840 KB Output is correct
8 Correct 7 ms 3840 KB Output is correct
9 Correct 7 ms 3840 KB Output is correct
10 Correct 7 ms 3840 KB Output is correct
11 Correct 7 ms 3968 KB Output is correct
12 Correct 7 ms 3840 KB Output is correct
13 Correct 7 ms 3968 KB Output is correct
14 Correct 7 ms 4096 KB Output is correct
15 Correct 7 ms 4096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 3840 KB Output is correct
2 Correct 7 ms 3840 KB Output is correct
3 Correct 8 ms 3840 KB Output is correct
4 Correct 6 ms 3840 KB Output is correct
5 Correct 7 ms 3840 KB Output is correct
6 Correct 7 ms 3840 KB Output is correct
7 Correct 7 ms 3840 KB Output is correct
8 Correct 7 ms 3840 KB Output is correct
9 Correct 6 ms 3840 KB Output is correct
10 Correct 6 ms 3840 KB Output is correct
11 Correct 7 ms 3968 KB Output is correct
12 Correct 6 ms 3840 KB Output is correct
13 Correct 7 ms 3968 KB Output is correct
14 Correct 8 ms 4096 KB Output is correct
15 Correct 7 ms 3968 KB Output is correct
16 Correct 8 ms 3968 KB Output is correct
17 Correct 7 ms 4224 KB Output is correct
18 Correct 7 ms 3968 KB Output is correct
19 Correct 7 ms 3968 KB Output is correct
20 Correct 7 ms 4096 KB Output is correct
21 Correct 7 ms 3968 KB Output is correct
22 Correct 7 ms 3968 KB Output is correct
23 Correct 8 ms 4096 KB Output is correct
24 Correct 8 ms 4096 KB Output is correct
25 Correct 9 ms 4096 KB Output is correct
26 Correct 7 ms 4096 KB Output is correct
27 Correct 7 ms 3968 KB Output is correct
28 Correct 8 ms 4224 KB Output is correct
29 Correct 11 ms 4736 KB Output is correct
30 Correct 7 ms 4224 KB Output is correct
31 Correct 8 ms 4352 KB Output is correct
32 Correct 9 ms 4224 KB Output is correct
33 Correct 14 ms 5500 KB Output is correct
34 Correct 10 ms 5500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 3840 KB Output is correct
2 Correct 6 ms 3840 KB Output is correct
3 Correct 7 ms 3840 KB Output is correct
4 Correct 6 ms 3840 KB Output is correct
5 Correct 6 ms 3840 KB Output is correct
6 Correct 6 ms 3968 KB Output is correct
7 Correct 6 ms 3840 KB Output is correct
8 Correct 6 ms 3840 KB Output is correct
9 Correct 6 ms 3840 KB Output is correct
10 Correct 6 ms 3968 KB Output is correct
11 Correct 7 ms 3968 KB Output is correct
12 Correct 7 ms 3840 KB Output is correct
13 Correct 6 ms 3840 KB Output is correct
14 Correct 8 ms 4016 KB Output is correct
15 Correct 8 ms 3968 KB Output is correct
16 Correct 7 ms 3968 KB Output is correct
17 Correct 8 ms 4224 KB Output is correct
18 Correct 7 ms 3968 KB Output is correct
19 Correct 7 ms 3968 KB Output is correct
20 Correct 8 ms 4096 KB Output is correct
21 Correct 7 ms 3968 KB Output is correct
22 Correct 8 ms 3968 KB Output is correct
23 Correct 7 ms 4096 KB Output is correct
24 Correct 8 ms 4088 KB Output is correct
25 Correct 7 ms 4096 KB Output is correct
26 Correct 7 ms 3968 KB Output is correct
27 Correct 7 ms 3968 KB Output is correct
28 Correct 8 ms 4224 KB Output is correct
29 Correct 9 ms 4736 KB Output is correct
30 Correct 8 ms 4224 KB Output is correct
31 Correct 8 ms 4352 KB Output is correct
32 Correct 7 ms 4224 KB Output is correct
33 Correct 12 ms 5500 KB Output is correct
34 Correct 10 ms 5500 KB Output is correct
35 Correct 26 ms 6272 KB Output is correct
36 Correct 9 ms 4352 KB Output is correct
37 Correct 25 ms 7040 KB Output is correct
38 Correct 28 ms 7296 KB Output is correct
39 Correct 28 ms 7296 KB Output is correct
40 Correct 28 ms 7288 KB Output is correct
41 Correct 29 ms 7296 KB Output is correct
42 Correct 11 ms 4224 KB Output is correct
43 Correct 12 ms 4224 KB Output is correct
44 Correct 11 ms 4224 KB Output is correct
45 Correct 30 ms 9984 KB Output is correct
46 Correct 27 ms 9992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 3840 KB Output is correct
2 Correct 6 ms 3840 KB Output is correct
3 Correct 6 ms 3840 KB Output is correct
4 Correct 7 ms 3924 KB Output is correct
5 Correct 6 ms 3840 KB Output is correct
6 Correct 6 ms 3840 KB Output is correct
7 Correct 6 ms 3840 KB Output is correct
8 Correct 7 ms 3840 KB Output is correct
9 Correct 6 ms 3840 KB Output is correct
10 Correct 6 ms 3968 KB Output is correct
11 Correct 7 ms 3968 KB Output is correct
12 Correct 8 ms 3840 KB Output is correct
13 Correct 7 ms 3840 KB Output is correct
14 Correct 7 ms 3968 KB Output is correct
15 Correct 7 ms 4096 KB Output is correct
16 Correct 8 ms 3968 KB Output is correct
17 Correct 8 ms 4224 KB Output is correct
18 Correct 7 ms 3968 KB Output is correct
19 Correct 6 ms 3968 KB Output is correct
20 Correct 7 ms 4096 KB Output is correct
21 Correct 7 ms 3968 KB Output is correct
22 Correct 7 ms 3968 KB Output is correct
23 Correct 7 ms 3968 KB Output is correct
24 Correct 8 ms 4096 KB Output is correct
25 Correct 8 ms 4096 KB Output is correct
26 Correct 8 ms 3968 KB Output is correct
27 Correct 7 ms 3968 KB Output is correct
28 Correct 8 ms 4224 KB Output is correct
29 Correct 10 ms 4736 KB Output is correct
30 Correct 7 ms 4224 KB Output is correct
31 Correct 8 ms 4352 KB Output is correct
32 Correct 9 ms 4224 KB Output is correct
33 Correct 12 ms 5500 KB Output is correct
34 Correct 11 ms 5500 KB Output is correct
35 Correct 22 ms 6272 KB Output is correct
36 Correct 9 ms 4352 KB Output is correct
37 Correct 27 ms 7040 KB Output is correct
38 Correct 28 ms 7296 KB Output is correct
39 Correct 31 ms 7296 KB Output is correct
40 Correct 28 ms 7288 KB Output is correct
41 Correct 28 ms 7296 KB Output is correct
42 Correct 11 ms 4224 KB Output is correct
43 Correct 13 ms 4224 KB Output is correct
44 Correct 12 ms 4224 KB Output is correct
45 Correct 30 ms 10112 KB Output is correct
46 Correct 28 ms 10000 KB Output is correct
47 Correct 57 ms 14452 KB Output is correct
48 Correct 23 ms 7540 KB Output is correct
49 Correct 20 ms 6656 KB Output is correct
50 Correct 17 ms 6272 KB Output is correct
51 Correct 43 ms 9604 KB Output is correct
52 Correct 44 ms 9976 KB Output is correct
53 Correct 23 ms 6644 KB Output is correct
54 Correct 9 ms 4480 KB Output is correct
55 Correct 10 ms 4988 KB Output is correct
56 Correct 22 ms 6528 KB Output is correct
57 Correct 21 ms 12800 KB Output is correct
58 Correct 15 ms 5240 KB Output is correct
59 Correct 16 ms 5628 KB Output is correct
60 Correct 16 ms 6268 KB Output is correct
61 Correct 17 ms 5632 KB Output is correct
62 Correct 28 ms 10748 KB Output is correct
63 Correct 80 ms 28396 KB Output is correct
64 Correct 83 ms 31596 KB Output is correct
65 Correct 106 ms 41192 KB Output is correct
66 Correct 190 ms 69472 KB Output is correct
67 Correct 145 ms 69600 KB Output is correct