답안 #347842

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
347842 2021-01-13T15:19:51 Z denkendoemeer 이상한 기계 (APIO19_strange_device) C++14
25 / 100
574 ms 41396 KB
#include<bits/stdc++.h>
#define ll long long
using namespace std;
vector<pair<ll,ll>>v;
ll gcd(ll a,ll b)
{
    ll r=0;
    while(b){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}
int main()
{
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    ll n,a,b,g,i,x,y,ans=0;
    scanf("%lld%lld%lld",&n,&a,&b);
    g=gcd(a,b+1);
    if ((double)a/g*b>1e17){
        for(i=1;i<=n;i++)
            scanf("%lld%lld",&x,&y),ans=ans+y-x+1;
        printf("%lld\n",ans);
        return 0;
    }
    ll aux=a/g*b;
    for(i=1;i<=n;i++){
        scanf("%lld%lld",&x,&y);
        if (y-x+1>=aux){
            printf("%lld\n",aux);
            return 0;
        }
        x=x%aux;
        y=y%aux;
        if (x>y){
            v.push_back(make_pair(x,aux-1));
            v.push_back(make_pair(0,y));
        }
        else
            v.push_back(make_pair(x,y));
    }
    sort(v.begin(),v.end());
    ll last=-1;
    for(auto it:v){
        ans=ans+max(0LL,it.second-max(last,it.first-1));
        last=max(last,it.second);
    }
    printf("%lld\n",min(ans,aux));
return 0;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:20:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   20 |     scanf("%lld%lld%lld",&n,&a,&b);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:24:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   24 |             scanf("%lld%lld",&x,&y),ans=ans+y-x+1;
      |             ~~~~~^~~~~~~~~~~~~~~~~~
strange_device.cpp:30:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   30 |         scanf("%lld%lld",&x,&y);
      |         ~~~~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 6 ms 1132 KB Output is correct
3 Correct 6 ms 1132 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 5 ms 1132 KB Output is correct
17 Correct 57 ms 5724 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 389 ms 41396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 521 ms 30932 KB Output is correct
3 Correct 510 ms 36828 KB Output is correct
4 Correct 506 ms 36552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 521 ms 30932 KB Output is correct
3 Correct 510 ms 36828 KB Output is correct
4 Correct 506 ms 36552 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 506 ms 36660 KB Output is correct
7 Correct 512 ms 36584 KB Output is correct
8 Correct 526 ms 36680 KB Output is correct
9 Incorrect 397 ms 20716 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 521 ms 30932 KB Output is correct
3 Correct 510 ms 36828 KB Output is correct
4 Correct 506 ms 36552 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 50 ms 5724 KB Output is correct
7 Correct 53 ms 5724 KB Output is correct
8 Correct 51 ms 5724 KB Output is correct
9 Incorrect 38 ms 4076 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 54 ms 5724 KB Output is correct
3 Correct 54 ms 5716 KB Output is correct
4 Correct 574 ms 36688 KB Output is correct
5 Correct 53 ms 5852 KB Output is correct
6 Correct 56 ms 5724 KB Output is correct
7 Correct 56 ms 5724 KB Output is correct
8 Correct 55 ms 5724 KB Output is correct
9 Correct 53 ms 5724 KB Output is correct
10 Correct 57 ms 5744 KB Output is correct
11 Correct 54 ms 5724 KB Output is correct
12 Incorrect 38 ms 4076 KB Output isn't correct
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 6 ms 1132 KB Output is correct
3 Correct 6 ms 1132 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 5 ms 1132 KB Output is correct
17 Correct 57 ms 5724 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 389 ms 41396 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 521 ms 30932 KB Output is correct
31 Correct 510 ms 36828 KB Output is correct
32 Correct 506 ms 36552 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 506 ms 36660 KB Output is correct
35 Correct 512 ms 36584 KB Output is correct
36 Correct 526 ms 36680 KB Output is correct
37 Incorrect 397 ms 20716 KB Output isn't correct