Submission #553464

# Submission time Handle Problem Language Result Execution time Memory
553464 2022-04-25T22:38:51 Z ala2 Jakarta Skyscrapers (APIO15_skyscraper) C++14
36 / 100
285 ms 262144 KB
    #include <bits/stdc++.h>
        #define int long long
        #define F first
        #define S second
        #define pb push_back
        #define B begin()
        #define E end()
     
        using namespace std;
        int a[30010];
        int b[30010];
        vector<pair<int,int>>v[10100];
        int dist(int i,int j)
        {
            return abs(a[j]-a[i]);
        }
        int dis[30010];
        const int inf=1e17;
        signed main()
        {
           ios_base::sync_with_stdio();
           cin.tie(0);
           cout.tie(0);
            int n,m;
            cin>>n>>m;
            int ss,ee;
            for(int i=1;i<=m;i++)
            {
                cin>>a[i]>>b[i];
                if(i==1)
                    ss=a[i];
                if(i==2)
                    ee=a[i];
     
     
            }
            for(int i=1;i<=m;i++)
            {
                int g=0;
                for(int j=a[i]-b[i];j>=0;j-=b[i])
                {
                    g++;
                    //cout<<"    "<<a[i]<<"   "<<j<<"  "<<g<<endl;
                    v[a[i]].pb({g,j});
                }
                g=1;
                for(int j=a[i]+b[i];j<n;j+=b[i])
                {
                  //  cout<<"            "<<a[i]<<"  "<<j<<"   "<<g<<endl;
                    v[a[i]].pb({g,j});
                    g++;
                }
            }
     
            if(ss==ee)
            {
                cout<<0<<endl;
                return 0;
            }
            for(int i=0;i<=n;i++)
                sort(v[i].B,v[i].E);
            for(int i=0;i<=n+1;i++)
            {
                dis[i]=inf;
            }
            dis[ss]=0;
            priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>q;
            q.push({0,ss});
            while(!q.empty())
            {
              //  cout<<"D";
                pair<int,int>x=q.top();
                q.pop();
               // cout<<"      ::::   "<<x.S<<endl;
                for(auto i:v[x.S])
                {
                    int ned=x.F+i.F;            //    cout<<"         "<<i.F<<"   "<<ned<<endl;
     
                    if(ned<dis[i.S])
                    {
                        //cout<<"              "<<i.S<<"   "<<ned<<"    "<<
                        dis[i.S]=ned;
                        q.push({ned,i.S});
                    }
                }
     
     
            }
            if(dis[ee]<inf)
            cout<<dis[ee]<<endl;
            else cout<<-1<<endl;
     
        }

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:66:20: warning: 'ss' may be used uninitialized in this function [-Wmaybe-uninitialized]
   66 |             dis[ss]=0;
      |             ~~~~~~~^~
skyscraper.cpp:89:22: warning: 'ee' may be used uninitialized in this function [-Wmaybe-uninitialized]
   89 |             if(dis[ee]<inf)
      |                ~~~~~~^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 0 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 0 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 1 ms 724 KB Output is correct
12 Correct 13 ms 4804 KB Output is correct
13 Correct 15 ms 4772 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 0 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 2 ms 724 KB Output is correct
12 Correct 15 ms 4724 KB Output is correct
13 Correct 14 ms 4804 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 1 ms 596 KB Output is correct
17 Correct 3 ms 980 KB Output is correct
18 Correct 1 ms 596 KB Output is correct
19 Correct 1 ms 596 KB Output is correct
20 Correct 216 ms 64752 KB Output is correct
21 Correct 1 ms 596 KB Output is correct
22 Correct 1 ms 596 KB Output is correct
23 Correct 1 ms 724 KB Output is correct
24 Correct 2 ms 852 KB Output is correct
25 Correct 3 ms 852 KB Output is correct
26 Correct 285 ms 66544 KB Output is correct
27 Correct 276 ms 66384 KB Output is correct
28 Correct 2 ms 980 KB Output is correct
29 Correct 6 ms 2132 KB Output is correct
30 Correct 3 ms 1108 KB Output is correct
31 Correct 4 ms 1492 KB Output is correct
32 Correct 3 ms 1236 KB Output is correct
33 Correct 12 ms 3376 KB Output is correct
34 Correct 11 ms 3164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 552 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 0 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 2 ms 724 KB Output is correct
12 Correct 14 ms 4720 KB Output is correct
13 Correct 13 ms 4804 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 1 ms 596 KB Output is correct
17 Correct 3 ms 980 KB Output is correct
18 Correct 1 ms 596 KB Output is correct
19 Correct 2 ms 596 KB Output is correct
20 Correct 229 ms 64692 KB Output is correct
21 Correct 1 ms 596 KB Output is correct
22 Correct 1 ms 596 KB Output is correct
23 Correct 2 ms 732 KB Output is correct
24 Correct 2 ms 852 KB Output is correct
25 Correct 2 ms 724 KB Output is correct
26 Correct 263 ms 66488 KB Output is correct
27 Correct 273 ms 66540 KB Output is correct
28 Correct 3 ms 980 KB Output is correct
29 Correct 9 ms 2132 KB Output is correct
30 Correct 2 ms 1108 KB Output is correct
31 Correct 4 ms 1492 KB Output is correct
32 Correct 3 ms 1236 KB Output is correct
33 Correct 15 ms 3336 KB Output is correct
34 Correct 12 ms 3152 KB Output is correct
35 Correct 19 ms 3968 KB Output is correct
36 Correct 4 ms 996 KB Output is correct
37 Correct 28 ms 7244 KB Output is correct
38 Correct 27 ms 6092 KB Output is correct
39 Correct 30 ms 6476 KB Output is correct
40 Correct 27 ms 6212 KB Output is correct
41 Correct 25 ms 6004 KB Output is correct
42 Runtime error 254 ms 262144 KB Execution killed with signal 9
43 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 0 ms 468 KB Output is correct
5 Correct 0 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 2 ms 724 KB Output is correct
12 Correct 15 ms 4804 KB Output is correct
13 Correct 15 ms 4804 KB Output is correct
14 Correct 2 ms 596 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 1 ms 596 KB Output is correct
17 Correct 3 ms 980 KB Output is correct
18 Correct 1 ms 596 KB Output is correct
19 Correct 1 ms 596 KB Output is correct
20 Correct 222 ms 64748 KB Output is correct
21 Correct 1 ms 596 KB Output is correct
22 Correct 1 ms 680 KB Output is correct
23 Correct 2 ms 724 KB Output is correct
24 Correct 3 ms 852 KB Output is correct
25 Correct 3 ms 852 KB Output is correct
26 Correct 268 ms 66544 KB Output is correct
27 Correct 266 ms 66424 KB Output is correct
28 Correct 2 ms 980 KB Output is correct
29 Correct 7 ms 2132 KB Output is correct
30 Correct 3 ms 1108 KB Output is correct
31 Correct 4 ms 1492 KB Output is correct
32 Correct 4 ms 1236 KB Output is correct
33 Correct 11 ms 3284 KB Output is correct
34 Correct 11 ms 3192 KB Output is correct
35 Correct 19 ms 4052 KB Output is correct
36 Correct 4 ms 1060 KB Output is correct
37 Correct 28 ms 7272 KB Output is correct
38 Correct 26 ms 6100 KB Output is correct
39 Correct 31 ms 6380 KB Output is correct
40 Correct 30 ms 6220 KB Output is correct
41 Correct 29 ms 5896 KB Output is correct
42 Runtime error 240 ms 262144 KB Execution killed with signal 9
43 Halted 0 ms 0 KB -