답안 #729240

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
729240 2023-04-23T17:20:33 Z 1075508020060209tc 이상한 기계 (APIO19_strange_device) C++14
15 / 100
5000 ms 524288 KB
#include<bits/stdc++.h>

using namespace std;
#define int long long
int n;int A;int B;
int ar[1000006];int br[1000006];


map<pair<int,int>,int>vis;

signed main(){
cin>>n>>A>>B;
for(int i=1;i<=n;i++){
    cin>>ar[i]>>br[i];
}

for(int t=1;t<=A*B+10;t++){
     int x=(t+t/B)%A;
     int y=(t%B);
     if(vis[{x,y}]){
        A=t-1;
        break;
     }
    vis[{x,y}]=1;
}




vector<pair<int,int>>seg;
for(int i=1;i<=n;i++){
    if(br[i]-ar[i]+1>=A){
        cout<<A;return 0;
    }
    int l=ar[i]%A;int r=br[i]%A;
    if(r<l){
        seg.push_back({l,A-1});
        seg.push_back({0,r});
    }else{
        seg.push_back({l,r});
    }
}
sort(seg.begin(),seg.end());
int ans=0;
int rpl=seg[0].second;
int lpl=seg[0].first;
for(int i=1;i<seg.size();i++){

    if(seg[i].first<=rpl+1){
        rpl=max(rpl,seg[i].second);
        continue;
    }else{
        ans+=rpl-lpl+1;
        lpl=seg[i].first;rpl=seg[i].second;
    }
}
ans+=rpl-lpl+1;
cout<<ans<<endl;

}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:47:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 | for(int i=1;i<seg.size();i++){
      |             ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 2302 ms 405608 KB Output is correct
3 Correct 1817 ms 311372 KB Output is correct
4 Correct 4 ms 1364 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 4 ms 1108 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 30 ms 7728 KB Output is correct
16 Correct 57 ms 12564 KB Output is correct
17 Correct 798 ms 127804 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Execution timed out 5092 ms 465956 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 257 ms 60516 KB Output is correct
3 Correct 333 ms 61320 KB Output is correct
4 Correct 320 ms 50980 KB Output is correct
5 Correct 1294 ms 94892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1799 ms 109712 KB Output is correct
3 Execution timed out 5092 ms 475624 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1799 ms 109712 KB Output is correct
3 Execution timed out 5092 ms 475624 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1799 ms 109712 KB Output is correct
3 Execution timed out 5092 ms 475624 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Runtime error 1978 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 2302 ms 405608 KB Output is correct
3 Correct 1817 ms 311372 KB Output is correct
4 Correct 4 ms 1364 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 4 ms 1108 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 30 ms 7728 KB Output is correct
16 Correct 57 ms 12564 KB Output is correct
17 Correct 798 ms 127804 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Execution timed out 5092 ms 465956 KB Time limit exceeded
21 Halted 0 ms 0 KB -