답안 #974636

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
974636 2024-05-03T14:50:01 Z Abito 이상한 기계 (APIO19_strange_device) C++17
0 / 100
418 ms 69612 KB
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define ppb pop_back
#define ep insert
#define endl '\n'
#define elif else if
#define pow pwr
#define sqrt sqrtt
#define int long long
#define ll long long
typedef unsigned long long ull;
using namespace std;
const int N=1e6+5;
int n,a,b,l[N],r[N];
int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    cin>>n>>a>>b;
    if (!(a&1)) a/=2;
    for (int i=1;i<=n;i++) cin>>l[i]>>r[i];
    vector<pair<int,int>> v;
    for (int i=1;i<=n;i++){
        if (r[i]-l[i]+1>=a) v.pb({0,a-1});
        else{
            int L=l[i]%a;
            if ((L+r[i]-l[i])%a>L) v.pb({L,(L+r[i]-l[i])%a});
            else{
                v.pb({L,a-1});
                v.pb({0,(L+r[i]-l[i])%a});
            }
        }
    }
    sort(v.begin(),v.end());
    //for (auto u:v) cout<<u.F<<' '<<u.S<<endl;
    set<pair<int,int>> s;
    pair<int,int> cur=v[0];
    for (int i=0;i<v.size();i++){
        int l=max(cur.F,v[i].F),r=min(cur.S,v[i].S);
        if (l>r){
            s.ep(cur);
            cur=v[i];
        }
        else{
            cur.F=min(cur.F,v[i].F);
            cur.S=max(cur.S,v[i].S);
        }
    }
    s.ep(cur);
    int ans=0;
    for (auto u:s) ans+=u.S-u.F+1;
    cout<<ans<<endl;
    return 0;
}

Compilation message

strange_device.cpp: In function 'int32_t main()':
strange_device.cpp:38:19: 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]
   38 |     for (int i=0;i<v.size();i++){
      |                  ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Incorrect 4 ms 3164 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Incorrect 1 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Incorrect 1 ms 2520 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2392 KB Output is correct
2 Incorrect 418 ms 69612 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2392 KB Output is correct
2 Incorrect 418 ms 69612 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2392 KB Output is correct
2 Incorrect 418 ms 69612 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Incorrect 35 ms 12492 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Incorrect 4 ms 3164 KB Output isn't correct
3 Halted 0 ms 0 KB -