답안 #221628

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
221628 2020-04-10T14:24:57 Z MKopchev 이상한 기계 (APIO19_strange_device) C++14
100 / 100
1050 ms 102072 KB
#include<bits/stdc++.h>
using namespace std;
const int nmax=1e6+42;
const long long inf=1e18;

int n;
long long A,B;

pair<long long,long long> inp[nmax];

vector< pair<long long,long long> > segments;

vector< pair<long long,int> > active;

bool cmp(pair<long long,int> s,pair<long long,int> t)
{
    if(s.first!=t.first)return s.first<t.first;
    return s.second>t.second;
}
int main()
{
    scanf("%i%lld%lld",&n,&A,&B);

    A=A/__gcd(A,B+1);

    for(int i=1;i<=n;i++)
    {
        scanf("%lld%lld",&inp[i].first,&inp[i].second);

        if(A>inf/B)segments.push_back(inp[i]);
        else
        {
            if(inp[i].second-inp[i].first+1>=A*B)
            {
                printf("%lld\n",A*B);
                return 0;
            }

            inp[i].first=inp[i].first%(A*B);
            inp[i].second=inp[i].second%(A*B);

            if(inp[i].first<=inp[i].second)segments.push_back(inp[i]);
            else
            {
                segments.push_back({inp[i].first,A*B-1});
                segments.push_back({0,inp[i].second});
            }
        }
    }

    for(auto k:segments)
    {
        active.push_back({k.first,1});
        active.push_back({k.second+1,-1});

        //cout<<k.first<<" "<<k.second<<endl;
    }

    sort(active.begin(),active.end(),cmp);

    int sum=1;

    long long output=0;

    for(int i=1;i<active.size();i++)
    {
        if(sum)output+=active[i].first-active[i-1].first;

        sum=sum+active[i].second;

        //cout<<i<<" -> "<<sum<<" "<<output<<" "<<active[i].first<<" "<<active[i].second<<endl;
    }

    printf("%lld\n",output);
    return 0;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:65:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=1;i<active.size();i++)
                 ~^~~~~~~~~~~~~~
strange_device.cpp:22:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%i%lld%lld",&n,&A,&B);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:28:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld%lld",&inp[i].first,&inp[i].second);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 13 ms 1660 KB Output is correct
3 Correct 12 ms 1660 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 256 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 256 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 256 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 12 ms 1660 KB Output is correct
17 Correct 105 ms 11380 KB Output is correct
18 Correct 4 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 6 ms 640 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 586 ms 90108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 820 ms 78364 KB Output is correct
3 Correct 891 ms 101820 KB Output is correct
4 Correct 863 ms 101952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 820 ms 78364 KB Output is correct
3 Correct 891 ms 101820 KB Output is correct
4 Correct 863 ms 101952 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 833 ms 101884 KB Output is correct
7 Correct 824 ms 101948 KB Output is correct
8 Correct 836 ms 101788 KB Output is correct
9 Correct 1002 ms 101752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 820 ms 78364 KB Output is correct
3 Correct 891 ms 101820 KB Output is correct
4 Correct 863 ms 101952 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 81 ms 11472 KB Output is correct
7 Correct 87 ms 11364 KB Output is correct
8 Correct 81 ms 11364 KB Output is correct
9 Correct 84 ms 11368 KB Output is correct
10 Correct 76 ms 11364 KB Output is correct
11 Correct 84 ms 11364 KB Output is correct
12 Correct 77 ms 11628 KB Output is correct
13 Correct 97 ms 11496 KB Output is correct
14 Correct 76 ms 11368 KB Output is correct
15 Correct 100 ms 11364 KB Output is correct
16 Correct 94 ms 11364 KB Output is correct
17 Correct 79 ms 11368 KB Output is correct
18 Correct 843 ms 101788 KB Output is correct
19 Correct 785 ms 101820 KB Output is correct
20 Correct 1025 ms 101664 KB Output is correct
21 Correct 99 ms 11368 KB Output is correct
22 Correct 76 ms 11368 KB Output is correct
23 Correct 246 ms 40144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 96 ms 11484 KB Output is correct
3 Correct 94 ms 11496 KB Output is correct
4 Correct 1050 ms 101740 KB Output is correct
5 Correct 93 ms 11496 KB Output is correct
6 Correct 95 ms 11364 KB Output is correct
7 Correct 96 ms 11364 KB Output is correct
8 Correct 98 ms 11496 KB Output is correct
9 Correct 90 ms 11368 KB Output is correct
10 Correct 99 ms 11364 KB Output is correct
11 Correct 92 ms 11364 KB Output is correct
12 Correct 81 ms 11492 KB Output is correct
13 Correct 99 ms 11364 KB Output is correct
14 Correct 1012 ms 101764 KB Output is correct
15 Correct 101 ms 11364 KB Output is correct
16 Correct 791 ms 101788 KB Output is correct
17 Correct 836 ms 101792 KB Output is correct
18 Correct 5 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 13 ms 1660 KB Output is correct
3 Correct 12 ms 1660 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 256 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 256 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 256 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 12 ms 1660 KB Output is correct
17 Correct 105 ms 11380 KB Output is correct
18 Correct 4 ms 256 KB Output is correct
19 Correct 5 ms 256 KB Output is correct
20 Correct 4 ms 256 KB Output is correct
21 Correct 5 ms 256 KB Output is correct
22 Correct 5 ms 256 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 256 KB Output is correct
25 Correct 6 ms 640 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 586 ms 90108 KB Output is correct
29 Correct 5 ms 256 KB Output is correct
30 Correct 820 ms 78364 KB Output is correct
31 Correct 891 ms 101820 KB Output is correct
32 Correct 863 ms 101952 KB Output is correct
33 Correct 5 ms 256 KB Output is correct
34 Correct 833 ms 101884 KB Output is correct
35 Correct 824 ms 101948 KB Output is correct
36 Correct 836 ms 101788 KB Output is correct
37 Correct 1002 ms 101752 KB Output is correct
38 Correct 5 ms 384 KB Output is correct
39 Correct 81 ms 11472 KB Output is correct
40 Correct 87 ms 11364 KB Output is correct
41 Correct 81 ms 11364 KB Output is correct
42 Correct 84 ms 11368 KB Output is correct
43 Correct 76 ms 11364 KB Output is correct
44 Correct 84 ms 11364 KB Output is correct
45 Correct 77 ms 11628 KB Output is correct
46 Correct 97 ms 11496 KB Output is correct
47 Correct 76 ms 11368 KB Output is correct
48 Correct 100 ms 11364 KB Output is correct
49 Correct 94 ms 11364 KB Output is correct
50 Correct 79 ms 11368 KB Output is correct
51 Correct 843 ms 101788 KB Output is correct
52 Correct 785 ms 101820 KB Output is correct
53 Correct 1025 ms 101664 KB Output is correct
54 Correct 99 ms 11368 KB Output is correct
55 Correct 76 ms 11368 KB Output is correct
56 Correct 246 ms 40144 KB Output is correct
57 Correct 5 ms 256 KB Output is correct
58 Correct 96 ms 11484 KB Output is correct
59 Correct 94 ms 11496 KB Output is correct
60 Correct 1050 ms 101740 KB Output is correct
61 Correct 93 ms 11496 KB Output is correct
62 Correct 95 ms 11364 KB Output is correct
63 Correct 96 ms 11364 KB Output is correct
64 Correct 98 ms 11496 KB Output is correct
65 Correct 90 ms 11368 KB Output is correct
66 Correct 99 ms 11364 KB Output is correct
67 Correct 92 ms 11364 KB Output is correct
68 Correct 81 ms 11492 KB Output is correct
69 Correct 99 ms 11364 KB Output is correct
70 Correct 1012 ms 101764 KB Output is correct
71 Correct 101 ms 11364 KB Output is correct
72 Correct 791 ms 101788 KB Output is correct
73 Correct 836 ms 101792 KB Output is correct
74 Correct 5 ms 256 KB Output is correct
75 Correct 5 ms 384 KB Output is correct
76 Correct 5 ms 256 KB Output is correct
77 Correct 5 ms 256 KB Output is correct
78 Correct 5 ms 256 KB Output is correct
79 Correct 11 ms 1660 KB Output is correct
80 Correct 1043 ms 101916 KB Output is correct
81 Correct 1049 ms 101916 KB Output is correct
82 Correct 988 ms 102072 KB Output is correct
83 Correct 1000 ms 101820 KB Output is correct
84 Correct 1050 ms 101788 KB Output is correct
85 Correct 1035 ms 101820 KB Output is correct
86 Correct 256 ms 40020 KB Output is correct
87 Correct 5 ms 384 KB Output is correct