# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1147479 | zakimoi | Circle Passing (EGOI24_circlepassing) | C++20 | 131 ms | 8620 KiB |
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdint>
#include <set>
#include <unordered_map>
#define int long long int
using namespace std;
int MAX = 1e9 + 7;
void iO() {
freopen("output.txt","w",stdout);
freopen("input.txt","r",stdin);
}
int32_t main () {
// iO();
int n, m, q;
cin >> n >> m >> q;
vector<int> bestie;
for (int i = 0; i < m; i++) {
int temp;
cin >> temp;
bestie.push_back(temp);
bestie.push_back(temp + n);
}
sort(bestie.begin(), bestie.end());
for (int i_ = 0; i_ < q; i_++) {
int begin, end;
cin >> begin >> end;
int notp = abs(end - begin);
notp = min(notp, 2*n - notp);
int lower = bestie[lower_bound(bestie.begin(), bestie.end(), begin) - bestie.begin()];
int bigger = bestie[(lower + 1) % (2*m)];
int closest_lower = abs(lower - begin);
closest_lower = min(closest_lower, 2*n - closest_lower) + 1;
int closest_bigger = abs(bigger - begin);
closest_bigger = min(closest_bigger, 2*n - closest_bigger) + 1;
int lower2end = abs(((lower + n) % (2*n)) - end);
lower2end = min(lower2end, 2*n - lower2end);
int bigger2end = abs(((bigger + n) % (2*n)) - end);
bigger2end = min(bigger2end, 2*n - bigger2end);
int closestp = min(closest_bigger + bigger2end, closest_lower + lower2end);
cout << min(notp, closestp) << endl;
}
}
// 1 1 2 5 7
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |