Submission #553463

# Submission time Handle Problem Language Result Execution time Memory
553463 2022-04-25T22:37:35 Z ala2 Jakarta Skyscrapers (APIO15_skyscraper) C++14
36 / 100
249 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[300010];
        int b[300010];
        vector<pair<int,int>>v[100100];
        int dist(int i,int j)
        {
            return abs(a[j]-a[i]);
        }
        int dis[100100];
        const int inf=1e18;
        signed main()
        {
           ios_base::sync_with_stdio(false);
           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:89:22: warning: 'ee' may be used uninitialized in this function [-Wmaybe-uninitialized]
   89 |             if(dis[ee]<inf)
      |                ~~~~~~^
skyscraper.cpp:66:20: warning: 'ss' may be used uninitialized in this function [-Wmaybe-uninitialized]
   66 |             dis[ss]=0;
      |             ~~~~~~~^~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2600 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2648 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 1 ms 2644 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
11 Correct 2 ms 2900 KB Output is correct
12 Correct 6 ms 6988 KB Output is correct
13 Correct 7 ms 6992 KB Output is correct
14 Correct 2 ms 2772 KB Output is correct
15 Correct 2 ms 2772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 1 ms 2644 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
11 Correct 2 ms 2900 KB Output is correct
12 Correct 6 ms 6988 KB Output is correct
13 Correct 6 ms 6992 KB Output is correct
14 Correct 2 ms 2772 KB Output is correct
15 Correct 2 ms 2772 KB Output is correct
16 Correct 2 ms 2772 KB Output is correct
17 Correct 2 ms 3156 KB Output is correct
18 Correct 2 ms 2772 KB Output is correct
19 Correct 2 ms 2772 KB Output is correct
20 Correct 79 ms 66836 KB Output is correct
21 Correct 2 ms 2644 KB Output is correct
22 Correct 2 ms 2772 KB Output is correct
23 Correct 2 ms 2772 KB Output is correct
24 Correct 3 ms 3028 KB Output is correct
25 Correct 3 ms 2900 KB Output is correct
26 Correct 89 ms 68712 KB Output is correct
27 Correct 90 ms 68500 KB Output is correct
28 Correct 3 ms 3156 KB Output is correct
29 Correct 5 ms 4436 KB Output is correct
30 Correct 4 ms 3284 KB Output is correct
31 Correct 4 ms 3540 KB Output is correct
32 Correct 3 ms 3284 KB Output is correct
33 Correct 7 ms 5700 KB Output is correct
34 Correct 6 ms 5520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 1 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 1 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 3 ms 2900 KB Output is correct
12 Correct 8 ms 7112 KB Output is correct
13 Correct 7 ms 6992 KB Output is correct
14 Correct 3 ms 2844 KB Output is correct
15 Correct 2 ms 2772 KB Output is correct
16 Correct 2 ms 2772 KB Output is correct
17 Correct 2 ms 3196 KB Output is correct
18 Correct 2 ms 2772 KB Output is correct
19 Correct 2 ms 2772 KB Output is correct
20 Correct 71 ms 66884 KB Output is correct
21 Correct 2 ms 2644 KB Output is correct
22 Correct 2 ms 2772 KB Output is correct
23 Correct 2 ms 2772 KB Output is correct
24 Correct 3 ms 2980 KB Output is correct
25 Correct 3 ms 2900 KB Output is correct
26 Correct 92 ms 68764 KB Output is correct
27 Correct 89 ms 68600 KB Output is correct
28 Correct 3 ms 3136 KB Output is correct
29 Correct 5 ms 4436 KB Output is correct
30 Correct 3 ms 3284 KB Output is correct
31 Correct 3 ms 3540 KB Output is correct
32 Correct 2 ms 3284 KB Output is correct
33 Correct 9 ms 5652 KB Output is correct
34 Correct 6 ms 5520 KB Output is correct
35 Correct 10 ms 6228 KB Output is correct
36 Correct 3 ms 3156 KB Output is correct
37 Correct 14 ms 9556 KB Output is correct
38 Correct 14 ms 8588 KB Output is correct
39 Correct 16 ms 8832 KB Output is correct
40 Correct 14 ms 8660 KB Output is correct
41 Correct 13 ms 8392 KB Output is correct
42 Runtime error 240 ms 262144 KB Execution killed with signal 9
43 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 1 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 3 ms 2900 KB Output is correct
12 Correct 8 ms 6940 KB Output is correct
13 Correct 9 ms 6992 KB Output is correct
14 Correct 2 ms 2772 KB Output is correct
15 Correct 2 ms 2772 KB Output is correct
16 Correct 2 ms 2772 KB Output is correct
17 Correct 3 ms 3156 KB Output is correct
18 Correct 2 ms 2772 KB Output is correct
19 Correct 2 ms 2772 KB Output is correct
20 Correct 82 ms 66912 KB Output is correct
21 Correct 2 ms 2644 KB Output is correct
22 Correct 2 ms 2772 KB Output is correct
23 Correct 2 ms 2772 KB Output is correct
24 Correct 3 ms 3028 KB Output is correct
25 Correct 3 ms 2900 KB Output is correct
26 Correct 88 ms 68688 KB Output is correct
27 Correct 90 ms 68500 KB Output is correct
28 Correct 3 ms 3156 KB Output is correct
29 Correct 5 ms 4436 KB Output is correct
30 Correct 3 ms 3284 KB Output is correct
31 Correct 3 ms 3540 KB Output is correct
32 Correct 3 ms 3284 KB Output is correct
33 Correct 6 ms 5684 KB Output is correct
34 Correct 7 ms 5520 KB Output is correct
35 Correct 9 ms 6228 KB Output is correct
36 Correct 3 ms 3156 KB Output is correct
37 Correct 12 ms 9404 KB Output is correct
38 Correct 12 ms 8276 KB Output is correct
39 Correct 13 ms 8532 KB Output is correct
40 Correct 13 ms 8404 KB Output is correct
41 Correct 13 ms 8128 KB Output is correct
42 Runtime error 249 ms 262144 KB Execution killed with signal 9
43 Halted 0 ms 0 KB -