답안 #780709

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
780709 2023-07-12T11:57:15 Z vjudge1 Simurgh (IOI17_simurgh) C++17
70 / 100
79 ms 8452 KB
#include <bits/stdc++.h>
#include "simurgh.h"

#define all(x) (x).begin(),(x).end()
using namespace std;

//#define ask count_common_roads 

using ll = long long;
using ld = long double;

//#define int ll
#define sz(x) ((int)(x).size())

using pii = pair<int,int>;
using tii = tuple<int,int,int>;

const int nmax = 500;

vector<pii> g[nmax];
vector<int> occ;
vector<int> candr;
int flag;

int cnt = 0;
int ask(vector<int> r) {
  return count_common_roads(r);
}

void dfs(int x) {
  occ[x] = flag;
  for(auto [y, ptr] : g[x]) {
    if(occ[y] != 0) continue;
    //cerr << x << ' ' << y << '\t' << ptr << '\n';
    occ[y] = flag;
    candr.emplace_back(ptr);
    dfs(y);
  }
  return;
}

int mat[nmax][nmax];
  vector<int> isgood;
  vector<int> checked;

void solvefori(int i) {
  fill(all(occ), 0);
  candr.clear();
  occ[i] = -1;
  vector<vector<int>> atrs;
  atrs.emplace_back();
  vector<int> nv;
  flag = 0;
  for(auto [x, ptr] : g[i]) {
    if(occ[x] == 0) {
      flag++;
      dfs(x);
      nv.emplace_back(ptr);
      atrs.emplace_back();
      atrs.back().emplace_back(ptr);
    }
    else
      atrs[occ[x]].emplace_back(ptr);
  }
  
  int startmn = sz(candr) - 1;
  copy(all(nv), back_inserter(candr));
  
  for(int i = 1; i <= flag; i++) {
    //cerr << "--\n";
    vector<int> rez;
    int mx = -1; 
    for(int j = 0; j < sz(atrs[i]); j++) {
      int u = atrs[i][j];
      candr[startmn + i] = u;
      if(checked[u] && isgood[u]) { mx = ask(candr); break; }
    }
    for(int j = 0; j < sz(atrs[i]); j++) {
      int u = atrs[i][j];
      candr[startmn + i] = u;
      if(!checked[u])
        rez.emplace_back(ask(candr));
      else
        rez.emplace_back(-1);
    }
    if(mx == -1)
      mx = *max_element(all(rez));
    for(int j = 0; j < sz(atrs[i]); j++) {
      checked[atrs[i][j]] = 1;
      if(rez[j] == mx)
        isgood[atrs[i][j]] = 1;
    }
  }
}

vector<int> S4(int n, vector<int> u, vector<int> v) {
  for(int i = 0; i < sz(u); i++) {
    mat[u[i]][v[i]] = i;
    mat[v[i]][u[i]] = i;
    
    g[u[i]].emplace_back(v[i], i);
    g[v[i]].emplace_back(u[i], i);
  }
  
  //cerr << "yura\n";
  solvefori(0);
  for(int j = 1; j < n; j++) checked[mat[j][0]] = 1;
  for(int i = 1; i < n; i++) {
    vector<int> crr;
    for(int j = 0; j < n; j++) {
      if(j == i) continue;
      crr.emplace_back(mat[i][j]);
    }
    int totaltf = ask(crr);
    for(int j = 0; j < i; j++)
      totaltf -= isgood[mat[i][j]];
    for(int smth = 0; smth < totaltf; smth++) {
      auto trywith = [&](int lim) {
        vector<int> ntwr;
        ntwr.emplace_back(mat[0][i]);
        int expected = isgood[mat[0][i]];
        for(int j = 1; j <= lim; j++) {
          if(j == i) continue;
          ntwr.emplace_back(mat[i][j]);
          if(checked[mat[i][j]]) expected += isgood[mat[i][j]];
        }
        for(int j = lim + 1; j < n; j++) {
          if(j == i) continue;
          ntwr.emplace_back(mat[0][j]);
          if(checked[mat[0][j]]) expected += isgood[mat[0][j]];
        }
        return ask(ntwr) - expected;
      };
      int lim = i - 1;
      
      for(int i = 9; i >= 0; i--) {
        if(lim + (1 << i) >= n) continue;
        if(trywith(lim + (1 << i)) <= 0) lim += (1 << i);
      }
      lim++;
      checked[mat[i][lim]] = 1;
      isgood[mat[i][lim]] = 1;
    }
    
    for(int j = 0; j < n; j++) {
      if(j == i) continue;
      checked[mat[i][j]] = 1;
    }
      
  }
  vector<int> lst;
  for(int i = 0; i < sz(isgood); i++)
    if(isgood[i])
      lst.emplace_back(i);
  return lst;
}

std::vector<int> find_roads(int n, std::vector<int> u, std::vector<int> v) {
  isgood.resize(sz(u));
  checked.resize(sz(u));
  occ.resize(n);
  if(n > 240)
   return S4(n, u, v);
  for(int i = 0; i < sz(u); i++) {
    g[u[i]].emplace_back(v[i], i);
    g[v[i]].emplace_back(u[i], i);
  }
  
  for(int i = 0; i < n; i++) {
    solvefori(i);
  }
  
  vector<int> lst;
  for(int i = 0; i < sz(isgood); i++)
    if(isgood[i])
      lst.emplace_back(i);
  
  //for(auto x : lst)
    //cerr << x << ' ';
  //cerr << '\n';
  
  return lst;
}



/**
      Anul asta se da centroid.
-- Surse oficiale
*/

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB correct
2 Correct 1 ms 212 KB correct
3 Correct 0 ms 212 KB correct
4 Correct 1 ms 212 KB correct
5 Correct 1 ms 212 KB correct
6 Correct 0 ms 212 KB correct
7 Correct 0 ms 212 KB correct
8 Correct 0 ms 212 KB correct
9 Correct 0 ms 212 KB correct
10 Correct 1 ms 212 KB correct
11 Correct 0 ms 212 KB correct
12 Correct 1 ms 212 KB correct
13 Correct 0 ms 212 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB correct
2 Correct 1 ms 212 KB correct
3 Correct 0 ms 212 KB correct
4 Correct 1 ms 212 KB correct
5 Correct 1 ms 212 KB correct
6 Correct 0 ms 212 KB correct
7 Correct 0 ms 212 KB correct
8 Correct 0 ms 212 KB correct
9 Correct 0 ms 212 KB correct
10 Correct 1 ms 212 KB correct
11 Correct 0 ms 212 KB correct
12 Correct 1 ms 212 KB correct
13 Correct 0 ms 212 KB correct
14 Correct 1 ms 340 KB correct
15 Correct 1 ms 340 KB correct
16 Correct 1 ms 340 KB correct
17 Correct 1 ms 340 KB correct
18 Correct 1 ms 340 KB correct
19 Correct 1 ms 340 KB correct
20 Correct 1 ms 340 KB correct
21 Correct 1 ms 340 KB correct
22 Correct 1 ms 340 KB correct
23 Correct 1 ms 340 KB correct
24 Correct 1 ms 340 KB correct
25 Correct 1 ms 212 KB correct
26 Correct 2 ms 340 KB correct
27 Correct 1 ms 340 KB correct
28 Correct 1 ms 340 KB correct
29 Correct 1 ms 212 KB correct
30 Correct 1 ms 340 KB correct
31 Correct 1 ms 244 KB correct
32 Correct 1 ms 340 KB correct
33 Correct 1 ms 340 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB correct
2 Correct 1 ms 212 KB correct
3 Correct 0 ms 212 KB correct
4 Correct 1 ms 212 KB correct
5 Correct 1 ms 212 KB correct
6 Correct 0 ms 212 KB correct
7 Correct 0 ms 212 KB correct
8 Correct 0 ms 212 KB correct
9 Correct 0 ms 212 KB correct
10 Correct 1 ms 212 KB correct
11 Correct 0 ms 212 KB correct
12 Correct 1 ms 212 KB correct
13 Correct 0 ms 212 KB correct
14 Correct 1 ms 340 KB correct
15 Correct 1 ms 340 KB correct
16 Correct 1 ms 340 KB correct
17 Correct 1 ms 340 KB correct
18 Correct 1 ms 340 KB correct
19 Correct 1 ms 340 KB correct
20 Correct 1 ms 340 KB correct
21 Correct 1 ms 340 KB correct
22 Correct 1 ms 340 KB correct
23 Correct 1 ms 340 KB correct
24 Correct 1 ms 340 KB correct
25 Correct 1 ms 212 KB correct
26 Correct 2 ms 340 KB correct
27 Correct 1 ms 340 KB correct
28 Correct 1 ms 340 KB correct
29 Correct 1 ms 212 KB correct
30 Correct 1 ms 340 KB correct
31 Correct 1 ms 244 KB correct
32 Correct 1 ms 340 KB correct
33 Correct 1 ms 340 KB correct
34 Correct 77 ms 1492 KB correct
35 Correct 73 ms 1492 KB correct
36 Correct 52 ms 1236 KB correct
37 Correct 6 ms 340 KB correct
38 Correct 79 ms 1492 KB correct
39 Correct 69 ms 1468 KB correct
40 Correct 52 ms 1336 KB correct
41 Correct 79 ms 1564 KB correct
42 Correct 79 ms 1492 KB correct
43 Correct 43 ms 1108 KB correct
44 Correct 35 ms 852 KB correct
45 Correct 40 ms 852 KB correct
46 Correct 31 ms 724 KB correct
47 Correct 15 ms 584 KB correct
48 Correct 2 ms 340 KB correct
49 Correct 5 ms 340 KB correct
50 Correct 15 ms 580 KB correct
51 Correct 40 ms 948 KB correct
52 Correct 36 ms 852 KB correct
53 Correct 32 ms 784 KB correct
54 Correct 42 ms 1108 KB correct
55 Correct 39 ms 944 KB correct
56 Correct 39 ms 936 KB correct
57 Correct 41 ms 852 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB correct
2 Correct 1 ms 212 KB correct
3 Correct 35 ms 5460 KB correct
4 Correct 54 ms 8328 KB correct
5 Correct 54 ms 8396 KB correct
6 Correct 53 ms 8404 KB correct
7 Correct 55 ms 8400 KB correct
8 Correct 53 ms 8404 KB correct
9 Correct 64 ms 8332 KB correct
10 Correct 53 ms 8324 KB correct
11 Correct 52 ms 8388 KB correct
12 Correct 56 ms 8440 KB correct
13 Correct 1 ms 212 KB correct
14 Correct 55 ms 8452 KB correct
15 Correct 53 ms 8396 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB correct
2 Correct 1 ms 212 KB correct
3 Correct 0 ms 212 KB correct
4 Correct 1 ms 212 KB correct
5 Correct 1 ms 212 KB correct
6 Correct 0 ms 212 KB correct
7 Correct 0 ms 212 KB correct
8 Correct 0 ms 212 KB correct
9 Correct 0 ms 212 KB correct
10 Correct 1 ms 212 KB correct
11 Correct 0 ms 212 KB correct
12 Correct 1 ms 212 KB correct
13 Correct 0 ms 212 KB correct
14 Correct 1 ms 340 KB correct
15 Correct 1 ms 340 KB correct
16 Correct 1 ms 340 KB correct
17 Correct 1 ms 340 KB correct
18 Correct 1 ms 340 KB correct
19 Correct 1 ms 340 KB correct
20 Correct 1 ms 340 KB correct
21 Correct 1 ms 340 KB correct
22 Correct 1 ms 340 KB correct
23 Correct 1 ms 340 KB correct
24 Correct 1 ms 340 KB correct
25 Correct 1 ms 212 KB correct
26 Correct 2 ms 340 KB correct
27 Correct 1 ms 340 KB correct
28 Correct 1 ms 340 KB correct
29 Correct 1 ms 212 KB correct
30 Correct 1 ms 340 KB correct
31 Correct 1 ms 244 KB correct
32 Correct 1 ms 340 KB correct
33 Correct 1 ms 340 KB correct
34 Correct 77 ms 1492 KB correct
35 Correct 73 ms 1492 KB correct
36 Correct 52 ms 1236 KB correct
37 Correct 6 ms 340 KB correct
38 Correct 79 ms 1492 KB correct
39 Correct 69 ms 1468 KB correct
40 Correct 52 ms 1336 KB correct
41 Correct 79 ms 1564 KB correct
42 Correct 79 ms 1492 KB correct
43 Correct 43 ms 1108 KB correct
44 Correct 35 ms 852 KB correct
45 Correct 40 ms 852 KB correct
46 Correct 31 ms 724 KB correct
47 Correct 15 ms 584 KB correct
48 Correct 2 ms 340 KB correct
49 Correct 5 ms 340 KB correct
50 Correct 15 ms 580 KB correct
51 Correct 40 ms 948 KB correct
52 Correct 36 ms 852 KB correct
53 Correct 32 ms 784 KB correct
54 Correct 42 ms 1108 KB correct
55 Correct 39 ms 944 KB correct
56 Correct 39 ms 936 KB correct
57 Correct 41 ms 852 KB correct
58 Correct 0 ms 212 KB correct
59 Correct 1 ms 212 KB correct
60 Correct 35 ms 5460 KB correct
61 Correct 54 ms 8328 KB correct
62 Correct 54 ms 8396 KB correct
63 Correct 53 ms 8404 KB correct
64 Correct 55 ms 8400 KB correct
65 Correct 53 ms 8404 KB correct
66 Correct 64 ms 8332 KB correct
67 Correct 53 ms 8324 KB correct
68 Correct 52 ms 8388 KB correct
69 Correct 56 ms 8440 KB correct
70 Correct 1 ms 212 KB correct
71 Correct 55 ms 8452 KB correct
72 Correct 53 ms 8396 KB correct
73 Correct 1 ms 212 KB correct
74 Correct 54 ms 8392 KB correct
75 Incorrect 22 ms 8172 KB WA in grader: NO
76 Halted 0 ms 0 KB -