답안 #915406

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
915406 2024-01-23T20:01:14 Z biank 통행료 (IOI18_highway) C++14
51 / 100
1500 ms 12108 KB
#include <bits/stdc++.h>
using namespace std;
#define SIZE(x) int(x.size())
#define forn(i,n) for(int i=0;i<int(n);i++)
#define pb push_back
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long long ll;
ll ask(const vi &w);
void answer(int s, int t);
const int MAXN = 90000;
int d[2][MAXN];
vector<ii> adj[MAXN];
int c=0;

void find_pair(int n, vi u, vi v, int /*a*/, int /*b*/) {
    int m=SIZE(u);
    forn(i,m) {
        adj[u[i]].pb({v[i],i});
        adj[v[i]].pb({u[i],i});
    }
    
    vi w(m,0);
    ll D=ask(w);
    
    auto bs=[&](int lo, int hi) {
        while(hi-lo>1) {
            int mid=(lo+hi)/2;
            forn(i,m) w[i]=i<=mid;
            if(ask(w)!=D) hi=mid;
            else lo=mid;
        }
        return hi;
    };
    
    int e=bs(-1,m);
    int start[2]={u[e],v[e]};
    memset(d,-1,sizeof d);
    forn(i,2) {
        queue<int> q;
        q.push(start[i]);
        int dist=0;
        while(!q.empty()) {
            int sz=SIZE(q);
            forn(_,sz) {
                int x=q.front();
                q.pop();
                d[i][x]=dist;
                for(auto [y,__]:adj[x]) {
                    if(d[i][y]==-1) q.push(y);
                }
            }
            dist++;
        }
    }
    
    int ans[2];
    forn(i,2) {
        vi node(n,0), edge(m,-1), dist(n,-1);
        queue<int> q;
        c=0;
        q.push(start[i]);
        dist[start[i]]=0;
        
        while(!q.empty()) {
            int x=q.front();
            q.pop();
            for(auto [y,idx]:adj[x]) {
                if(d[i][y]<d[1-i][y] && dist[y]==-1) {
                    dist[y]=dist[x]+1;
                    node[c]=y;
                    edge[idx]=c++;
                    q.push(y);
                } else if((d[i][y]>=d[1-i][y] && idx!=e)||dist[y]==dist[x]+1) {
                    edge[idx]=n;
                }
            }
        }
        
        int lo=-1, hi=c;
        while(hi-lo>1) {
            int mid=(lo+hi)/2;
            forn(j,m) w[j]=edge[j]>=mid;
            if(ask(w)!=D) lo=mid;
            else hi=mid;
        }
        if(lo==-1) ans[i]=start[i];
        else ans[i]=node[lo];
    }
    
    answer(ans[0],ans[1]);
}

Compilation message

highway.cpp: In function 'void find_pair(int, vi, vi, int, int)':
highway.cpp:49:26: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   49 |                 for(auto [y,__]:adj[x]) {
      |                          ^
highway.cpp:68:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   68 |             for(auto [y,idx]:adj[x]) {
      |                      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3184 KB Output is correct
2 Correct 1 ms 3184 KB Output is correct
3 Correct 1 ms 3432 KB Output is correct
4 Correct 1 ms 3184 KB Output is correct
5 Correct 1 ms 3188 KB Output is correct
6 Correct 1 ms 3180 KB Output is correct
7 Correct 1 ms 3184 KB Output is correct
8 Correct 1 ms 3180 KB Output is correct
9 Correct 1 ms 3432 KB Output is correct
10 Correct 1 ms 3188 KB Output is correct
11 Correct 1 ms 3184 KB Output is correct
12 Correct 1 ms 3180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3232 KB Output is correct
2 Correct 11 ms 3968 KB Output is correct
3 Correct 82 ms 9960 KB Output is correct
4 Correct 90 ms 9480 KB Output is correct
5 Correct 97 ms 9492 KB Output is correct
6 Correct 98 ms 9708 KB Output is correct
7 Correct 122 ms 9736 KB Output is correct
8 Correct 86 ms 9680 KB Output is correct
9 Correct 96 ms 9708 KB Output is correct
10 Correct 160 ms 9484 KB Output is correct
11 Correct 98 ms 9132 KB Output is correct
12 Correct 125 ms 9116 KB Output is correct
13 Correct 93 ms 9116 KB Output is correct
14 Correct 100 ms 9088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 3852 KB Output is correct
2 Correct 15 ms 4516 KB Output is correct
3 Correct 55 ms 5128 KB Output is correct
4 Correct 64 ms 9156 KB Output is correct
5 Correct 69 ms 9128 KB Output is correct
6 Correct 64 ms 9108 KB Output is correct
7 Correct 65 ms 9116 KB Output is correct
8 Correct 68 ms 8880 KB Output is correct
9 Correct 67 ms 9132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3228 KB Output is correct
2 Correct 16 ms 3944 KB Output is correct
3 Correct 61 ms 8112 KB Output is correct
4 Correct 129 ms 9472 KB Output is correct
5 Correct 72 ms 10060 KB Output is correct
6 Correct 90 ms 9472 KB Output is correct
7 Correct 106 ms 9484 KB Output is correct
8 Correct 74 ms 9672 KB Output is correct
9 Correct 104 ms 10068 KB Output is correct
10 Correct 144 ms 9960 KB Output is correct
11 Correct 94 ms 9360 KB Output is correct
12 Correct 90 ms 9036 KB Output is correct
13 Correct 109 ms 9532 KB Output is correct
14 Correct 96 ms 9120 KB Output is correct
15 Correct 77 ms 9720 KB Output is correct
16 Correct 80 ms 9488 KB Output is correct
17 Correct 121 ms 9116 KB Output is correct
18 Correct 86 ms 8888 KB Output is correct
19 Correct 79 ms 9716 KB Output is correct
20 Correct 88 ms 9040 KB Output is correct
21 Correct 69 ms 10212 KB Output is correct
22 Correct 75 ms 9968 KB Output is correct
23 Correct 118 ms 9776 KB Output is correct
24 Correct 100 ms 9940 KB Output is correct
25 Correct 91 ms 8996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 3948 KB Output is correct
2 Correct 13 ms 4036 KB Output is correct
3 Correct 125 ms 10300 KB Output is correct
4 Correct 127 ms 10736 KB Output is correct
5 Correct 152 ms 12008 KB Output is correct
6 Correct 159 ms 12108 KB Output is correct
7 Correct 155 ms 11800 KB Output is correct
8 Correct 155 ms 11860 KB Output is correct
9 Execution timed out 2778 ms 9536 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 3972 KB Output is correct
2 Correct 27 ms 4196 KB Output is correct
3 Correct 165 ms 10848 KB Output is correct
4 Correct 146 ms 10612 KB Output is correct
5 Correct 149 ms 10672 KB Output is correct
6 Correct 188 ms 11880 KB Output is correct
7 Correct 151 ms 10260 KB Output is correct
8 Correct 130 ms 10384 KB Output is correct
9 Correct 224 ms 10976 KB Output is correct
10 Correct 224 ms 11972 KB Output is correct
11 Correct 168 ms 12072 KB Output is correct
12 Correct 169 ms 11984 KB Output is correct
13 Execution timed out 3089 ms 9612 KB Time limit exceeded
14 Halted 0 ms 0 KB -