이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include"bits/stdc++.h"
using namespace std;
#define LL long long
#define MP make_pair
LL gcd(LL a, LL b){
if(a%b == 0) return b;
return gcd(b, a%b);
}
int N;
LL A, B, S;
vector<pair<LL,LL>> all; //closed range
int main(){
cin >> N >> A >> B;
S = A*B/gcd(A, B+1);
//cout << S << endl;
for(int i=0; i<N; i++){
LL l, r;
cin >> l >> r;
if(l/S == r/S){
all.push_back(MP(l%S, r%S));
//cout << l%S << " " << r%S << endl;
}
else if(l/S+1 == r/S){
all.push_back(MP(l%S, S-1));
all.push_back(MP(0, r%S));
//cout << l%S << " " << S-1 << endl;
//cout << 0 << " " << r%S << endl;
}
else{
all.push_back(MP(0, S-1));
//cout << 0 << " " << S-1 << endl;
}
}
sort(all.begin(), all.end());
for(int i=0; i<all.size()-1; i++){
if(all[i+1].first <= all[i].second){
all[i+1].first = all[i].first;
all[i+1].second = max(all[i].second, all[i+1].second);
all[i] = MP(-1,-2);
}
}
LL ans = 0;
for(int i=0; i<all.size(); i++){
//cout << all[i].first << " " << all[i].second << " " << all[i].second - all[i].first + 1 << endl;
ans += all[i].second - all[i].first + 1;
}
cout << ans << endl;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
strange_device.cpp: In function 'int main()':
strange_device.cpp:38:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<all.size()-1; i++){
~^~~~~~~~~~~~~
strange_device.cpp:46:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<all.size(); i++){
~^~~~~~~~~~~
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |