제출 #1347599

#제출 시각아이디문제언어결과실행 시간메모리
1347599julia_08Circle Passing (EGOI24_circlepassing)C++20
14 / 100
2096 ms33612 KiB
#include <bits/stdc++.h>
using namespace std;

int n;

int dist(int x, int y){
  if(x > y) swap(x, y);
  return min(y - x, 2 * n - (y - x));
}

int main(){
  cin.tie(0)->sync_with_stdio(0);

  int m, q; cin >> n >> m >> q;

  set<int> s;

  while(m--){

    int k; cin >> k;
    
    s.insert(k);
    // s.insert(k + n);
  
  }

  vector<pair<pair<int, int>, int>> queries;

  vector<int> ans(q, 0);

  for(int i=0; i<q; i++){

    int x, y; cin >> x >> y;
    if(x > y) swap(x, y);

    int rot = 2 * n - x;

    if(2 * n - (y - x) < (y - x)) rot = 2 * n - y;

    // cout << "rot = " << rot << " " << dist(x, y) << endl;
    queries.push_back({{rot, dist(x, y)}, i});

  }

  sort(queries.begin(), queries.end());

  // todo mundo move 1 no sentido horario

  for(auto [x, j] : queries){

    auto [i, y] = x;

    set<int> ns;

    for(auto x : s){

      int pos = (x + i) % (2 * n);
      if(pos > n) pos -= n;
      
      ns.insert(pos);
    
    }

    // for(auto c : s) cout << c << " ";
    // cout << endl;

    // todo mundo no set é x + i

    ans[j] = y;

    if(y == n){

      ans[j] = min(ans[j], 2 * min(*ns.begin(), n - *ns.rbegin()) + 1);

      continue;

    }

    if(*ns.begin() <= y) ans[j] = min(ans[j], 2 * (*ns.begin()) + n - y + 1);

    if(*ns.rbegin() >= y){
      ans[j] = min(ans[j], n - y + 1);
    }

  }

  for(int i=0; i<q; i++) cout << ans[i] << "\n";

  return 0;
}
#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...