Submission #304825

# Submission time Handle Problem Language Result Execution time Memory
304825 2020-09-22T00:39:09 Z Hemimor Strange Device (APIO19_strange_device) C++14
100 / 100
799 ms 69148 KB
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <cassert>
#include <bitset>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

ll gcd(ll a,ll b){
	if(!b) return a;
	return gcd(b,a%b);
}

typedef __int128 b128;

int n;
ll A,B,res=0;

int main(){
	scanf("%d%lld%lld",&n,&A,&B);
	b128 m=A/gcd(A,B+1)*b128(B);
	vector<pair<ll,int>> a;
	for(int i=0;i<n;i++){
		ll l,r;
		scanf("%lld%lld",&l,&r);
		if(r-l+1>=m){
			cout<<(ll)m<<endl;
			return 0;
		}
		l%=m,r%=m;
		r++;
		a.push_back({l,1});
		a.push_back({r,-1});
		if(l>r){
			a.push_back(make_pair(0LL,1));
			a.push_back(make_pair((ll)m,-1));
		}
	}
	sort(a.begin(),a.end());
	ll N=a.size(),x=0,s=0;
	for(int i=0;i<N;i++){
		ll y=a[i].first,t=a[i].second;
		if(s) res+=y-x;
		x=y,s+=t;
	}
	printf("%lld\n",res);
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:51:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   51 |  scanf("%d%lld%lld",&n,&A,&B);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:56:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   56 |   scanf("%lld%lld",&l,&r);
      |   ~~~~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 7 ms 1404 KB Output is correct
3 Correct 7 ms 1404 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 7 ms 1276 KB Output is correct
17 Correct 71 ms 7272 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 416 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 2 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 477 ms 57004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 639 ms 69016 KB Output is correct
3 Correct 662 ms 68980 KB Output is correct
4 Correct 644 ms 69144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 639 ms 69016 KB Output is correct
3 Correct 662 ms 68980 KB Output is correct
4 Correct 644 ms 69144 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 647 ms 69108 KB Output is correct
7 Correct 660 ms 69088 KB Output is correct
8 Correct 634 ms 69016 KB Output is correct
9 Correct 761 ms 69064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 639 ms 69016 KB Output is correct
3 Correct 662 ms 68980 KB Output is correct
4 Correct 644 ms 69144 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 62 ms 7384 KB Output is correct
7 Correct 66 ms 7436 KB Output is correct
8 Correct 60 ms 7280 KB Output is correct
9 Correct 70 ms 7392 KB Output is correct
10 Correct 61 ms 7272 KB Output is correct
11 Correct 66 ms 7272 KB Output is correct
12 Correct 60 ms 7272 KB Output is correct
13 Correct 69 ms 7268 KB Output is correct
14 Correct 62 ms 7272 KB Output is correct
15 Correct 73 ms 7268 KB Output is correct
16 Correct 73 ms 7300 KB Output is correct
17 Correct 62 ms 7268 KB Output is correct
18 Correct 682 ms 69072 KB Output is correct
19 Correct 617 ms 69016 KB Output is correct
20 Correct 778 ms 69016 KB Output is correct
21 Correct 71 ms 7280 KB Output is correct
22 Correct 56 ms 7272 KB Output is correct
23 Correct 222 ms 26704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 69 ms 7352 KB Output is correct
3 Correct 69 ms 7272 KB Output is correct
4 Correct 799 ms 69016 KB Output is correct
5 Correct 67 ms 7268 KB Output is correct
6 Correct 66 ms 7280 KB Output is correct
7 Correct 69 ms 7392 KB Output is correct
8 Correct 71 ms 7272 KB Output is correct
9 Correct 66 ms 7392 KB Output is correct
10 Correct 71 ms 7400 KB Output is correct
11 Correct 68 ms 7396 KB Output is correct
12 Correct 62 ms 7392 KB Output is correct
13 Correct 71 ms 7272 KB Output is correct
14 Correct 759 ms 68932 KB Output is correct
15 Correct 73 ms 7272 KB Output is correct
16 Correct 633 ms 69044 KB Output is correct
17 Correct 648 ms 69148 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 7 ms 1404 KB Output is correct
3 Correct 7 ms 1404 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 7 ms 1276 KB Output is correct
17 Correct 71 ms 7272 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
19 Correct 0 ms 256 KB Output is correct
20 Correct 1 ms 416 KB Output is correct
21 Correct 1 ms 256 KB Output is correct
22 Correct 1 ms 256 KB Output is correct
23 Correct 0 ms 256 KB Output is correct
24 Correct 0 ms 256 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 477 ms 57004 KB Output is correct
29 Correct 1 ms 256 KB Output is correct
30 Correct 639 ms 69016 KB Output is correct
31 Correct 662 ms 68980 KB Output is correct
32 Correct 644 ms 69144 KB Output is correct
33 Correct 0 ms 256 KB Output is correct
34 Correct 647 ms 69108 KB Output is correct
35 Correct 660 ms 69088 KB Output is correct
36 Correct 634 ms 69016 KB Output is correct
37 Correct 761 ms 69064 KB Output is correct
38 Correct 1 ms 256 KB Output is correct
39 Correct 62 ms 7384 KB Output is correct
40 Correct 66 ms 7436 KB Output is correct
41 Correct 60 ms 7280 KB Output is correct
42 Correct 70 ms 7392 KB Output is correct
43 Correct 61 ms 7272 KB Output is correct
44 Correct 66 ms 7272 KB Output is correct
45 Correct 60 ms 7272 KB Output is correct
46 Correct 69 ms 7268 KB Output is correct
47 Correct 62 ms 7272 KB Output is correct
48 Correct 73 ms 7268 KB Output is correct
49 Correct 73 ms 7300 KB Output is correct
50 Correct 62 ms 7268 KB Output is correct
51 Correct 682 ms 69072 KB Output is correct
52 Correct 617 ms 69016 KB Output is correct
53 Correct 778 ms 69016 KB Output is correct
54 Correct 71 ms 7280 KB Output is correct
55 Correct 56 ms 7272 KB Output is correct
56 Correct 222 ms 26704 KB Output is correct
57 Correct 0 ms 256 KB Output is correct
58 Correct 69 ms 7352 KB Output is correct
59 Correct 69 ms 7272 KB Output is correct
60 Correct 799 ms 69016 KB Output is correct
61 Correct 67 ms 7268 KB Output is correct
62 Correct 66 ms 7280 KB Output is correct
63 Correct 69 ms 7392 KB Output is correct
64 Correct 71 ms 7272 KB Output is correct
65 Correct 66 ms 7392 KB Output is correct
66 Correct 71 ms 7400 KB Output is correct
67 Correct 68 ms 7396 KB Output is correct
68 Correct 62 ms 7392 KB Output is correct
69 Correct 71 ms 7272 KB Output is correct
70 Correct 759 ms 68932 KB Output is correct
71 Correct 73 ms 7272 KB Output is correct
72 Correct 633 ms 69044 KB Output is correct
73 Correct 648 ms 69148 KB Output is correct
74 Correct 1 ms 256 KB Output is correct
75 Correct 1 ms 256 KB Output is correct
76 Correct 1 ms 384 KB Output is correct
77 Correct 1 ms 384 KB Output is correct
78 Correct 0 ms 384 KB Output is correct
79 Correct 6 ms 1276 KB Output is correct
80 Correct 790 ms 68888 KB Output is correct
81 Correct 783 ms 68836 KB Output is correct
82 Correct 736 ms 68920 KB Output is correct
83 Correct 742 ms 68888 KB Output is correct
84 Correct 740 ms 69016 KB Output is correct
85 Correct 745 ms 69028 KB Output is correct
86 Correct 218 ms 26704 KB Output is correct
87 Correct 1 ms 256 KB Output is correct