Submission #251226

# Submission time Handle Problem Language Result Execution time Memory
251226 2020-07-20T15:50:10 Z Marlov Jakarta Skyscrapers (APIO15_skyscraper) C++14
57 / 100
1000 ms 3576 KB
/*
Code by @marlov       
*/
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <utility>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <iterator>
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;

#define INF 200000000
#define maxV 30005

int N,M;
pair<int,int> doge[maxV];
//distance to location 0-N-1 inclusive
int dist[maxV];
bool vdoge[maxV];
priority_queue< pair<int,int> > pq;
//location contains array
vector<int> lc[maxV];

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>N>>M;
    fill(dist,dist+N,INF);
    for(int i=0;i<M;i++){
        cin>>doge[i].first>>doge[i].second;
        lc[doge[i].first].push_back(i);
    }

    for(int j=0;j<lc[doge[0].first].size();j++){
        pq.push(make_pair(0,lc[doge[0].first][j]));
    }

    dist[doge[0].first]=0;
    while(!pq.empty()){
        //cd is number of jumps and ci is the current index
        int cd=-1*pq.top().first;
        int ci=pq.top().second;
        pq.pop();
        //if that dog has already been visited there is no need to check again
        if(vdoge[ci]) continue;
        vdoge[ci]=true;
        //loops from current location to 0
        for(int i=0;doge[ci].first-i*doge[ci].second>=0;i++){
            //current location
            int cl=doge[ci].first-i*doge[ci].second;
            if(cd+i<dist[cl]){
                dist[cl]=cd+i;
                for(int j=0;j<lc[cl].size();j++){
                    pq.push(make_pair(-1*dist[cl],lc[cl][j]));
                }
            }
        }
        //to N-1
        for(int i=0;doge[ci].first+i*doge[ci].second<N;i++){ 
            int cl=doge[ci].first+i*doge[ci].second;
            if(cd+i<dist[cl]){
                dist[cl]=cd+i;
                for(int j=0;j<lc[cl].size();j++){
                    pq.push(make_pair(-1*dist[cl],lc[cl][j]));
                }
            }
        }
    }
    if(dist[doge[1].first]==INF){
        cout<<-1<<'\n';
    }else{
        cout<<dist[doge[1].first]<<'\n';
    }
    return 0;
}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1,n=0?)
	* do smth instead of nothing and stay organized
*/

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:46:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int j=0;j<lc[doge[0].first].size();j++){
                 ~^~~~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:65:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 for(int j=0;j<lc[cl].size();j++){
                             ~^~~~~~~~~~~~~~
skyscraper.cpp:75:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 for(int j=0;j<lc[cl].size();j++){
                             ~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1024 KB Output is correct
2 Correct 1 ms 1024 KB Output is correct
3 Correct 1 ms 1024 KB Output is correct
4 Correct 1 ms 1024 KB Output is correct
5 Correct 1 ms 1024 KB Output is correct
6 Correct 1 ms 1024 KB Output is correct
7 Correct 1 ms 1024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1024 KB Output is correct
2 Correct 1 ms 1024 KB Output is correct
3 Correct 1 ms 1024 KB Output is correct
4 Correct 1 ms 1024 KB Output is correct
5 Correct 1 ms 1024 KB Output is correct
6 Correct 1 ms 1024 KB Output is correct
7 Correct 1 ms 1024 KB Output is correct
8 Correct 1 ms 1024 KB Output is correct
9 Correct 1 ms 1024 KB Output is correct
10 Correct 1 ms 1024 KB Output is correct
11 Correct 2 ms 1152 KB Output is correct
12 Correct 1 ms 1152 KB Output is correct
13 Correct 1 ms 1152 KB Output is correct
14 Correct 2 ms 1152 KB Output is correct
15 Correct 2 ms 1280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1024 KB Output is correct
2 Correct 1 ms 1024 KB Output is correct
3 Correct 1 ms 1024 KB Output is correct
4 Correct 1 ms 1024 KB Output is correct
5 Correct 1 ms 1024 KB Output is correct
6 Correct 1 ms 1024 KB Output is correct
7 Correct 1 ms 1024 KB Output is correct
8 Correct 1 ms 1024 KB Output is correct
9 Correct 1 ms 1024 KB Output is correct
10 Correct 1 ms 1024 KB Output is correct
11 Correct 2 ms 1152 KB Output is correct
12 Correct 2 ms 1152 KB Output is correct
13 Correct 2 ms 1152 KB Output is correct
14 Correct 1 ms 1152 KB Output is correct
15 Correct 2 ms 1152 KB Output is correct
16 Correct 2 ms 1024 KB Output is correct
17 Correct 2 ms 1152 KB Output is correct
18 Correct 1 ms 1152 KB Output is correct
19 Correct 1 ms 1024 KB Output is correct
20 Correct 6 ms 1152 KB Output is correct
21 Correct 1 ms 1024 KB Output is correct
22 Correct 1 ms 1152 KB Output is correct
23 Correct 1 ms 1152 KB Output is correct
24 Correct 2 ms 1152 KB Output is correct
25 Correct 3 ms 1152 KB Output is correct
26 Correct 5 ms 1152 KB Output is correct
27 Correct 6 ms 1152 KB Output is correct
28 Correct 1 ms 1152 KB Output is correct
29 Correct 1 ms 1152 KB Output is correct
30 Correct 1 ms 1024 KB Output is correct
31 Correct 1 ms 1152 KB Output is correct
32 Correct 2 ms 1024 KB Output is correct
33 Correct 2 ms 1152 KB Output is correct
34 Correct 2 ms 1152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1024 KB Output is correct
2 Correct 1 ms 1024 KB Output is correct
3 Correct 1 ms 1024 KB Output is correct
4 Correct 1 ms 1104 KB Output is correct
5 Correct 1 ms 1024 KB Output is correct
6 Correct 1 ms 1024 KB Output is correct
7 Correct 1 ms 1024 KB Output is correct
8 Correct 1 ms 1024 KB Output is correct
9 Correct 1 ms 1024 KB Output is correct
10 Correct 1 ms 1024 KB Output is correct
11 Correct 2 ms 1152 KB Output is correct
12 Correct 2 ms 1152 KB Output is correct
13 Correct 2 ms 1152 KB Output is correct
14 Correct 2 ms 1152 KB Output is correct
15 Correct 1 ms 1152 KB Output is correct
16 Correct 1 ms 1024 KB Output is correct
17 Correct 3 ms 1116 KB Output is correct
18 Correct 1 ms 1152 KB Output is correct
19 Correct 1 ms 1024 KB Output is correct
20 Correct 6 ms 1152 KB Output is correct
21 Correct 1 ms 1024 KB Output is correct
22 Correct 1 ms 1152 KB Output is correct
23 Correct 1 ms 1152 KB Output is correct
24 Correct 2 ms 1152 KB Output is correct
25 Correct 2 ms 1152 KB Output is correct
26 Correct 5 ms 1152 KB Output is correct
27 Correct 7 ms 1128 KB Output is correct
28 Correct 1 ms 1152 KB Output is correct
29 Correct 1 ms 1152 KB Output is correct
30 Correct 1 ms 1024 KB Output is correct
31 Correct 1 ms 1152 KB Output is correct
32 Correct 1 ms 1024 KB Output is correct
33 Correct 2 ms 1152 KB Output is correct
34 Correct 2 ms 1152 KB Output is correct
35 Correct 23 ms 2428 KB Output is correct
36 Correct 4 ms 1280 KB Output is correct
37 Correct 22 ms 2300 KB Output is correct
38 Correct 30 ms 2936 KB Output is correct
39 Correct 24 ms 2936 KB Output is correct
40 Correct 24 ms 2936 KB Output is correct
41 Correct 24 ms 2936 KB Output is correct
42 Correct 73 ms 2048 KB Output is correct
43 Correct 73 ms 2048 KB Output is correct
44 Correct 101 ms 2112 KB Output is correct
45 Correct 17 ms 2300 KB Output is correct
46 Correct 17 ms 2300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1024 KB Output is correct
2 Correct 1 ms 1024 KB Output is correct
3 Correct 1 ms 1024 KB Output is correct
4 Correct 1 ms 1024 KB Output is correct
5 Correct 1 ms 1024 KB Output is correct
6 Correct 1 ms 1024 KB Output is correct
7 Correct 1 ms 1024 KB Output is correct
8 Correct 1 ms 1024 KB Output is correct
9 Correct 1 ms 1024 KB Output is correct
10 Correct 1 ms 1024 KB Output is correct
11 Correct 2 ms 1152 KB Output is correct
12 Correct 2 ms 1152 KB Output is correct
13 Correct 2 ms 1152 KB Output is correct
14 Correct 2 ms 1152 KB Output is correct
15 Correct 2 ms 1152 KB Output is correct
16 Correct 1 ms 1024 KB Output is correct
17 Correct 3 ms 1152 KB Output is correct
18 Correct 1 ms 1152 KB Output is correct
19 Correct 1 ms 1152 KB Output is correct
20 Correct 6 ms 1244 KB Output is correct
21 Correct 1 ms 1024 KB Output is correct
22 Correct 1 ms 1152 KB Output is correct
23 Correct 2 ms 1152 KB Output is correct
24 Correct 2 ms 1152 KB Output is correct
25 Correct 2 ms 1152 KB Output is correct
26 Correct 8 ms 1152 KB Output is correct
27 Correct 5 ms 1152 KB Output is correct
28 Correct 2 ms 1152 KB Output is correct
29 Correct 2 ms 1152 KB Output is correct
30 Correct 1 ms 1024 KB Output is correct
31 Correct 2 ms 1152 KB Output is correct
32 Correct 1 ms 1024 KB Output is correct
33 Correct 2 ms 1152 KB Output is correct
34 Correct 2 ms 1152 KB Output is correct
35 Correct 19 ms 2428 KB Output is correct
36 Correct 3 ms 1280 KB Output is correct
37 Correct 15 ms 2300 KB Output is correct
38 Correct 24 ms 2936 KB Output is correct
39 Correct 28 ms 2936 KB Output is correct
40 Correct 32 ms 2936 KB Output is correct
41 Correct 24 ms 2988 KB Output is correct
42 Correct 82 ms 2120 KB Output is correct
43 Correct 79 ms 2048 KB Output is correct
44 Correct 80 ms 2112 KB Output is correct
45 Correct 19 ms 2300 KB Output is correct
46 Correct 17 ms 2300 KB Output is correct
47 Correct 28 ms 3064 KB Output is correct
48 Correct 10 ms 2048 KB Output is correct
49 Correct 7 ms 2048 KB Output is correct
50 Correct 5 ms 1792 KB Output is correct
51 Correct 29 ms 3576 KB Output is correct
52 Correct 28 ms 3068 KB Output is correct
53 Correct 16 ms 3068 KB Output is correct
54 Correct 1 ms 1152 KB Output is correct
55 Correct 1 ms 1152 KB Output is correct
56 Correct 969 ms 2944 KB Output is correct
57 Correct 13 ms 1536 KB Output is correct
58 Correct 991 ms 2208 KB Output is correct
59 Correct 972 ms 2196 KB Output is correct
60 Execution timed out 1002 ms 2428 KB Time limit exceeded
61 Halted 0 ms 0 KB -