제출 #604899

#제출 시각아이디문제언어결과실행 시간메모리
604899Sam_a17기지국 (IOI20_stations)C++14
0 / 100
794 ms500 KiB
#include <bits/stdc++.h>
using namespace std;
 
#define sz(x) (int((x).size()))
#define len(x) (int)x.length()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define dbg(x) cout << #x << " " << x << endl;
#define uniq(x) x.resize(unique(all(x)) - x.begin());
 
#define pb push_back
#define ld long double
#define ll long long
 
void pr(vector<int>& a) {
  cerr << "arr" << " ";
  for(auto i: a) {
    cerr << i << " "; 
  } cerr << endl;
}

vector<int> label(int n, int k, vector<int> u, vector<int> v) {
	vector<int> labels(n), in(n);
  // vector<int> adj[n + 1];

  // for(int i = 0; i < n - 1; i++) {
  //   in[u[i]]++, in[v[i]]++;
  //   adj[u[i]].push_back(v[i]);
  //   adj[v[i]].push_back(u[i]);
  // }
 
  // int start = -1;
  // vector<int> order;
  // for(int i = 0; i < n; i++) {
  //   if(in[i] == 1) {
  //     start = i;
  //     break;
  //   }
  // }
  
  // // assert(start != -1);
  // // dfs(start, -1);

  // auto bfs = [&](int node)-> void {
  //   queue<pair<int, int>> q;
  //   q.push({node, -1});
  //   while(!q.empty()) {
  //     auto u = q.front();
  //     q.pop();

  //     order.push_back(u.first);

  //     for(auto i: adj[u.first]) {
  //       if(i == u.second) continue;
  //       q.push({i, u.first});
  //     }
  //   }
  // };

  // bfs(start);

	for (int i = 0; i < n; i++) {
		labels[i] = i;
	}
 
	return labels;
}
 
int find_next_station(int s, int t, std::vector<int> c) {
  // dbg(s)
  // dbg(t)

  // for(auto i: c) {
    // dbg(i)
  // }

  set<int> parentsFirst, parentsSecond;
  int new_s = s;
  while(new_s) {
    parentsFirst.insert(new_s);
    new_s /= 2;
  }
  parentsFirst.insert(0);


  int new_t = t, lca = -1;
  while(true) {
    parentsSecond.insert(new_t);
    if(parentsFirst.find(new_t) != parentsFirst.end()) {
      parentsSecond.erase(new_t);
      lca = new_t;
      break;
    }
    if(!new_t) {
      break;
    }
    if(new_t % 2 == 0) new_t--;
    new_t /= 2;
  }

  bool f1 = false, f2 = false;;
  int answ = -1;
  for(auto i: c) {
    if(parentsFirst.find(i) != parentsFirst.end()) {
      f1 = true;
    }

    if(parentsSecond.find(i) != parentsSecond.end()) {
      f2 = true;
    }
  }

  if(f1 && f2) {
    // this is lca
    int mx = -1;
    for(auto i: c) {
      if(parentsSecond.find(i) != parentsSecond.end()) {
        mx = max(mx, i);
      }
    }

    return mx;
  } else if(f1) {
    int mn = 1005;
    for(auto i: c) {
      if(parentsFirst.find(i) != parentsFirst.end()) {
        mn = min(mn, i);
      }
    }
    return mn;
  } else {
    int mx = -1;
    for(auto i: c) {
      if(parentsSecond.find(i) != parentsSecond.end()) {
        mx = max(mx, i);
      }
    }

    return mx;
  }

  return c[0];
}

컴파일 시 표준 에러 (stderr) 메시지

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:86:18: warning: variable 'lca' set but not used [-Wunused-but-set-variable]
   86 |   int new_t = t, lca = -1;
      |                  ^~~
stations.cpp:102:7: warning: unused variable 'answ' [-Wunused-variable]
  102 |   int answ = -1;
      |       ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...