이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mxN = (int)1e6+10;
int n, m, q;
int k[mxN];
int dis(int a, int b){ return min(abs(a-b), n*2-abs(a-b)); }
int getDis(int a, int K, int b){
return min(dis(a,K)+1+dis(K+n,b), dis(a,K+n)+1+dis(K,b));
}
int32_t main(){
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n >> m >> q;
for(int i = 0; i < m; i++) cin >> k[i];
while(q--){
int a, b; cin >> a >> b;
if(a>b) swap(a,b);
int ans = dis(a,b);
int pos = lower_bound(k,k+m,a)-k;
int tot = min(m, (int)1e4/2); int tot2 = tot;
if(pos==m) pos=0;
ans = min(ans, getDis(a,k[pos],b));
if(pos==0) pos=m-1;
else pos--;
ans = min(ans, getDis(a,k[pos],b));
cout << ans << "\n";
}
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'int32_t main()':
Main.cpp:22:43: warning: unused variable 'tot2' [-Wunused-variable]
22 | int tot = min(m, (int)1e4/2); int tot2 = tot;
| ^~~~
# | 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... |