Submission #1032719

# Submission time Handle Problem Language Result Execution time Memory
1032719 2024-07-24T06:47:48 Z KasymK Strange Device (APIO19_strange_device) C++17
20 / 100
276 ms 41528 KB
#include "bits/stdc++.h"
using namespace std;
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define ll long long
#define pb push_back
#define pii pair<int, int>
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
const int MOD = 1e9+7;
const int N = 1e5+5;
const ll INF = 1e18+1;

int main(){
	// freopen("file.txt", "r", stdin);
	int n;
	scanf("%d",&n);
	ll a, b;
	scanf("%lld%lld",&a,&b);
	ll ad = a/__gcd(a, b+1);
	if(ad <= INF/b)
		ad *= b;
	else
		ad = INF;
	vector<pii>v;
	for(int i = 1; i <= n; ++i){
		ll l, r;
		scanf("%lld%lld", &l, &r);
		if(r-l+1 >= ad){
			printf("%lld\n", ad);
			return 0;	
		}
		l %= ad, r %= ad;
		if(l <= r)
			v.pb({l, r});
		else
			v.pb({l, ad-1}), v.pb({0, r});
	}
	sort(all(v));
	pii as = {-1, -1};
	ll ans = 0;
	for(auto it = v.begin(); it != v.end(); ++it){
		if(as.ss < it->ff){
			if(as.ff != -1)
				ans += as.ss-as.ff+1;
			as = *it;
		}
		else
			umax(as.ss, it->ss);
	}
	printf("%lld\n", ans+as.ss-as.ff+1);
	return 0;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:18:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |  scanf("%d",&n);
      |  ~~~~~^~~~~~~~~
strange_device.cpp:20:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |  scanf("%lld%lld",&a,&b);
      |  ~~~~~^~~~~~~~~~~~~~~~~~
strange_device.cpp:29:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |   scanf("%lld%lld", &l, &r);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 3 ms 928 KB Output is correct
3 Correct 4 ms 856 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 356 KB Output is correct
8 Correct 0 ms 352 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 352 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 352 KB Output is correct
14 Correct 1 ms 352 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 864 KB Output is correct
17 Correct 30 ms 4792 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 352 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 356 KB Output is correct
2 Correct 1 ms 484 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 480 KB Output is correct
5 Correct 204 ms 31292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 352 KB Output is correct
2 Correct 276 ms 41528 KB Output is correct
3 Incorrect 273 ms 41212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 352 KB Output is correct
2 Correct 276 ms 41528 KB Output is correct
3 Incorrect 273 ms 41212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 352 KB Output is correct
2 Correct 276 ms 41528 KB Output is correct
3 Incorrect 273 ms 41212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 29 ms 4852 KB Output is correct
3 Incorrect 29 ms 4804 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 3 ms 928 KB Output is correct
3 Correct 4 ms 856 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 356 KB Output is correct
8 Correct 0 ms 352 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 352 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 352 KB Output is correct
14 Correct 1 ms 352 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 864 KB Output is correct
17 Correct 30 ms 4792 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 352 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 356 KB Output is correct
25 Correct 1 ms 484 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 1 ms 480 KB Output is correct
28 Correct 204 ms 31292 KB Output is correct
29 Correct 1 ms 352 KB Output is correct
30 Correct 276 ms 41528 KB Output is correct
31 Incorrect 273 ms 41212 KB Output isn't correct
32 Halted 0 ms 0 KB -