Submission #243390

# Submission time Handle Problem Language Result Execution time Memory
243390 2020-07-01T02:00:00 Z NaimSS Jakarta Skyscrapers (APIO15_skyscraper) C++14
57 / 100
1000 ms 48620 KB
    #include <bits/stdc++.h>
    #define ld long double
    #define endl "\n"
    #define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #define pb(x) push_back(x)
    #define mp(a,b) make_pair(a,b)
    #define ms(v,x) memset(v,x,sizeof(v))
    #define all(v) v.begin(),v.end()
    #define ff first
    #define ss second
    #define rep(i, a, b) for(int i = a; i < (b); ++i)
    #define per(i, a, b) for(int i = b-1; i>=a ; i--)
    #define trav(a, x) for(auto& a : x)
    #define allin(a , x) for(auto a : x)
    #define td(v) v.begin(),v.end()
    #define sz(v) (int)v.size()
    //#define int long long
    using namespace std;
    typedef vector<int> vi;
    #define y1 abacaba
    #define left sefude
    #define right sefudermano
    typedef long long ll;
    typedef pair<int,int> pii;
    inline ll mod(ll n, ll m ){ ll ret = n%m; if(ret < 0) ret += m; return ret; }
    ll gcd(ll a, ll b){return (b == 0LL ? a : gcd(b, a%b));}
    ll exp(ll a,ll b,ll m){
        if(b==0LL) return 1LL;
        if(b==1LL) return mod(a,m);
        ll k = mod(exp(a,b/2,m),m);
        if(b&1LL){
            return mod(a*mod(k*k,m),m);
        }
        else return mod(k*k,m);
    }
     
     
    int n,m;
    const int N = 30100;
    int b[N],p[N];
     
     
    const int sq = 175;
    int vis[N][sq + 15];
     
    int dist[N][sq + 15];
    vi aqui[N];
    const int inf = 1e9;
    struct coisa{
      int dist,cur,p;
      coisa(){}
      coisa(int a,int b,int c){
        dist = a;
        cur = b;
        p = c;
      }
      bool operator<(const coisa& o)const{
        return dist > o.dist;
      }
    };
     
    #define pwr(x) (x>=sq ? sq + 1 : x)
    void djkistra(){
      for(int i=0;i<N;i++){
     
        for(int j=0;j<sq+10;j++)dist[i][j] = inf;
      }
      
      priority_queue<coisa> pq;
      dist[b[0]][pwr(p[0])] =0;
      pq.push(coisa(dist[b[0]][pwr(p[0])],b[0],p[0]));
      
      while(!pq.empty()){
        coisa c = pq.top();
        pq.pop();
       
        if(vis[c.cur][pwr(c.p)])continue;
        vis[c.cur][pwr(c.p)]=1;
        int d = dist[c.cur][pwr(c.p)];
        int id = c.cur;
        int cur = c.cur;
       
        if(c.p < sq){
          aqui[id].pb(c.p);
        }
     
        for(int x : aqui[id]){
          
            if(x >= sq){
              int t=0;
              for(int l = cur-x;l>=0;l-=x){
                t++;
                if(dist[l][sq + 1] > d + t){
                  dist[l][sq + 1] = d + t;
                  pq.push(coisa(dist[l][sq+1],l,x));
                }
              }
              t=0;
              for(int l = cur + x;l<n;l+=x){
                t++;
                if(dist[l][sq+1] > d + t){
                  dist[l][sq + 1] = d + t;
                  pq.push(coisa(dist[l][sq+1],l,x));
                }
              }
            }else{
              dist[cur][x] = min(dist[cur][x],d);
              if(cur - x >=0 and dist[cur-x][x] > d + 1){
                dist[cur-x][x] = d + 1;
                pq.push(coisa(dist[cur-x][x],cur - x,x));
              } 
              if(cur + x < n and dist[cur + x][x] > d + 1){
                dist[cur + x][x] = d + 1;
                pq.push(coisa(dist[cur + x][x],cur + x,x));
              }
            }
        } 
        aqui[id].clear();
        
     
     
      }  
     
      int res = inf;
      for(int i=0;i<sq + 10;i++){
        res = min(res,dist[b[1]][i]);
      }
      if(res == inf)cout<<-1<<endl;
      else cout << res << endl;
    }
     
    int32_t main(){
      fastio;
      cin >> n >> m;
      for(int i=0;i<m;i++){
        cin >> b[i] >> p[i];
        aqui[b[i]].pb(p[i]);
      }
      djkistra();
      // Math -> gcd it all
      // Did u check N=1? Did you switch N,M?
    } 
# Verdict Execution time Memory Grader output
1 Correct 22 ms 23424 KB Output is correct
2 Correct 18 ms 23424 KB Output is correct
3 Correct 18 ms 23424 KB Output is correct
4 Correct 22 ms 23424 KB Output is correct
5 Correct 18 ms 23424 KB Output is correct
6 Correct 19 ms 23424 KB Output is correct
7 Correct 18 ms 23424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 23424 KB Output is correct
2 Correct 22 ms 23424 KB Output is correct
3 Correct 19 ms 23424 KB Output is correct
4 Correct 21 ms 23552 KB Output is correct
5 Correct 20 ms 23424 KB Output is correct
6 Correct 18 ms 23424 KB Output is correct
7 Correct 18 ms 23424 KB Output is correct
8 Correct 18 ms 23552 KB Output is correct
9 Correct 18 ms 23424 KB Output is correct
10 Correct 18 ms 23552 KB Output is correct
11 Correct 19 ms 23552 KB Output is correct
12 Correct 19 ms 23552 KB Output is correct
13 Correct 20 ms 23552 KB Output is correct
14 Correct 19 ms 23552 KB Output is correct
15 Correct 19 ms 23552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 23424 KB Output is correct
2 Correct 20 ms 23552 KB Output is correct
3 Correct 20 ms 23416 KB Output is correct
4 Correct 18 ms 23436 KB Output is correct
5 Correct 20 ms 23424 KB Output is correct
6 Correct 20 ms 23424 KB Output is correct
7 Correct 20 ms 23424 KB Output is correct
8 Correct 18 ms 23424 KB Output is correct
9 Correct 23 ms 23464 KB Output is correct
10 Correct 18 ms 23552 KB Output is correct
11 Correct 19 ms 23552 KB Output is correct
12 Correct 19 ms 23680 KB Output is correct
13 Correct 19 ms 23552 KB Output is correct
14 Correct 20 ms 23552 KB Output is correct
15 Correct 18 ms 23552 KB Output is correct
16 Correct 20 ms 23424 KB Output is correct
17 Correct 21 ms 24064 KB Output is correct
18 Correct 19 ms 23584 KB Output is correct
19 Correct 19 ms 23552 KB Output is correct
20 Correct 24 ms 25088 KB Output is correct
21 Correct 19 ms 23424 KB Output is correct
22 Correct 18 ms 23424 KB Output is correct
23 Correct 21 ms 24832 KB Output is correct
24 Correct 22 ms 25088 KB Output is correct
25 Correct 21 ms 24984 KB Output is correct
26 Correct 22 ms 25088 KB Output is correct
27 Correct 22 ms 24960 KB Output is correct
28 Correct 23 ms 24960 KB Output is correct
29 Correct 25 ms 24960 KB Output is correct
30 Correct 21 ms 24960 KB Output is correct
31 Correct 22 ms 24960 KB Output is correct
32 Correct 26 ms 25088 KB Output is correct
33 Correct 33 ms 25088 KB Output is correct
34 Correct 31 ms 25088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 23424 KB Output is correct
2 Correct 18 ms 23424 KB Output is correct
3 Correct 18 ms 23680 KB Output is correct
4 Correct 19 ms 23424 KB Output is correct
5 Correct 19 ms 23424 KB Output is correct
6 Correct 19 ms 23424 KB Output is correct
7 Correct 18 ms 23424 KB Output is correct
8 Correct 17 ms 23424 KB Output is correct
9 Correct 18 ms 23552 KB Output is correct
10 Correct 19 ms 23552 KB Output is correct
11 Correct 23 ms 23552 KB Output is correct
12 Correct 20 ms 23584 KB Output is correct
13 Correct 21 ms 23552 KB Output is correct
14 Correct 21 ms 23552 KB Output is correct
15 Correct 19 ms 23552 KB Output is correct
16 Correct 20 ms 23424 KB Output is correct
17 Correct 21 ms 24064 KB Output is correct
18 Correct 19 ms 23424 KB Output is correct
19 Correct 24 ms 23552 KB Output is correct
20 Correct 22 ms 25088 KB Output is correct
21 Correct 20 ms 23424 KB Output is correct
22 Correct 18 ms 23552 KB Output is correct
23 Correct 22 ms 24704 KB Output is correct
24 Correct 22 ms 24960 KB Output is correct
25 Correct 22 ms 24960 KB Output is correct
26 Correct 23 ms 24960 KB Output is correct
27 Correct 20 ms 24960 KB Output is correct
28 Correct 22 ms 24960 KB Output is correct
29 Correct 28 ms 24960 KB Output is correct
30 Correct 21 ms 24960 KB Output is correct
31 Correct 22 ms 24960 KB Output is correct
32 Correct 23 ms 24960 KB Output is correct
33 Correct 31 ms 25088 KB Output is correct
34 Correct 32 ms 25088 KB Output is correct
35 Correct 32 ms 25088 KB Output is correct
36 Correct 21 ms 24480 KB Output is correct
37 Correct 44 ms 25436 KB Output is correct
38 Correct 39 ms 25600 KB Output is correct
39 Correct 38 ms 25600 KB Output is correct
40 Correct 40 ms 25600 KB Output is correct
41 Correct 42 ms 25592 KB Output is correct
42 Correct 28 ms 25472 KB Output is correct
43 Correct 26 ms 25344 KB Output is correct
44 Correct 27 ms 25472 KB Output is correct
45 Correct 67 ms 25720 KB Output is correct
46 Correct 65 ms 25724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 23424 KB Output is correct
2 Correct 18 ms 23424 KB Output is correct
3 Correct 18 ms 23424 KB Output is correct
4 Correct 18 ms 23424 KB Output is correct
5 Correct 18 ms 23424 KB Output is correct
6 Correct 20 ms 23424 KB Output is correct
7 Correct 18 ms 23424 KB Output is correct
8 Correct 18 ms 23424 KB Output is correct
9 Correct 20 ms 23424 KB Output is correct
10 Correct 20 ms 23552 KB Output is correct
11 Correct 23 ms 23552 KB Output is correct
12 Correct 18 ms 23552 KB Output is correct
13 Correct 20 ms 23552 KB Output is correct
14 Correct 19 ms 23552 KB Output is correct
15 Correct 19 ms 23680 KB Output is correct
16 Correct 19 ms 23424 KB Output is correct
17 Correct 20 ms 24064 KB Output is correct
18 Correct 18 ms 23424 KB Output is correct
19 Correct 18 ms 23552 KB Output is correct
20 Correct 20 ms 24960 KB Output is correct
21 Correct 19 ms 23424 KB Output is correct
22 Correct 19 ms 23424 KB Output is correct
23 Correct 22 ms 24680 KB Output is correct
24 Correct 22 ms 24960 KB Output is correct
25 Correct 20 ms 24960 KB Output is correct
26 Correct 22 ms 24960 KB Output is correct
27 Correct 21 ms 24960 KB Output is correct
28 Correct 22 ms 24960 KB Output is correct
29 Correct 26 ms 24960 KB Output is correct
30 Correct 22 ms 25088 KB Output is correct
31 Correct 24 ms 25088 KB Output is correct
32 Correct 21 ms 24960 KB Output is correct
33 Correct 31 ms 25088 KB Output is correct
34 Correct 31 ms 25088 KB Output is correct
35 Correct 31 ms 25088 KB Output is correct
36 Correct 22 ms 24320 KB Output is correct
37 Correct 43 ms 25408 KB Output is correct
38 Correct 37 ms 25592 KB Output is correct
39 Correct 37 ms 25592 KB Output is correct
40 Correct 40 ms 25600 KB Output is correct
41 Correct 43 ms 25592 KB Output is correct
42 Correct 26 ms 25412 KB Output is correct
43 Correct 25 ms 25416 KB Output is correct
44 Correct 26 ms 25344 KB Output is correct
45 Correct 63 ms 25720 KB Output is correct
46 Correct 65 ms 25716 KB Output is correct
47 Correct 120 ms 33524 KB Output is correct
48 Correct 25 ms 24064 KB Output is correct
49 Correct 24 ms 24064 KB Output is correct
50 Correct 22 ms 23936 KB Output is correct
51 Correct 95 ms 47092 KB Output is correct
52 Correct 109 ms 47336 KB Output is correct
53 Correct 52 ms 46968 KB Output is correct
54 Correct 34 ms 46200 KB Output is correct
55 Correct 37 ms 46332 KB Output is correct
56 Correct 47 ms 46968 KB Output is correct
57 Correct 125 ms 46752 KB Output is correct
58 Correct 45 ms 46968 KB Output is correct
59 Correct 53 ms 46968 KB Output is correct
60 Correct 62 ms 47104 KB Output is correct
61 Correct 55 ms 47096 KB Output is correct
62 Correct 94 ms 46968 KB Output is correct
63 Correct 87 ms 48108 KB Output is correct
64 Correct 91 ms 48104 KB Output is correct
65 Correct 431 ms 48468 KB Output is correct
66 Execution timed out 1063 ms 48620 KB Time limit exceeded
67 Halted 0 ms 0 KB -