Submission #170569

# Submission time Handle Problem Language Result Execution time Memory
170569 2019-12-25T16:02:15 Z Swan Jakarta Skyscrapers (APIO15_skyscraper) C++14
57 / 100
79 ms 1400 KB
#include <bits/stdc++.h>
#define stop system("pause")
#define stop2 char o; cin >> o
#define INP freopen("pcb.in","r",stdin)
#define OUTP freopen ("pcb.out","w",stdout)
using namespace std;

const int maxn = 210;

int ans[2001];
vector<int> qwe[2001];
vector<pair<int,int> > v;
priority_queue<pair<int,int> > q;
int n,m;

void solve(int start){
    ans[start] = 0;
    q.push({0,start});
    while(q.size()){
        //stop;
        int now = q.top().second;
        int dist = -q.top().first;
        //cerr << now << endl;
        q.pop();
        if(dist > ans[now])continue;
        //cout << now << ' ' << ans[now] << endl;
        for(int i(0); i < qwe[now].size();i++){
            int w = qwe[now][i];
            int p = qwe[now][i];
            int cnt = 1;
            while(now+p < n){
                if(ans[now+p] > ans[now]+cnt){
                    ans[now+p] = ans[now]+cnt;
                    q.push({-ans[now+p],now+p});
                }
                cnt++;
                p+=w;
            }
            p = -w;
            cnt = 1;
            while(now+p >= 0){
                if(ans[now+p] > ans[now]+cnt){
                    ans[now+p] = ans[now]+cnt;
                    q.push({-ans[now+p],now+p});
                }
                cnt++;
                p-=w;
            }
        }
    }
}

main(){
    ios_base::sync_with_stdio(0);
    cin >> n >> m;
    for(int i(0);i<=n;i++)ans[i] = 1e9;
    int need;
    for(int i(0); i < m;i++){
        int b,p; cin >> b >> p;
        v.push_back({b,p});
        qwe[b].push_back(p);
        if(i==1)need = b;
    }
    solve(v[0].first);
    if(ans[need] == 1e9)cout << -1;
    else cout << ans[need];
}

/*
5 3
0 2
1 1
4 1
*/

Compilation message

skyscraper.cpp: In function 'void solve(int)':
skyscraper.cpp:27:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i(0); i < qwe[now].size();i++){
                       ~~^~~~~~~~~~~~~~~~~
skyscraper.cpp: At global scope:
skyscraper.cpp:53:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:65:16: warning: 'need' may be used uninitialized in this function [-Wmaybe-uninitialized]
     if(ans[need] == 1e9)cout << -1;
        ~~~~~~~~^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 3 ms 504 KB Output is correct
12 Correct 3 ms 504 KB Output is correct
13 Correct 3 ms 504 KB Output is correct
14 Correct 3 ms 504 KB Output is correct
15 Correct 3 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 2 ms 432 KB Output is correct
12 Correct 3 ms 504 KB Output is correct
13 Correct 3 ms 504 KB Output is correct
14 Correct 3 ms 508 KB Output is correct
15 Correct 3 ms 504 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 3 ms 504 KB Output is correct
18 Correct 3 ms 504 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 7 ms 504 KB Output is correct
21 Correct 2 ms 504 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 3 ms 508 KB Output is correct
24 Correct 3 ms 504 KB Output is correct
25 Correct 3 ms 504 KB Output is correct
26 Correct 7 ms 504 KB Output is correct
27 Correct 6 ms 376 KB Output is correct
28 Correct 3 ms 504 KB Output is correct
29 Correct 3 ms 504 KB Output is correct
30 Correct 3 ms 504 KB Output is correct
31 Correct 3 ms 508 KB Output is correct
32 Correct 3 ms 504 KB Output is correct
33 Correct 4 ms 504 KB Output is correct
34 Correct 4 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 380 KB Output is correct
4 Correct 0 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 3 ms 504 KB Output is correct
12 Correct 3 ms 380 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 3 ms 504 KB Output is correct
18 Correct 2 ms 504 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 7 ms 504 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 504 KB Output is correct
23 Correct 3 ms 552 KB Output is correct
24 Correct 3 ms 504 KB Output is correct
25 Correct 3 ms 504 KB Output is correct
26 Correct 7 ms 376 KB Output is correct
27 Correct 7 ms 504 KB Output is correct
28 Correct 3 ms 504 KB Output is correct
29 Correct 3 ms 504 KB Output is correct
30 Correct 3 ms 504 KB Output is correct
31 Correct 3 ms 504 KB Output is correct
32 Correct 3 ms 464 KB Output is correct
33 Correct 4 ms 504 KB Output is correct
34 Correct 4 ms 632 KB Output is correct
35 Correct 10 ms 1140 KB Output is correct
36 Correct 4 ms 632 KB Output is correct
37 Correct 9 ms 1016 KB Output is correct
38 Correct 13 ms 1400 KB Output is correct
39 Correct 12 ms 1272 KB Output is correct
40 Correct 12 ms 1272 KB Output is correct
41 Correct 12 ms 1272 KB Output is correct
42 Correct 78 ms 1140 KB Output is correct
43 Correct 75 ms 1016 KB Output is correct
44 Correct 79 ms 1144 KB Output is correct
45 Correct 10 ms 1120 KB Output is correct
46 Correct 10 ms 1120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 424 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 3 ms 504 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 3 ms 504 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 504 KB Output is correct
20 Correct 7 ms 504 KB Output is correct
21 Correct 2 ms 504 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 3 ms 376 KB Output is correct
24 Correct 3 ms 504 KB Output is correct
25 Correct 3 ms 504 KB Output is correct
26 Correct 7 ms 504 KB Output is correct
27 Correct 7 ms 504 KB Output is correct
28 Correct 3 ms 504 KB Output is correct
29 Correct 3 ms 504 KB Output is correct
30 Correct 3 ms 504 KB Output is correct
31 Correct 3 ms 504 KB Output is correct
32 Correct 3 ms 504 KB Output is correct
33 Correct 4 ms 504 KB Output is correct
34 Correct 4 ms 632 KB Output is correct
35 Correct 10 ms 1140 KB Output is correct
36 Correct 4 ms 632 KB Output is correct
37 Correct 9 ms 1016 KB Output is correct
38 Correct 12 ms 1268 KB Output is correct
39 Correct 12 ms 1272 KB Output is correct
40 Correct 12 ms 1272 KB Output is correct
41 Correct 12 ms 1272 KB Output is correct
42 Correct 78 ms 1140 KB Output is correct
43 Correct 76 ms 1144 KB Output is correct
44 Correct 79 ms 1144 KB Output is correct
45 Correct 10 ms 1120 KB Output is correct
46 Correct 10 ms 1120 KB Output is correct
47 Runtime error 2 ms 632 KB Execution killed with signal 11 (could be triggered by violating memory limits)
48 Halted 0 ms 0 KB -