답안 #398267

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
398267 2021-05-04T04:17:04 Z juggernaut Jakarta Skyscrapers (APIO15_skyscraper) C++17
100 / 100
955 ms 5052 KB
#include<bits/stdc++.h>
#define f first
#define s second
using namespace std;
void usaco(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
typedef long long ll;
#define USING_ORDERED_SET 0
#if USING_ORDERED_SET
#include<bits/extc++.h>
using namespace __gnu_pbds;
template<class T>using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
#endif
template<class T>void umax(T &a,T b){if(a<b)a=b;}
template<class T>void umin(T &a,T b){if(b<a)a=b;}
#ifdef IOI2021SG
    #define printl(args...)printf(args)
#else
    #define printl(args...)((void)0)
#endif
typedef pair<int,int> dat;
dat a[30010];
int st[30010],D[30010];
priority_queue<dat,vector<dat>,greater<dat> > q;
int main(){
    int i,j,n,m,s,e,d;
    scanf("%d%d",&n,&m);
    for(i=0;i<m;++i)scanf("%d%d",&a[i].f,&a[i].s);
    s=a[0].f,e=a[1].f;
    sort(a,a+m);
    st[a[0].f]=0;
    for(i=1;i<m;++i)if(a[i].f!=a[i-1].f)st[a[i].f]=i;
    for(i=0;i<n;++i)D[i]=2e9;
    D[s]=0;
    q.push({0,s});
    while(!q.empty()){
        dat p=q.top();
        q.pop();
        if(D[p.s]!=p.f)continue;
        for(i=st[p.s];a[i].f==p.s&&i<m;++i){
            d=p.f;
            for(j=p.s+a[i].s;j<n;j+=a[i].s)if(D[j]>++d)q.push({D[j]=d,j});
            d=p.f;
            for(j=p.s-a[i].s;j>=0;j-=a[i].s)if(D[j]>++d)q.push({D[j]=d,j});
        }
    }
    printf("%d",D[e]<2e9?D[e]:-1);
    return 0;
}

Compilation message

skyscraper.cpp: In function 'void usaco(std::string)':
skyscraper.cpp:5:29: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
    5 | void usaco(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
      |                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:5:66: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
    5 | void usaco(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
      |                                                           ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:26:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   26 |     scanf("%d%d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~
skyscraper.cpp:27:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   27 |     for(i=0;i<m;++i)scanf("%d%d",&a[i].f,&a[i].s);
      |                     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 308 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 296 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 300 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 312 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 2 ms 316 KB Output is correct
18 Correct 1 ms 312 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 5 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 2 ms 332 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 5 ms 332 KB Output is correct
27 Correct 5 ms 332 KB Output is correct
28 Correct 2 ms 320 KB Output is correct
29 Correct 3 ms 460 KB Output is correct
30 Correct 2 ms 332 KB Output is correct
31 Correct 2 ms 332 KB Output is correct
32 Correct 2 ms 332 KB Output is correct
33 Correct 5 ms 716 KB Output is correct
34 Correct 5 ms 716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 2 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 1 ms 312 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 304 KB Output is correct
20 Correct 5 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 304 KB Output is correct
23 Correct 1 ms 308 KB Output is correct
24 Correct 2 ms 332 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 5 ms 332 KB Output is correct
27 Correct 5 ms 332 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 3 ms 460 KB Output is correct
30 Correct 2 ms 332 KB Output is correct
31 Correct 2 ms 332 KB Output is correct
32 Correct 2 ms 332 KB Output is correct
33 Correct 4 ms 720 KB Output is correct
34 Correct 5 ms 716 KB Output is correct
35 Correct 10 ms 716 KB Output is correct
36 Correct 3 ms 332 KB Output is correct
37 Correct 8 ms 716 KB Output is correct
38 Correct 13 ms 900 KB Output is correct
39 Correct 12 ms 844 KB Output is correct
40 Correct 13 ms 828 KB Output is correct
41 Correct 12 ms 844 KB Output is correct
42 Correct 70 ms 676 KB Output is correct
43 Correct 71 ms 836 KB Output is correct
44 Correct 69 ms 820 KB Output is correct
45 Correct 14 ms 1080 KB Output is correct
46 Correct 13 ms 1100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 2 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 5 ms 332 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 2 ms 332 KB Output is correct
25 Correct 3 ms 332 KB Output is correct
26 Correct 5 ms 332 KB Output is correct
27 Correct 5 ms 332 KB Output is correct
28 Correct 2 ms 332 KB Output is correct
29 Correct 3 ms 460 KB Output is correct
30 Correct 2 ms 332 KB Output is correct
31 Correct 2 ms 332 KB Output is correct
32 Correct 2 ms 300 KB Output is correct
33 Correct 6 ms 716 KB Output is correct
34 Correct 4 ms 716 KB Output is correct
35 Correct 10 ms 716 KB Output is correct
36 Correct 3 ms 332 KB Output is correct
37 Correct 9 ms 744 KB Output is correct
38 Correct 12 ms 916 KB Output is correct
39 Correct 12 ms 844 KB Output is correct
40 Correct 12 ms 820 KB Output is correct
41 Correct 12 ms 828 KB Output is correct
42 Correct 69 ms 716 KB Output is correct
43 Correct 68 ms 764 KB Output is correct
44 Correct 73 ms 784 KB Output is correct
45 Correct 14 ms 1100 KB Output is correct
46 Correct 15 ms 1100 KB Output is correct
47 Correct 19 ms 1404 KB Output is correct
48 Correct 8 ms 880 KB Output is correct
49 Correct 8 ms 832 KB Output is correct
50 Correct 6 ms 716 KB Output is correct
51 Correct 29 ms 2268 KB Output is correct
52 Correct 28 ms 1720 KB Output is correct
53 Correct 19 ms 1732 KB Output is correct
54 Correct 2 ms 588 KB Output is correct
55 Correct 3 ms 588 KB Output is correct
56 Correct 748 ms 1356 KB Output is correct
57 Correct 49 ms 2752 KB Output is correct
58 Correct 535 ms 1012 KB Output is correct
59 Correct 955 ms 1100 KB Output is correct
60 Correct 639 ms 1212 KB Output is correct
61 Correct 798 ms 1228 KB Output is correct
62 Correct 14 ms 972 KB Output is correct
63 Correct 45 ms 3056 KB Output is correct
64 Correct 44 ms 3036 KB Output is correct
65 Correct 53 ms 3016 KB Output is correct
66 Correct 116 ms 5052 KB Output is correct
67 Correct 98 ms 5052 KB Output is correct