답안 #249946

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
249946 2020-07-16T14:55:31 Z jeqcho 이상한 기계 (APIO19_strange_device) C++17
0 / 100
527 ms 18516 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpi;

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

#define pb push_back
#define rsz resize
#define sz(x) int(x.size())
#define all(x) begin(x), end(x)
#define f first
#define s second

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    ll A,B;
    cin>>n>>A>>B;
    vector<pair<ll,ll>> segments;
    ll l,r;
    bool wrap;
    while(n--)
    {
        cin>>l>>r;
        if(r>l)wrap=1;
        else wrap=0;
        l *= 2;
        l %= A;
        r *= 2;
        r %= A;
        if(wrap&&r<=l)
        {
            segments.pb({0,l});
            segments.pb({r,A-1});
        }
        else segments.pb({l,r});
    }
    sort(all(segments));
    ll ldex,rdex;
    ll ans=0;
    segments.pb({4e18,0});
    bool init=0;
    ll len;
    trav(seg,segments)
    {
        if(!init)
        {
            ldex=seg.f;
            rdex=seg.s;
            init=1;
            continue;
        }
        if(seg.f>rdex)
        {
            len = rdex-ldex+1;
            if(len&1)
            {
                if(rdex&1)
                {
                    ans += len/2;
                }
                else ans += len/2 + 1;
            }
            else ans += len/2;
            ldex=seg.f;
            rdex=seg.s;
        }
        else
        {
            rdex = max(rdex,seg.s);
        }
    }
    cout<<ans<<'\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Incorrect 6 ms 1152 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 0 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Incorrect 1 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Incorrect 527 ms 18516 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Incorrect 527 ms 18516 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Incorrect 527 ms 18516 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Incorrect 57 ms 3820 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Incorrect 6 ms 1152 KB Output isn't correct
3 Halted 0 ms 0 KB -