Submission #1147478

#TimeUsernameProblemLanguageResultExecution timeMemory
1147478zakimoiCircle Passing (EGOI24_circlepassing)C++20
0 / 100
133 ms8616 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 = min(end - begin, 2*n - end + begin);
        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)

Main.cpp: In function 'void iO()':
Main.cpp:13:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |     freopen("output.txt","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:14:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |     freopen("input.txt","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#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...