답안 #111895

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
111895 2019-05-16T17:10:32 Z mayhoubsaleh Jakarta Skyscrapers (APIO15_skyscraper) C++14
36 / 100
1000 ms 66196 KB
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define inf 1e18+100

using namespace std;

const ll N=30300;
priority_queue<pair<ll,ll>>q;
ll n,m;
ll b[N],p[N],dist[N];
vector<ll>a[N];
vector<pair<ll,ll>>v[N];
void fil(ll id){
    for(ll i=0;i<n;i++){
        if(i==id||a[i].empty())continue;
        for(auto j:a[id]){
            if((i%p[j])==(id%p[j])){
                v[id].pb({i,abs(i-id)/p[j]});
            }
        }
    }
}
int main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n>>m;
    for(ll i=0;i<m;i++){
        cin>>b[i]>>p[i];
        a[b[i]].pb(i);
    }
    for(ll i=0;i<n;i++){
        if(!a[i].empty())fil(i);
    }

    /*for(ll i=0;i<n;i++){
        if(v[i].empty())continue;
        cout<<i<<": ";
        for(auto j:v[i])cout<<'('<<j.first<<' '<<j.second<<')'<<"      ";cout<<endl;
    }*/

    for(ll i=0;i<n;i++){
        dist[i]=inf;
    }
    q.push({0,b[0]});
    dist[b[0]]=0;
    while(!q.empty()){
        ll u=q.top().second,d=-q.top().first;
        q.pop();
        if(d>dist[u])continue;
        for(auto i:v[u]){
            ll ch=i.first,chd=i.second;
            if(chd+d<dist[ch]){
                dist[ch]=chd+d;
                q.push({-dist[ch],ch});
            }
        }
    }
    if(dist[b[1]]==inf){cout<<-1<<endl;return 0;}
    cout<<dist[b[1]]<<endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1868 KB Output is correct
2 Correct 3 ms 1792 KB Output is correct
3 Correct 4 ms 1792 KB Output is correct
4 Correct 4 ms 1792 KB Output is correct
5 Correct 4 ms 1792 KB Output is correct
6 Correct 4 ms 1792 KB Output is correct
7 Correct 3 ms 1792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1792 KB Output is correct
2 Correct 3 ms 1792 KB Output is correct
3 Correct 3 ms 1792 KB Output is correct
4 Correct 3 ms 1792 KB Output is correct
5 Correct 3 ms 1792 KB Output is correct
6 Correct 4 ms 1792 KB Output is correct
7 Correct 3 ms 1792 KB Output is correct
8 Correct 2 ms 1792 KB Output is correct
9 Correct 3 ms 1792 KB Output is correct
10 Correct 4 ms 1792 KB Output is correct
11 Correct 9 ms 2048 KB Output is correct
12 Correct 5 ms 2184 KB Output is correct
13 Correct 17 ms 6256 KB Output is correct
14 Correct 7 ms 1920 KB Output is correct
15 Correct 8 ms 1920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1792 KB Output is correct
2 Correct 4 ms 1792 KB Output is correct
3 Correct 3 ms 1792 KB Output is correct
4 Correct 4 ms 1792 KB Output is correct
5 Correct 4 ms 1792 KB Output is correct
6 Correct 4 ms 1792 KB Output is correct
7 Correct 3 ms 1792 KB Output is correct
8 Correct 4 ms 1792 KB Output is correct
9 Correct 4 ms 1792 KB Output is correct
10 Correct 5 ms 1792 KB Output is correct
11 Correct 10 ms 2048 KB Output is correct
12 Correct 5 ms 2304 KB Output is correct
13 Correct 16 ms 6256 KB Output is correct
14 Correct 7 ms 1920 KB Output is correct
15 Correct 6 ms 1920 KB Output is correct
16 Correct 9 ms 1920 KB Output is correct
17 Correct 38 ms 2296 KB Output is correct
18 Correct 28 ms 1920 KB Output is correct
19 Correct 16 ms 1792 KB Output is correct
20 Correct 219 ms 66196 KB Output is correct
21 Correct 12 ms 1820 KB Output is correct
22 Correct 18 ms 1916 KB Output is correct
23 Correct 28 ms 1920 KB Output is correct
24 Correct 65 ms 2040 KB Output is correct
25 Correct 65 ms 2044 KB Output is correct
26 Correct 12 ms 6140 KB Output is correct
27 Correct 12 ms 4096 KB Output is correct
28 Correct 105 ms 2424 KB Output is correct
29 Correct 6 ms 1792 KB Output is correct
30 Correct 3 ms 1792 KB Output is correct
31 Correct 4 ms 1792 KB Output is correct
32 Correct 4 ms 1792 KB Output is correct
33 Correct 6 ms 1920 KB Output is correct
34 Correct 6 ms 1920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1792 KB Output is correct
2 Correct 4 ms 1792 KB Output is correct
3 Correct 4 ms 1792 KB Output is correct
4 Correct 4 ms 1792 KB Output is correct
5 Correct 8 ms 1792 KB Output is correct
6 Correct 3 ms 1792 KB Output is correct
7 Correct 3 ms 1792 KB Output is correct
8 Correct 3 ms 1792 KB Output is correct
9 Correct 3 ms 1792 KB Output is correct
10 Correct 4 ms 1792 KB Output is correct
11 Correct 8 ms 2048 KB Output is correct
12 Correct 5 ms 2304 KB Output is correct
13 Correct 14 ms 6256 KB Output is correct
14 Correct 6 ms 1920 KB Output is correct
15 Correct 6 ms 1920 KB Output is correct
16 Correct 10 ms 1920 KB Output is correct
17 Correct 34 ms 2360 KB Output is correct
18 Correct 24 ms 1920 KB Output is correct
19 Correct 12 ms 1892 KB Output is correct
20 Correct 189 ms 66168 KB Output is correct
21 Correct 13 ms 1792 KB Output is correct
22 Correct 21 ms 1920 KB Output is correct
23 Correct 27 ms 1920 KB Output is correct
24 Correct 70 ms 2040 KB Output is correct
25 Correct 76 ms 2040 KB Output is correct
26 Correct 18 ms 6140 KB Output is correct
27 Correct 14 ms 3968 KB Output is correct
28 Correct 142 ms 2400 KB Output is correct
29 Correct 4 ms 1792 KB Output is correct
30 Correct 4 ms 1792 KB Output is correct
31 Correct 4 ms 1792 KB Output is correct
32 Correct 4 ms 1792 KB Output is correct
33 Correct 8 ms 1920 KB Output is correct
34 Correct 9 ms 1920 KB Output is correct
35 Correct 840 ms 5944 KB Output is correct
36 Correct 115 ms 2356 KB Output is correct
37 Correct 961 ms 8952 KB Output is correct
38 Execution timed out 1058 ms 6604 KB Time limit exceeded
39 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1792 KB Output is correct
2 Correct 4 ms 1792 KB Output is correct
3 Correct 4 ms 1792 KB Output is correct
4 Correct 4 ms 1792 KB Output is correct
5 Correct 4 ms 1792 KB Output is correct
6 Correct 3 ms 1792 KB Output is correct
7 Correct 4 ms 1792 KB Output is correct
8 Correct 3 ms 1792 KB Output is correct
9 Correct 3 ms 1792 KB Output is correct
10 Correct 4 ms 1792 KB Output is correct
11 Correct 8 ms 2048 KB Output is correct
12 Correct 4 ms 2184 KB Output is correct
13 Correct 19 ms 6428 KB Output is correct
14 Correct 7 ms 1920 KB Output is correct
15 Correct 7 ms 1920 KB Output is correct
16 Correct 10 ms 1920 KB Output is correct
17 Correct 40 ms 2296 KB Output is correct
18 Correct 29 ms 1900 KB Output is correct
19 Correct 15 ms 1792 KB Output is correct
20 Correct 254 ms 66140 KB Output is correct
21 Correct 16 ms 1920 KB Output is correct
22 Correct 20 ms 1920 KB Output is correct
23 Correct 26 ms 1920 KB Output is correct
24 Correct 73 ms 2168 KB Output is correct
25 Correct 79 ms 2048 KB Output is correct
26 Correct 13 ms 6140 KB Output is correct
27 Correct 14 ms 4096 KB Output is correct
28 Correct 114 ms 2388 KB Output is correct
29 Correct 5 ms 1868 KB Output is correct
30 Correct 4 ms 1792 KB Output is correct
31 Correct 4 ms 1792 KB Output is correct
32 Correct 5 ms 1764 KB Output is correct
33 Correct 7 ms 1920 KB Output is correct
34 Correct 8 ms 1920 KB Output is correct
35 Correct 926 ms 5884 KB Output is correct
36 Correct 137 ms 2424 KB Output is correct
37 Correct 934 ms 8956 KB Output is correct
38 Execution timed out 1064 ms 6736 KB Time limit exceeded
39 Halted 0 ms 0 KB -