Submission #1058176

#TimeUsernameProblemLanguageResultExecution timeMemory
1058176Mr_HusanboyCircle Passing (EGOI24_circlepassing)C++17
100 / 100
40 ms6004 KiB
//#pragma GCC optimize("Ofast,O3") //#pragma GCC target("avx,avx2") #include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "debugger.cpp" #else #define debug(...) #endif template<class T> int len(T &a){ return a.size(); } using ll = long long; using pii = pair<int,int>; #define all(a) (a).begin(), (a).end() #define ff first #define ss second string fileio = ""; mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); const int MOD = 1e9 + 7; const int inf = 1e9; const ll infl = 1e18; const int maxn = 1e5 + 1; void yesno(bool ok){ cout << (ok ? "Yes\n" : "No\n"); } void solve(){ int n; cin >> n; int m; cin >> m; int q; cin >> q; vector<int> fr(m); for(int i = 0; i < m; i ++) cin >> fr[i]; for(int i = 0; i < m; i ++) fr.push_back(fr[i] + n); auto dis = [&](int a, int b){ if(a > b) swap(a, b); return min(b - a, a + 2 * n - b); }; while(q --){ int a, b; cin >> a >> b; int ans = dis(a, b); auto it = upper_bound(all(fr), a) - fr.begin(); int i = fr[it % len(fr)]; it --; if(it < 0) it = len(fr) - 1; int j = fr[it]; ans = min({ans, dis(a, i) + dis((i + n) % (n + n), b) + 1, dis(a, j) + dis((j + n) % (2 * n), b) + 1}); cout << ans << '\n'; } } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); auto start = chrono::high_resolution_clock::now(); #ifndef LOCAL if(fileio.size()){ freopen((fileio + ".in").c_str(), "r", stdin); freopen((fileio + ".out").c_str(), "w", stdout); } #endif int testcases = 1; #ifdef Tests cin >> testcases; #endif while(testcases --){ solve(); if(testcases) cout << '\n'; #ifdef LOCAL else cout << '\n'; cout << "_________________________" << endl; #endif } #ifdef LOCAL auto duration = chrono::duration_cast<chrono::microseconds>(chrono::high_resolution_clock::now() - start); cout << "time: " << (double)duration.count()/1000.0 << " milliseconds" << endl; #endif return 0; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:67:10: warning: variable 'start' set but not used [-Wunused-but-set-variable]
   67 |     auto start = chrono::high_resolution_clock::now();
      |          ^~~~~
Main.cpp:70:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |         freopen((fileio + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:71:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |         freopen((fileio + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...