답안 #695142

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
695142 2023-02-04T18:38:44 Z Abito Jakarta Skyscrapers (APIO15_skyscraper) C++17
57 / 100
1000 ms 71192 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define F first
#define S second
#define int long long
const int N=3e4+5;
int a[N],b[N],n,m,dis[N];
vector<pair<int,int>> adj[N];
vector<int> d[N],p[N];
bool vis[N];
priority_queue<pair<int,int>> pq;
void getdiv(int x){
    for (int i=1;i*i<=x;i++){
        if (x%i) continue;
        int y=i,z=x/i;
        d[x].pb(y);
        if (y!=z) d[x].pb(z);
    }sort(d[x].begin(),d[x].end());
    return;
}
void dijkstra(){
    pq.push({0,a[0]});
    while (!pq.empty()){
        pair<int,int> x=pq.top();
        x.F*=-1;pq.pop();
        if (vis[x.S]) continue;
        vis[x.S]=true;
        for (auto u:adj[x.S]){
            if (dis[u.F]<=x.F+u.S) continue;
            dis[u.F]=x.F+u.S;
            pq.push({-dis[u.F],u.F});
        }
    }return;
}
int32_t main(){
    for (int i=0;i<N;i++){
        getdiv(i);
        dis[i]=INT_MAX;
    }cin>>n>>m;
    for (int i=0;i<m;i++){
        cin>>a[i]>>b[i];
        p[a[i]].pb(b[i]);
    }dis[a[0]]=0;
    for (int i=0;i<n;i++) sort(p[i].begin(),p[i].end());
    for (int i=0;i<n;i++){
        for (int j=0;j<n;j++){
            if (i==j) continue;
            int dist=abs(i-j),x=0,y=0,ans=INT_MAX;
            while (x<d[dist].size() && y<p[i].size()){
                if (d[dist][x]==p[i][y]){
                    ans=dist/d[dist][x];
                    x++;
                    y++;
                    continue;
                }
                if (d[dist][x]<p[i][y]) x++;
                else y++;
            }
            if (ans==INT_MAX) continue;
            adj[i].pb({j,ans});
        }
    }dijkstra();
    if (dis[a[1]]==INT_MAX) cout<<-1<<endl;
    else cout<<dis[a[1]]<<endl;
    return 0;
}

Compilation message

skyscraper.cpp: In function 'int32_t main()':
skyscraper.cpp:50:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |             while (x<d[dist].size() && y<p[i].size()){
      |                    ~^~~~~~~~~~~~~~~
skyscraper.cpp:50:41: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |             while (x<d[dist].size() && y<p[i].size()){
      |                                        ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 5964 KB Output is correct
2 Correct 29 ms 6024 KB Output is correct
3 Correct 29 ms 5952 KB Output is correct
4 Correct 30 ms 6100 KB Output is correct
5 Correct 29 ms 5972 KB Output is correct
6 Correct 30 ms 5972 KB Output is correct
7 Correct 29 ms 5996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 5972 KB Output is correct
2 Correct 30 ms 6088 KB Output is correct
3 Correct 29 ms 6044 KB Output is correct
4 Correct 31 ms 6068 KB Output is correct
5 Correct 33 ms 6016 KB Output is correct
6 Correct 30 ms 6024 KB Output is correct
7 Correct 30 ms 6028 KB Output is correct
8 Correct 31 ms 5964 KB Output is correct
9 Correct 30 ms 6024 KB Output is correct
10 Correct 30 ms 6028 KB Output is correct
11 Correct 33 ms 6248 KB Output is correct
12 Correct 31 ms 6092 KB Output is correct
13 Correct 32 ms 6344 KB Output is correct
14 Correct 32 ms 6092 KB Output is correct
15 Correct 31 ms 6120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 6080 KB Output is correct
2 Correct 30 ms 6100 KB Output is correct
3 Correct 31 ms 6044 KB Output is correct
4 Correct 30 ms 5968 KB Output is correct
5 Correct 30 ms 6004 KB Output is correct
6 Correct 30 ms 6072 KB Output is correct
7 Correct 33 ms 5992 KB Output is correct
8 Correct 30 ms 6072 KB Output is correct
9 Correct 32 ms 6064 KB Output is correct
10 Correct 34 ms 6088 KB Output is correct
11 Correct 34 ms 6184 KB Output is correct
12 Correct 32 ms 6024 KB Output is correct
13 Correct 33 ms 6236 KB Output is correct
14 Correct 31 ms 6132 KB Output is correct
15 Correct 31 ms 6148 KB Output is correct
16 Correct 31 ms 6092 KB Output is correct
17 Correct 43 ms 6640 KB Output is correct
18 Correct 61 ms 6160 KB Output is correct
19 Correct 60 ms 6148 KB Output is correct
20 Correct 110 ms 70320 KB Output is correct
21 Correct 32 ms 6132 KB Output is correct
22 Correct 56 ms 6136 KB Output is correct
23 Correct 57 ms 6288 KB Output is correct
24 Correct 83 ms 6468 KB Output is correct
25 Correct 85 ms 6356 KB Output is correct
26 Correct 49 ms 6304 KB Output is correct
27 Correct 55 ms 6184 KB Output is correct
28 Correct 110 ms 6624 KB Output is correct
29 Correct 52 ms 6788 KB Output is correct
30 Correct 44 ms 6432 KB Output is correct
31 Correct 47 ms 6748 KB Output is correct
32 Correct 45 ms 6600 KB Output is correct
33 Correct 52 ms 7252 KB Output is correct
34 Correct 59 ms 7268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 6076 KB Output is correct
2 Correct 31 ms 6072 KB Output is correct
3 Correct 31 ms 6072 KB Output is correct
4 Correct 30 ms 5960 KB Output is correct
5 Correct 31 ms 6060 KB Output is correct
6 Correct 31 ms 6100 KB Output is correct
7 Correct 32 ms 6088 KB Output is correct
8 Correct 37 ms 6048 KB Output is correct
9 Correct 30 ms 5976 KB Output is correct
10 Correct 31 ms 6100 KB Output is correct
11 Correct 32 ms 6220 KB Output is correct
12 Correct 42 ms 6076 KB Output is correct
13 Correct 32 ms 6240 KB Output is correct
14 Correct 32 ms 6216 KB Output is correct
15 Correct 32 ms 6212 KB Output is correct
16 Correct 34 ms 6220 KB Output is correct
17 Correct 44 ms 6588 KB Output is correct
18 Correct 62 ms 6152 KB Output is correct
19 Correct 75 ms 6140 KB Output is correct
20 Correct 113 ms 70304 KB Output is correct
21 Correct 34 ms 6092 KB Output is correct
22 Correct 60 ms 6192 KB Output is correct
23 Correct 56 ms 6156 KB Output is correct
24 Correct 91 ms 6464 KB Output is correct
25 Correct 101 ms 6348 KB Output is correct
26 Correct 68 ms 6372 KB Output is correct
27 Correct 50 ms 6184 KB Output is correct
28 Correct 113 ms 6612 KB Output is correct
29 Correct 48 ms 6804 KB Output is correct
30 Correct 46 ms 6504 KB Output is correct
31 Correct 50 ms 6836 KB Output is correct
32 Correct 50 ms 6608 KB Output is correct
33 Correct 54 ms 7256 KB Output is correct
34 Correct 56 ms 7164 KB Output is correct
35 Correct 128 ms 9612 KB Output is correct
36 Correct 87 ms 6552 KB Output is correct
37 Correct 219 ms 12520 KB Output is correct
38 Correct 220 ms 11728 KB Output is correct
39 Correct 210 ms 11964 KB Output is correct
40 Correct 214 ms 11772 KB Output is correct
41 Correct 216 ms 11428 KB Output is correct
42 Correct 114 ms 7180 KB Output is correct
43 Correct 122 ms 7132 KB Output is correct
44 Correct 172 ms 71168 KB Output is correct
45 Correct 135 ms 11284 KB Output is correct
46 Correct 126 ms 11300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 6044 KB Output is correct
2 Correct 30 ms 5964 KB Output is correct
3 Correct 30 ms 6080 KB Output is correct
4 Correct 30 ms 5964 KB Output is correct
5 Correct 30 ms 6100 KB Output is correct
6 Correct 29 ms 6040 KB Output is correct
7 Correct 31 ms 6100 KB Output is correct
8 Correct 29 ms 6072 KB Output is correct
9 Correct 30 ms 6064 KB Output is correct
10 Correct 30 ms 6028 KB Output is correct
11 Correct 31 ms 6220 KB Output is correct
12 Correct 31 ms 6088 KB Output is correct
13 Correct 31 ms 6260 KB Output is correct
14 Correct 33 ms 6092 KB Output is correct
15 Correct 34 ms 6176 KB Output is correct
16 Correct 33 ms 6120 KB Output is correct
17 Correct 42 ms 6612 KB Output is correct
18 Correct 62 ms 6132 KB Output is correct
19 Correct 58 ms 6196 KB Output is correct
20 Correct 105 ms 70376 KB Output is correct
21 Correct 36 ms 6092 KB Output is correct
22 Correct 59 ms 6208 KB Output is correct
23 Correct 57 ms 6204 KB Output is correct
24 Correct 81 ms 6424 KB Output is correct
25 Correct 84 ms 6344 KB Output is correct
26 Correct 55 ms 6316 KB Output is correct
27 Correct 48 ms 6220 KB Output is correct
28 Correct 103 ms 6608 KB Output is correct
29 Correct 48 ms 6848 KB Output is correct
30 Correct 44 ms 6440 KB Output is correct
31 Correct 54 ms 6732 KB Output is correct
32 Correct 50 ms 6624 KB Output is correct
33 Correct 51 ms 7224 KB Output is correct
34 Correct 51 ms 7244 KB Output is correct
35 Correct 120 ms 9616 KB Output is correct
36 Correct 59 ms 6592 KB Output is correct
37 Correct 204 ms 12472 KB Output is correct
38 Correct 208 ms 11644 KB Output is correct
39 Correct 218 ms 11932 KB Output is correct
40 Correct 212 ms 11676 KB Output is correct
41 Correct 212 ms 11576 KB Output is correct
42 Correct 125 ms 7176 KB Output is correct
43 Correct 114 ms 7112 KB Output is correct
44 Correct 176 ms 71192 KB Output is correct
45 Correct 124 ms 11368 KB Output is correct
46 Correct 124 ms 11492 KB Output is correct
47 Execution timed out 1094 ms 12480 KB Time limit exceeded
48 Halted 0 ms 0 KB -