답안 #99527

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
99527 2019-03-04T17:16:47 Z ae04071 Jakarta Skyscrapers (APIO15_skyscraper) C++11
100 / 100
388 ms 31144 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using namespace std;
using pii=pair<int,int>;

struct Data{
    int b,p,idx;
    Data() {}
    Data(int b,int p,int idx=0):b(b),p(p),idx(idx){}
    bool operator<(const Data &rhs)const {
        if(p!=rhs.p) return p<rhs.p;
        else if(b%p!=rhs.b%rhs.p) return b%p < rhs.b%rhs.p;
        else return b<rhs.b;
    }
};
int n,m;
vector<Data> arr[30000];
int vis[10000001];

queue<pair<int, Data>> que;

void push(int cost,Data v) {
    if(v.b-v.p>=0 && !vis[v.idx-1]) {
        vis[v.idx-1]=1;
        que.push({cost,Data(v.b-v.p,v.p,v.idx-1)});
    }
    if(v.b+v.p<n && !vis[v.idx+1]) {
        vis[v.idx+1]=1;
        que.push({cost,Data(v.b+v.p,v.p,v.idx+1)});
    }
}
int main() {
    int si,ei;
    vector<Data> ta;
    scanf("%d%d",&n,&m);
    for(int i=0,a,b;i<m;i++) {
        scanf("%d%d",&a,&b);
        ta.push_back(Data(a,b));
        if(i==0) si = a;
        else if(i==1) ei = a;
    }
    sort(ta.begin(),ta.end());
    
    for(int i=0,j=0,c=0;i<m;i=j) {
        for(j=i;j<sz(ta) && ta[i].b%ta[i].p == ta[j].b%ta[j].p && ta[i].p == ta[j].p;j++);
        for(int b=ta[i].b%ta[i].p, k=i;b<n;b+=ta[i].p,c++) {
            while(k<j && b==ta[k].b) {
                arr[b].push_back(Data(b,ta[i].p,c));
                k++;
            }
        }
    }

    que.push({0, Data(si, 0, -1)});
    while(!que.empty()) {
        int cost=que.front().fi;
        Data v=que.front().se;
        que.pop();
        if(v.b==ei) {
            printf("%d\n",cost);
            return 0;
        }
        
        if(v.p!=0) push(cost+1, v);
        while(!arr[v.b].empty()) {
            Data tmp=arr[v.b].back(); arr[v.b].pop_back();
            push(cost+1, tmp);
        }
    }
    puts("-1");
    
    return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:37:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&m);
     ~~~~~^~~~~~~~~~~~~~
skyscraper.cpp:39:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&a,&b);
         ~~~~~^~~~~~~~~~~~~~
skyscraper.cpp:61:9: warning: 'ei' may be used uninitialized in this function [-Wmaybe-uninitialized]
         if(v.b==ei) {
         ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1024 KB Output is correct
2 Correct 3 ms 1024 KB Output is correct
3 Correct 3 ms 1024 KB Output is correct
4 Correct 3 ms 1024 KB Output is correct
5 Correct 3 ms 1024 KB Output is correct
6 Correct 3 ms 1024 KB Output is correct
7 Correct 3 ms 1024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1024 KB Output is correct
2 Correct 3 ms 1024 KB Output is correct
3 Correct 3 ms 1024 KB Output is correct
4 Correct 3 ms 1024 KB Output is correct
5 Correct 2 ms 1024 KB Output is correct
6 Correct 3 ms 1024 KB Output is correct
7 Correct 3 ms 1024 KB Output is correct
8 Correct 2 ms 1024 KB Output is correct
9 Correct 3 ms 1024 KB Output is correct
10 Correct 3 ms 1024 KB Output is correct
11 Correct 3 ms 1152 KB Output is correct
12 Correct 4 ms 1152 KB Output is correct
13 Correct 4 ms 1152 KB Output is correct
14 Correct 3 ms 1152 KB Output is correct
15 Correct 3 ms 1152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1024 KB Output is correct
2 Correct 3 ms 1024 KB Output is correct
3 Correct 3 ms 1024 KB Output is correct
4 Correct 3 ms 1024 KB Output is correct
5 Correct 3 ms 1024 KB Output is correct
6 Correct 3 ms 1024 KB Output is correct
7 Correct 3 ms 1024 KB Output is correct
8 Correct 1 ms 896 KB Output is correct
9 Correct 2 ms 1024 KB Output is correct
10 Correct 3 ms 1024 KB Output is correct
11 Correct 3 ms 1152 KB Output is correct
12 Correct 3 ms 1152 KB Output is correct
13 Correct 3 ms 1152 KB Output is correct
14 Correct 4 ms 1152 KB Output is correct
15 Correct 3 ms 1152 KB Output is correct
16 Correct 3 ms 1024 KB Output is correct
17 Correct 4 ms 1152 KB Output is correct
18 Correct 3 ms 1152 KB Output is correct
19 Correct 3 ms 1024 KB Output is correct
20 Correct 4 ms 1152 KB Output is correct
21 Correct 3 ms 1024 KB Output is correct
22 Correct 4 ms 1024 KB Output is correct
23 Correct 3 ms 1152 KB Output is correct
24 Correct 4 ms 1152 KB Output is correct
25 Correct 4 ms 1152 KB Output is correct
26 Correct 5 ms 1152 KB Output is correct
27 Correct 3 ms 1152 KB Output is correct
28 Correct 5 ms 1152 KB Output is correct
29 Correct 7 ms 1280 KB Output is correct
30 Correct 4 ms 1152 KB Output is correct
31 Correct 4 ms 1152 KB Output is correct
32 Correct 4 ms 1152 KB Output is correct
33 Correct 7 ms 1664 KB Output is correct
34 Correct 6 ms 1664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1024 KB Output is correct
2 Correct 3 ms 1152 KB Output is correct
3 Correct 2 ms 1024 KB Output is correct
4 Correct 3 ms 1024 KB Output is correct
5 Correct 4 ms 1024 KB Output is correct
6 Correct 3 ms 1024 KB Output is correct
7 Correct 3 ms 1024 KB Output is correct
8 Correct 3 ms 1024 KB Output is correct
9 Correct 3 ms 1024 KB Output is correct
10 Correct 4 ms 1024 KB Output is correct
11 Correct 4 ms 1152 KB Output is correct
12 Correct 3 ms 1152 KB Output is correct
13 Correct 5 ms 1152 KB Output is correct
14 Correct 4 ms 1280 KB Output is correct
15 Correct 4 ms 1152 KB Output is correct
16 Correct 4 ms 1024 KB Output is correct
17 Correct 3 ms 1152 KB Output is correct
18 Correct 3 ms 1152 KB Output is correct
19 Correct 3 ms 1024 KB Output is correct
20 Correct 3 ms 1152 KB Output is correct
21 Correct 4 ms 1152 KB Output is correct
22 Correct 3 ms 1024 KB Output is correct
23 Correct 3 ms 1024 KB Output is correct
24 Correct 4 ms 1152 KB Output is correct
25 Correct 4 ms 1152 KB Output is correct
26 Correct 3 ms 1152 KB Output is correct
27 Correct 4 ms 1152 KB Output is correct
28 Correct 6 ms 1280 KB Output is correct
29 Correct 5 ms 1280 KB Output is correct
30 Correct 3 ms 1152 KB Output is correct
31 Correct 5 ms 1280 KB Output is correct
32 Correct 4 ms 1152 KB Output is correct
33 Correct 9 ms 1664 KB Output is correct
34 Correct 6 ms 1664 KB Output is correct
35 Correct 14 ms 2556 KB Output is correct
36 Correct 6 ms 1280 KB Output is correct
37 Correct 12 ms 2680 KB Output is correct
38 Correct 19 ms 2940 KB Output is correct
39 Correct 17 ms 2300 KB Output is correct
40 Correct 19 ms 2528 KB Output is correct
41 Correct 17 ms 3068 KB Output is correct
42 Correct 11 ms 2044 KB Output is correct
43 Correct 13 ms 1916 KB Output is correct
44 Correct 14 ms 2044 KB Output is correct
45 Correct 52 ms 4828 KB Output is correct
46 Correct 54 ms 4752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1024 KB Output is correct
2 Correct 3 ms 1024 KB Output is correct
3 Correct 3 ms 1024 KB Output is correct
4 Correct 3 ms 1024 KB Output is correct
5 Correct 3 ms 1024 KB Output is correct
6 Correct 3 ms 1024 KB Output is correct
7 Correct 3 ms 1024 KB Output is correct
8 Correct 3 ms 1024 KB Output is correct
9 Correct 3 ms 1024 KB Output is correct
10 Correct 3 ms 1024 KB Output is correct
11 Correct 4 ms 1152 KB Output is correct
12 Correct 3 ms 1152 KB Output is correct
13 Correct 3 ms 1152 KB Output is correct
14 Correct 5 ms 1152 KB Output is correct
15 Correct 4 ms 1152 KB Output is correct
16 Correct 4 ms 1024 KB Output is correct
17 Correct 4 ms 1152 KB Output is correct
18 Correct 4 ms 1280 KB Output is correct
19 Correct 3 ms 1024 KB Output is correct
20 Correct 4 ms 1152 KB Output is correct
21 Correct 4 ms 1152 KB Output is correct
22 Correct 3 ms 1024 KB Output is correct
23 Correct 4 ms 1152 KB Output is correct
24 Correct 4 ms 1152 KB Output is correct
25 Correct 4 ms 1152 KB Output is correct
26 Correct 6 ms 1152 KB Output is correct
27 Correct 3 ms 1152 KB Output is correct
28 Correct 4 ms 1280 KB Output is correct
29 Correct 5 ms 1280 KB Output is correct
30 Correct 4 ms 1152 KB Output is correct
31 Correct 4 ms 1152 KB Output is correct
32 Correct 4 ms 1152 KB Output is correct
33 Correct 7 ms 1664 KB Output is correct
34 Correct 7 ms 1664 KB Output is correct
35 Correct 16 ms 2556 KB Output is correct
36 Correct 6 ms 1280 KB Output is correct
37 Correct 15 ms 2704 KB Output is correct
38 Correct 19 ms 2912 KB Output is correct
39 Correct 16 ms 2300 KB Output is correct
40 Correct 17 ms 2600 KB Output is correct
41 Correct 20 ms 3040 KB Output is correct
42 Correct 12 ms 2044 KB Output is correct
43 Correct 14 ms 2044 KB Output is correct
44 Correct 12 ms 2044 KB Output is correct
45 Correct 42 ms 4724 KB Output is correct
46 Correct 28 ms 4732 KB Output is correct
47 Correct 21 ms 4604 KB Output is correct
48 Correct 14 ms 1788 KB Output is correct
49 Correct 17 ms 1788 KB Output is correct
50 Correct 9 ms 1600 KB Output is correct
51 Correct 20 ms 3068 KB Output is correct
52 Correct 21 ms 3068 KB Output is correct
53 Correct 21 ms 2300 KB Output is correct
54 Correct 4 ms 1152 KB Output is correct
55 Correct 3 ms 1152 KB Output is correct
56 Correct 19 ms 2420 KB Output is correct
57 Correct 4 ms 1280 KB Output is correct
58 Correct 14 ms 2172 KB Output is correct
59 Correct 15 ms 2172 KB Output is correct
60 Correct 19 ms 2172 KB Output is correct
61 Correct 14 ms 2044 KB Output is correct
62 Correct 33 ms 3956 KB Output is correct
63 Correct 113 ms 11120 KB Output is correct
64 Correct 132 ms 13272 KB Output is correct
65 Correct 188 ms 18420 KB Output is correct
66 Correct 388 ms 31144 KB Output is correct
67 Correct 224 ms 30040 KB Output is correct