답안 #247258

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
247258 2020-07-11T08:28:25 Z rrrr10000 Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
830 ms 42348 KB
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb emplace_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
#define dupli(a) a.erase(unique(all(a)),a.end())
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vvvvi=vector<vvvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const ll INF=1001001001;
const ll mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}

int main(){
    ll n,m;cin>>n>>m;
    ll k=sqrt(n*2/3);
    vvi v(n);
    ll s,g;
    rep(i,m){
        ll a,b;cin>>a>>b;
        if(i==0)s=a;
        if(i==1)g=a;
        v[a].pb(b);
    }
    vvi dis(n,vi(k+1,inf));
    SPQ(PP) pq;
    dis[s][0]=0;
    pq.emplace(0,s,0);
    while(!pq.empty()){
        auto t=pq.top();pq.pop();
        ll cost,i,j;
        tie(cost,i,j)=t;
        if(i==g)dame(cost);
        if(dis[i][j]!=cost)continue;
        if(j){
            if(i+j<n)if(chmin(dis[i+j][j],cost+1))pq.emplace(cost+1,i+j,j);
            if(i-j>=0)if(chmin(dis[i-j][j],cost+1))pq.emplace(cost+1,i-j,j);
            if(chmin(dis[i][0],cost))pq.emplace(cost,i,0);
        }
        else{
            for(ll x:v[i]){
                if(x<=k){
                    if(chmin(dis[i][x],cost))pq.emplace(cost,i,x);
                }
                else{
                    for(ll u=1;u*x+i<n;u++)if(chmin(dis[u*x+i][0],cost+u))pq.emplace(cost+u,u*x+i,0);
                    for(ll u=1;i-u*x>=0;u++)if(chmin(dis[i-u*x][0],cost+u))pq.emplace(cost+u,i-u*x,0);
                }
            }
        }
    }
    out(-1);
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:73:9: warning: 'g' may be used uninitialized in this function [-Wmaybe-uninitialized]
         if(i==g)dame(cost);
         ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 4 ms 256 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 6 ms 384 KB Output is correct
12 Correct 6 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 6 ms 384 KB Output is correct
15 Correct 6 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 4 ms 256 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 256 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 6 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 6 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 6 ms 512 KB Output is correct
18 Correct 6 ms 896 KB Output is correct
19 Correct 5 ms 1024 KB Output is correct
20 Correct 6 ms 1024 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 896 KB Output is correct
23 Correct 6 ms 896 KB Output is correct
24 Correct 7 ms 1024 KB Output is correct
25 Correct 7 ms 1024 KB Output is correct
26 Correct 6 ms 1000 KB Output is correct
27 Correct 6 ms 1024 KB Output is correct
28 Correct 7 ms 1024 KB Output is correct
29 Correct 13 ms 1152 KB Output is correct
30 Correct 7 ms 1024 KB Output is correct
31 Correct 8 ms 1152 KB Output is correct
32 Correct 6 ms 1152 KB Output is correct
33 Correct 16 ms 1344 KB Output is correct
34 Correct 12 ms 1408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 4 ms 256 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 4 ms 256 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 6 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 6 ms 384 KB Output is correct
15 Correct 6 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 6 ms 640 KB Output is correct
18 Correct 5 ms 896 KB Output is correct
19 Correct 7 ms 1024 KB Output is correct
20 Correct 7 ms 1152 KB Output is correct
21 Correct 6 ms 384 KB Output is correct
22 Correct 6 ms 896 KB Output is correct
23 Correct 6 ms 896 KB Output is correct
24 Correct 7 ms 1024 KB Output is correct
25 Correct 6 ms 1024 KB Output is correct
26 Correct 6 ms 1024 KB Output is correct
27 Correct 7 ms 1024 KB Output is correct
28 Correct 7 ms 1024 KB Output is correct
29 Correct 12 ms 1280 KB Output is correct
30 Correct 7 ms 1024 KB Output is correct
31 Correct 8 ms 1152 KB Output is correct
32 Correct 6 ms 1152 KB Output is correct
33 Correct 15 ms 1344 KB Output is correct
34 Correct 11 ms 1408 KB Output is correct
35 Correct 24 ms 1280 KB Output is correct
36 Correct 8 ms 768 KB Output is correct
37 Correct 19 ms 1408 KB Output is correct
38 Correct 27 ms 1536 KB Output is correct
39 Correct 26 ms 1400 KB Output is correct
40 Correct 26 ms 1536 KB Output is correct
41 Correct 28 ms 1528 KB Output is correct
42 Correct 22 ms 1276 KB Output is correct
43 Correct 29 ms 1276 KB Output is correct
44 Correct 23 ms 1276 KB Output is correct
45 Correct 32 ms 1664 KB Output is correct
46 Correct 27 ms 1672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 256 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 256 KB Output is correct
10 Correct 5 ms 308 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 6 ms 384 KB Output is correct
14 Correct 6 ms 432 KB Output is correct
15 Correct 6 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 6 ms 512 KB Output is correct
18 Correct 6 ms 896 KB Output is correct
19 Correct 6 ms 1076 KB Output is correct
20 Correct 7 ms 1024 KB Output is correct
21 Correct 6 ms 512 KB Output is correct
22 Correct 5 ms 896 KB Output is correct
23 Correct 6 ms 896 KB Output is correct
24 Correct 8 ms 1024 KB Output is correct
25 Correct 6 ms 1024 KB Output is correct
26 Correct 6 ms 1024 KB Output is correct
27 Correct 6 ms 1024 KB Output is correct
28 Correct 7 ms 1024 KB Output is correct
29 Correct 14 ms 1152 KB Output is correct
30 Correct 7 ms 1024 KB Output is correct
31 Correct 10 ms 1152 KB Output is correct
32 Correct 6 ms 1152 KB Output is correct
33 Correct 16 ms 1344 KB Output is correct
34 Correct 14 ms 1344 KB Output is correct
35 Correct 24 ms 1280 KB Output is correct
36 Correct 8 ms 768 KB Output is correct
37 Correct 19 ms 1408 KB Output is correct
38 Correct 26 ms 1536 KB Output is correct
39 Correct 27 ms 1408 KB Output is correct
40 Correct 26 ms 1400 KB Output is correct
41 Correct 27 ms 1536 KB Output is correct
42 Correct 23 ms 1276 KB Output is correct
43 Correct 23 ms 1276 KB Output is correct
44 Correct 23 ms 1276 KB Output is correct
45 Correct 32 ms 1664 KB Output is correct
46 Correct 27 ms 1664 KB Output is correct
47 Correct 36 ms 11136 KB Output is correct
48 Correct 37 ms 24832 KB Output is correct
49 Correct 43 ms 28152 KB Output is correct
50 Correct 34 ms 32128 KB Output is correct
51 Correct 70 ms 37108 KB Output is correct
52 Correct 60 ms 37112 KB Output is correct
53 Correct 52 ms 36216 KB Output is correct
54 Correct 26 ms 35584 KB Output is correct
55 Correct 25 ms 35576 KB Output is correct
56 Correct 49 ms 36472 KB Output is correct
57 Correct 26 ms 35584 KB Output is correct
58 Correct 39 ms 35828 KB Output is correct
59 Correct 47 ms 35828 KB Output is correct
60 Correct 44 ms 35828 KB Output is correct
61 Correct 48 ms 35828 KB Output is correct
62 Correct 69 ms 36472 KB Output is correct
63 Correct 108 ms 39148 KB Output is correct
64 Correct 136 ms 39148 KB Output is correct
65 Correct 298 ms 39152 KB Output is correct
66 Correct 830 ms 42208 KB Output is correct
67 Correct 395 ms 42348 KB Output is correct