Submission #1017902

# Submission time Handle Problem Language Result Execution time Memory
1017902 2024-07-09T11:15:05 Z mindiyak Highway Tolls (IOI18_highway) C++14
6 / 100
229 ms 262144 KB
#include "highway.h"
#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <cmath>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<int, int> pl;
typedef pair<ld, ld> pd;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<ld> vd;
typedef vector<long> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vector<pi>> vvpi;
#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto &a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)
#define len(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define nl endl
#define S second
#define lb lower_bound
#define ub upper_bound
#define aint(x) x.begin(), x.end()
#define raint(x) x.rbegin(), x.rend()
#define ins insert
const int MOD = 1000000007;

int64_t N,M;
vi arr;
vi con;
vvpi paths;
int64_t none = 0,filled = 0;

int64_t fill_with(int a,int b){
  vi quest(M,0);
  if(a>=0 && b < M){
    FOR(i,a,b+1){
      quest[con[i]]=1;
    }
  }
  int64_t val = ask(quest);
  // cout << a << " " << b << " | ";
  // for(int i:quest)cout << i << " ";
  // cout << " - " << val << " | ";
  // cout << endl;
  return val;
}

void dfs(int pos,int prev){
  arr.pb(pos);
  for(auto a:paths[pos]){
    if(a.F == prev)continue;
    con.pb(a.S);
    dfs(a.F,pos);
  }
}

void find_pair(int n, std::vector<int> U, std::vector<int> V, int A, int B) {
  N = n;M = N-1;
  paths = vvpi(N,vpi());
  FOR(i,0,M){
    paths[U[i]].pb({V[i],i});
    paths[V[i]].pb({U[i],i});
  }
  int64_t head = -1;
  FOR(i,0,N){
    if(paths[i].size() == 1){
      head = i;
      break;
    }
  }
  dfs(head,-1);

  // for(int i:arr)cout << i << " ";
  // cout << endl;
  // for(int i:con)cout << i << " ";
  // cout << endl;

  none = fill_with(-1,-1);
  // cout << endl;
  filled = fill_with(0,M-1);
  // cout << endl;

  int64_t l=0,r=M-1;
  while(l<r){
    int64_t mid = (l+r)/2;
    int64_t count = fill_with(0,mid) - none;
    // cout << count << endl;
    if(count > 0){
      r = mid;
    }else{
      l = mid+1;
    }
  }

  int64_t start = arr[l];
  int64_t end = arr[l+(none/A)];

  // cout << start << " " << end << endl;
  answer(start,end);
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1880 KB Output is correct
2 Correct 18 ms 3664 KB Output is correct
3 Correct 23 ms 5276 KB Output is correct
4 Correct 64 ms 14964 KB Output is correct
5 Correct 67 ms 15000 KB Output is correct
6 Correct 69 ms 14980 KB Output is correct
7 Correct 62 ms 14996 KB Output is correct
8 Correct 59 ms 14980 KB Output is correct
9 Correct 64 ms 14964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 227 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 229 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -