답안 #252066

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
252066 2020-07-24T05:44:07 Z jeqcho 이상한 기계 (APIO19_strange_device) C++17
35 / 100
724 ms 17008 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

// solved subtask 4 and 5

ll A,B;

ll gcd(ll a, ll b)
{
    // O((log n)^2)
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    cin>>n>>A>>B;
    ll l,r;
    ll q = A / gcd(A,B+1);
    ll maxlen = q*B;
    vector<pair<ll,ll>> segments;
    F0R(i,n)
    {
        cin>>l>>r;
        if(r-l+1 >= maxlen)
        {
            FOR(j,i+1,n)cin>>l>>r;
            cout<<maxlen<<endl;
            return 0;
        }
        l %= maxlen;
        r %= maxlen;
        if(r<l)
        {
            segments.pb({0,r});
            segments.pb({l,maxlen-1});
        }
        else segments.pb({l,r});
    }
    sort(all(segments));
    bool init=0;
    ll ldex,rdex;
    ll ans=0;
    pair<ll,ll> seg;
    F0R(i,sz(segments)+1)
    {
        if(i==sz(segments))
        {
            ans += rdex-ldex+1;
            break;
        }
        seg = segments[i];
        if(!init)
        {
            ldex=seg.f;
            rdex=seg.s;
            init=1;
        }
        else if(seg.f==ldex)
        {
            rdex = seg.s;
        }
        else
        {
            // seg.f > ldex
            if(seg.f <= rdex)
            {
                rdex = max(rdex,seg.s);
            }
            else
            {
                ans += rdex-ldex+1;
                ldex=seg.f;
                rdex=seg.s;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:70:24: warning: 'rdex' may be used uninitialized in this function [-Wmaybe-uninitialized]
             ans += rdex-ldex+1;
                    ~~~~^~~~~
strange_device.cpp:70:24: warning: 'ldex' may be used uninitialized in this function [-Wmaybe-uninitialized]
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 7 ms 768 KB Output is correct
3 Correct 5 ms 768 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 9 ms 768 KB Output is correct
17 Correct 59 ms 2544 KB Output is correct
18 Incorrect 0 ms 384 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Incorrect 0 ms 384 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 363 ms 16976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 507 ms 16852 KB Output is correct
3 Correct 510 ms 16980 KB Output is correct
4 Correct 507 ms 16852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 507 ms 16852 KB Output is correct
3 Correct 510 ms 16980 KB Output is correct
4 Correct 507 ms 16852 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 507 ms 16988 KB Output is correct
7 Correct 526 ms 16968 KB Output is correct
8 Correct 489 ms 16856 KB Output is correct
9 Correct 555 ms 17008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 507 ms 16852 KB Output is correct
3 Correct 510 ms 16980 KB Output is correct
4 Correct 507 ms 16852 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 55 ms 2552 KB Output is correct
7 Correct 55 ms 2544 KB Output is correct
8 Correct 50 ms 2552 KB Output is correct
9 Correct 56 ms 2544 KB Output is correct
10 Correct 55 ms 2544 KB Output is correct
11 Correct 51 ms 2544 KB Output is correct
12 Correct 64 ms 2544 KB Output is correct
13 Correct 65 ms 2540 KB Output is correct
14 Correct 51 ms 2544 KB Output is correct
15 Correct 61 ms 2544 KB Output is correct
16 Correct 60 ms 2552 KB Output is correct
17 Correct 63 ms 2544 KB Output is correct
18 Correct 521 ms 16852 KB Output is correct
19 Correct 523 ms 16876 KB Output is correct
20 Correct 554 ms 16852 KB Output is correct
21 Correct 55 ms 2552 KB Output is correct
22 Correct 45 ms 2552 KB Output is correct
23 Correct 157 ms 8672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 54 ms 2544 KB Output is correct
3 Correct 57 ms 2544 KB Output is correct
4 Correct 557 ms 16852 KB Output is correct
5 Correct 53 ms 2672 KB Output is correct
6 Correct 51 ms 2544 KB Output is correct
7 Correct 52 ms 2544 KB Output is correct
8 Correct 62 ms 2540 KB Output is correct
9 Correct 53 ms 2544 KB Output is correct
10 Correct 52 ms 2544 KB Output is correct
11 Correct 52 ms 2552 KB Output is correct
12 Correct 46 ms 2544 KB Output is correct
13 Correct 54 ms 2544 KB Output is correct
14 Correct 558 ms 16980 KB Output is correct
15 Correct 53 ms 2544 KB Output is correct
16 Correct 724 ms 16832 KB Output is correct
17 Correct 484 ms 16852 KB Output is correct
18 Incorrect 1 ms 384 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 7 ms 768 KB Output is correct
3 Correct 5 ms 768 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 9 ms 768 KB Output is correct
17 Correct 59 ms 2544 KB Output is correct
18 Incorrect 0 ms 384 KB Output isn't correct