Submission #998893

# Submission time Handle Problem Language Result Execution time Memory
998893 2024-06-14T19:21:35 Z PCTprobability Highway Tolls (IOI18_highway) C++17
100 / 100
177 ms 19264 KB
#include "highway.h"
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
using ll = long long;
vector<pair<int,int>> g[101010];
vector<pair<int,int>> t[2][101010];
void find_pair(int n, std::vector<int> p, std::vector<int> q, int a, int b) {
  int m=p.size();
  for(int i=0;i<m;i++){
    g[p[i]].push_back({q[i],i});
    g[q[i]].push_back({p[i],i});
  }
  int ok=0,ng=m;
  vector<int> w(m,0);
  ll l=ask(w);
  while(abs(ok-ng)>1){
    int mid=(ok+ng)/2;
    vector<int> w2(m);
    for(int i=0;i<mid;i++) w2[i]=1;
    if(ask(w2)==l) ok=mid;
    else ng=mid;
  }
  int u=p[ok],v=q[ok],uv=ok;
  queue<int> qu;
  qu.push(u);
  qu.push(v);
  vector<int> seen(n,0);
  vector<int> d(n,0);
  vector<int> id(n,-1);
  //u,v それぞれ最短路
  seen[u]=1;
  seen[v]=2;
  while(qu.size()){
    int nv=qu.front();
    qu.pop();
    for(auto e:g[nv]){
      if(seen[e.fi]==0){
        seen[e.fi]=seen[nv];
        d[e.fi]=d[nv]+1;
        qu.push(e.fi);
        id[e.fi]=e.se;
        t[seen[e.fi]][e.fi].pb({nv,e.se});
      }
    }
  }
  int s=-1,t=-1;
  for(int ty=1;ty<=2;ty++){
    vector<pair<int,int>> vs;
    for(int i=0;i<n;i++){
      if(seen[i]==ty) vs.pb({d[i],i});
    }
    sort(vs.begin(),vs.end());
    while(vs.size()>1){
      int m2=vs.size();
      int mid=m2/2;
      vector<int> as(m,1);
      as[uv]=0;
      for(int i=0;i<n;i++) if(id[i]>=0) as[id[i]]=0;
      for(int i=mid;i<m2;i++) as[id[vs[i].se]]=1;
      ll l2=ask(as);
      if(l2==l){
        for(int i=mid;i<m2;i++) vs.pop_back();
      }
      else{
        reverse(vs.begin(),vs.end());
        for(int i=0;i<mid;i++) vs.pop_back();
        reverse(vs.begin(),vs.end());
      }
    }
    if(ty==1) s=vs[0].se;
    else t=vs[0].se;
  }
  answer(s,t);
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7764 KB Output is correct
2 Correct 3 ms 7512 KB Output is correct
3 Correct 3 ms 7512 KB Output is correct
4 Correct 3 ms 7512 KB Output is correct
5 Correct 3 ms 7512 KB Output is correct
6 Correct 3 ms 7512 KB Output is correct
7 Correct 3 ms 7512 KB Output is correct
8 Correct 3 ms 7512 KB Output is correct
9 Correct 4 ms 7512 KB Output is correct
10 Correct 3 ms 7512 KB Output is correct
11 Correct 3 ms 7512 KB Output is correct
12 Correct 4 ms 7512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7512 KB Output is correct
2 Correct 13 ms 8536 KB Output is correct
3 Correct 102 ms 17892 KB Output is correct
4 Correct 100 ms 16320 KB Output is correct
5 Correct 94 ms 16100 KB Output is correct
6 Correct 97 ms 16264 KB Output is correct
7 Correct 97 ms 16344 KB Output is correct
8 Correct 93 ms 16320 KB Output is correct
9 Correct 103 ms 17868 KB Output is correct
10 Correct 98 ms 16100 KB Output is correct
11 Correct 98 ms 16572 KB Output is correct
12 Correct 101 ms 17108 KB Output is correct
13 Correct 97 ms 16820 KB Output is correct
14 Correct 102 ms 17380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 8536 KB Output is correct
2 Correct 18 ms 9304 KB Output is correct
3 Correct 26 ms 10680 KB Output is correct
4 Correct 74 ms 15944 KB Output is correct
5 Correct 65 ms 15976 KB Output is correct
6 Correct 86 ms 16212 KB Output is correct
7 Correct 74 ms 17344 KB Output is correct
8 Correct 74 ms 15880 KB Output is correct
9 Correct 72 ms 17152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7512 KB Output is correct
2 Correct 14 ms 8536 KB Output is correct
3 Correct 72 ms 14248 KB Output is correct
4 Correct 93 ms 16088 KB Output is correct
5 Correct 96 ms 17884 KB Output is correct
6 Correct 87 ms 16324 KB Output is correct
7 Correct 107 ms 17976 KB Output is correct
8 Correct 94 ms 17892 KB Output is correct
9 Correct 109 ms 17792 KB Output is correct
10 Correct 105 ms 17892 KB Output is correct
11 Correct 103 ms 17368 KB Output is correct
12 Correct 99 ms 16884 KB Output is correct
13 Correct 101 ms 17092 KB Output is correct
14 Correct 98 ms 16388 KB Output is correct
15 Correct 88 ms 16080 KB Output is correct
16 Correct 93 ms 16228 KB Output is correct
17 Correct 107 ms 17344 KB Output is correct
18 Correct 112 ms 17380 KB Output is correct
19 Correct 88 ms 18076 KB Output is correct
20 Correct 96 ms 16924 KB Output is correct
21 Correct 81 ms 15696 KB Output is correct
22 Correct 83 ms 18672 KB Output is correct
23 Correct 86 ms 16540 KB Output is correct
24 Correct 91 ms 16340 KB Output is correct
25 Correct 111 ms 17428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 8280 KB Output is correct
2 Correct 16 ms 8824 KB Output is correct
3 Correct 113 ms 16824 KB Output is correct
4 Correct 127 ms 18212 KB Output is correct
5 Correct 147 ms 18052 KB Output is correct
6 Correct 148 ms 17744 KB Output is correct
7 Correct 159 ms 17836 KB Output is correct
8 Correct 163 ms 18116 KB Output is correct
9 Correct 127 ms 15656 KB Output is correct
10 Correct 103 ms 14860 KB Output is correct
11 Correct 115 ms 16204 KB Output is correct
12 Correct 139 ms 17332 KB Output is correct
13 Correct 177 ms 17488 KB Output is correct
14 Correct 140 ms 17940 KB Output is correct
15 Correct 162 ms 19012 KB Output is correct
16 Correct 122 ms 16212 KB Output is correct
17 Correct 97 ms 18384 KB Output is correct
18 Correct 95 ms 15952 KB Output is correct
19 Correct 104 ms 18644 KB Output is correct
20 Correct 93 ms 15992 KB Output is correct
21 Correct 167 ms 18412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 8792 KB Output is correct
2 Correct 14 ms 8792 KB Output is correct
3 Correct 107 ms 16688 KB Output is correct
4 Correct 117 ms 16848 KB Output is correct
5 Correct 126 ms 16852 KB Output is correct
6 Correct 149 ms 18356 KB Output is correct
7 Correct 124 ms 16780 KB Output is correct
8 Correct 115 ms 17032 KB Output is correct
9 Correct 120 ms 17496 KB Output is correct
10 Correct 165 ms 18024 KB Output is correct
11 Correct 150 ms 18292 KB Output is correct
12 Correct 156 ms 18660 KB Output is correct
13 Correct 110 ms 15032 KB Output is correct
14 Correct 99 ms 15500 KB Output is correct
15 Correct 107 ms 15024 KB Output is correct
16 Correct 121 ms 15500 KB Output is correct
17 Correct 105 ms 15016 KB Output is correct
18 Correct 104 ms 14920 KB Output is correct
19 Correct 151 ms 17648 KB Output is correct
20 Correct 136 ms 18748 KB Output is correct
21 Correct 150 ms 17924 KB Output is correct
22 Correct 150 ms 17928 KB Output is correct
23 Correct 145 ms 18148 KB Output is correct
24 Correct 143 ms 18276 KB Output is correct
25 Correct 152 ms 18976 KB Output is correct
26 Correct 154 ms 19264 KB Output is correct
27 Correct 110 ms 18628 KB Output is correct
28 Correct 91 ms 15996 KB Output is correct
29 Correct 95 ms 18912 KB Output is correct
30 Correct 95 ms 18632 KB Output is correct
31 Correct 95 ms 18636 KB Output is correct
32 Correct 95 ms 18372 KB Output is correct
33 Correct 86 ms 15996 KB Output is correct
34 Correct 106 ms 18468 KB Output is correct
35 Correct 114 ms 18400 KB Output is correct
36 Correct 106 ms 15740 KB Output is correct
37 Correct 100 ms 18652 KB Output is correct
38 Correct 86 ms 16012 KB Output is correct
39 Correct 160 ms 18252 KB Output is correct
40 Correct 146 ms 19256 KB Output is correct
41 Correct 146 ms 18280 KB Output is correct
42 Correct 144 ms 18524 KB Output is correct