Submission #531274

# Submission time Handle Problem Language Result Execution time Memory
531274 2022-02-28T10:39:16 Z AdamGS Highway Tolls (IOI18_highway) C++17
100 / 100
249 ms 11376 KB
#include "highway.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int MAXN=9e4+7, MAXM=13e4+7, INF=1e9+7;
vector<int>V[MAXN], kol[2], pytanie, P;
pair<int,int>kraw[MAXM];
ll dist;
int odl[MAXN], syn[MAXM], n, m;
bool ok() {
  ll x=ask(pytanie);
  return x==dist;
}
void find_pair(int N, vector<int>X, vector<int>Y, int A, int B) {
  n=N; m=X.size();
  rep(i, m) {
    pytanie.pb(0);
    kraw[i]={X[i], Y[i]};
  }
  dist=ask(pytanie);
  int p=0, k=m-1;
  while(p<k) {
    int sr=(p+k)/2;
    rep(i, m) pytanie[i]=0;
    rep(i, sr+1) pytanie[i]=1;
    if(ok()) p=sr+1; else k=sr;
  }
  rep(i, m) pytanie[i]=1;
  pytanie[p]=0;
  P.pb(p);
  for(int i=p; i<m; ++i) {
    V[kraw[i].st].pb(i);
    V[kraw[i].nd].pb(i);
  }
  queue<pair<int,int>>q;
  rep(i, n) odl[i]=INF;
  odl[kraw[p].st]=odl[kraw[p].nd]=1;
  q.push({kraw[p].st, 0});
  q.push({kraw[p].nd, 1});
  rep(i, m) syn[i]=-1;
  while(!q.empty()) {
    int v=q.front().st, r=q.front().nd; q.pop();
    for(auto i : V[v]) {
      int z=v^kraw[i].st^kraw[i].nd;
      if(odl[z]>odl[v]+1) {
        odl[z]=odl[v]+1;
        q.push({z, r});
        kol[r].pb(i);
        syn[i]=z;
        P.pb(i);
      }
    }
  }
  rep(i, 2) reverse(all(kol[i]));
  int p1=0, k1=kol[0].size();
  while(p1<k1) {
    int sr=(p1+k1)/2;
    rep(i, m) pytanie[i]=1;
    for(auto i : P) pytanie[i]=0;
    rep(i, sr+1) pytanie[kol[0][i]]=1;
    if(ok()) p1=sr+1; else k1=sr;
  }
  if(p1==kol[0].size()) p1=kraw[p].st;
  else p1=syn[kol[0][p1]];
  int p2=0, k2=kol[1].size();
  while(p2<k2) {
    int sr=(p2+k2)/2;
    rep(i, m) pytanie[i]=1;
    for(auto i : P) pytanie[i]=0;
    rep(i, sr+1) pytanie[kol[1][i]]=1;
    if(ok()) p2=sr+1; else k2=sr;
  }
  if(p2==kol[1].size()) p2=kraw[p].nd;
  else p2=syn[kol[1][p2]];
  answer(p1, p2);
}

Compilation message

highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:68:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |   if(p1==kol[0].size()) p1=kraw[p].st;
      |      ~~^~~~~~~~~~~~~~~
highway.cpp:78:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |   if(p2==kol[1].size()) p2=kraw[p].nd;
      |      ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2376 KB Output is correct
2 Correct 2 ms 2376 KB Output is correct
3 Correct 2 ms 2376 KB Output is correct
4 Correct 1 ms 2376 KB Output is correct
5 Correct 1 ms 2376 KB Output is correct
6 Correct 2 ms 2376 KB Output is correct
7 Correct 1 ms 2376 KB Output is correct
8 Correct 2 ms 2376 KB Output is correct
9 Correct 1 ms 2376 KB Output is correct
10 Correct 2 ms 2400 KB Output is correct
11 Correct 2 ms 2376 KB Output is correct
12 Correct 1 ms 2376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2504 KB Output is correct
2 Correct 14 ms 3172 KB Output is correct
3 Correct 154 ms 9732 KB Output is correct
4 Correct 149 ms 9728 KB Output is correct
5 Correct 148 ms 9876 KB Output is correct
6 Correct 98 ms 9228 KB Output is correct
7 Correct 110 ms 9188 KB Output is correct
8 Correct 125 ms 9864 KB Output is correct
9 Correct 109 ms 9136 KB Output is correct
10 Correct 161 ms 9504 KB Output is correct
11 Correct 100 ms 8588 KB Output is correct
12 Correct 149 ms 9756 KB Output is correct
13 Correct 131 ms 9768 KB Output is correct
14 Correct 173 ms 9532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 3132 KB Output is correct
2 Correct 20 ms 3844 KB Output is correct
3 Correct 42 ms 3624 KB Output is correct
4 Correct 129 ms 8128 KB Output is correct
5 Correct 134 ms 8176 KB Output is correct
6 Correct 88 ms 8972 KB Output is correct
7 Correct 119 ms 5808 KB Output is correct
8 Correct 88 ms 8424 KB Output is correct
9 Correct 84 ms 6624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2504 KB Output is correct
2 Correct 18 ms 3116 KB Output is correct
3 Correct 101 ms 8556 KB Output is correct
4 Correct 146 ms 9688 KB Output is correct
5 Correct 108 ms 8200 KB Output is correct
6 Correct 113 ms 8420 KB Output is correct
7 Correct 139 ms 9044 KB Output is correct
8 Correct 102 ms 8380 KB Output is correct
9 Correct 155 ms 9920 KB Output is correct
10 Correct 121 ms 9232 KB Output is correct
11 Correct 126 ms 9468 KB Output is correct
12 Correct 180 ms 9724 KB Output is correct
13 Correct 172 ms 9492 KB Output is correct
14 Correct 97 ms 8724 KB Output is correct
15 Correct 94 ms 8252 KB Output is correct
16 Correct 129 ms 7708 KB Output is correct
17 Correct 140 ms 9452 KB Output is correct
18 Correct 121 ms 9660 KB Output is correct
19 Correct 119 ms 8260 KB Output is correct
20 Correct 83 ms 8460 KB Output is correct
21 Correct 130 ms 8460 KB Output is correct
22 Correct 115 ms 6888 KB Output is correct
23 Correct 137 ms 10080 KB Output is correct
24 Correct 101 ms 10032 KB Output is correct
25 Correct 119 ms 9812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 3292 KB Output is correct
2 Correct 15 ms 3284 KB Output is correct
3 Correct 169 ms 10212 KB Output is correct
4 Correct 195 ms 10212 KB Output is correct
5 Correct 211 ms 10812 KB Output is correct
6 Correct 182 ms 11376 KB Output is correct
7 Correct 242 ms 10944 KB Output is correct
8 Correct 144 ms 11052 KB Output is correct
9 Correct 154 ms 6768 KB Output is correct
10 Correct 160 ms 7924 KB Output is correct
11 Correct 138 ms 8672 KB Output is correct
12 Correct 198 ms 10832 KB Output is correct
13 Correct 185 ms 11096 KB Output is correct
14 Correct 192 ms 11216 KB Output is correct
15 Correct 170 ms 11208 KB Output is correct
16 Correct 215 ms 9468 KB Output is correct
17 Correct 156 ms 9728 KB Output is correct
18 Correct 112 ms 8304 KB Output is correct
19 Correct 162 ms 10172 KB Output is correct
20 Correct 104 ms 9056 KB Output is correct
21 Correct 194 ms 11268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 3272 KB Output is correct
2 Correct 15 ms 3324 KB Output is correct
3 Correct 143 ms 10180 KB Output is correct
4 Correct 151 ms 10216 KB Output is correct
5 Correct 148 ms 10420 KB Output is correct
6 Correct 196 ms 11212 KB Output is correct
7 Correct 129 ms 10332 KB Output is correct
8 Correct 191 ms 10532 KB Output is correct
9 Correct 148 ms 10456 KB Output is correct
10 Correct 166 ms 11096 KB Output is correct
11 Correct 180 ms 11268 KB Output is correct
12 Correct 169 ms 11096 KB Output is correct
13 Correct 107 ms 6796 KB Output is correct
14 Correct 113 ms 6724 KB Output is correct
15 Correct 201 ms 9444 KB Output is correct
16 Correct 159 ms 8100 KB Output is correct
17 Correct 139 ms 8736 KB Output is correct
18 Correct 167 ms 8064 KB Output is correct
19 Correct 176 ms 10544 KB Output is correct
20 Correct 190 ms 11080 KB Output is correct
21 Correct 220 ms 11060 KB Output is correct
22 Correct 195 ms 10996 KB Output is correct
23 Correct 223 ms 11100 KB Output is correct
24 Correct 189 ms 11216 KB Output is correct
25 Correct 188 ms 11036 KB Output is correct
26 Correct 249 ms 11148 KB Output is correct
27 Correct 104 ms 9080 KB Output is correct
28 Correct 159 ms 9872 KB Output is correct
29 Correct 152 ms 10744 KB Output is correct
30 Correct 152 ms 10376 KB Output is correct
31 Correct 123 ms 10312 KB Output is correct
32 Correct 150 ms 10224 KB Output is correct
33 Correct 115 ms 10868 KB Output is correct
34 Correct 159 ms 9176 KB Output is correct
35 Correct 111 ms 9612 KB Output is correct
36 Correct 116 ms 10176 KB Output is correct
37 Correct 110 ms 10016 KB Output is correct
38 Correct 126 ms 10020 KB Output is correct
39 Correct 186 ms 11316 KB Output is correct
40 Correct 178 ms 11252 KB Output is correct
41 Correct 229 ms 11100 KB Output is correct
42 Correct 233 ms 11244 KB Output is correct