답안 #1032702

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1032702 2024-07-24T06:32:04 Z KasymK 이상한 기계 (APIO19_strange_device) C++17
20 / 100
296 ms 26976 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 v[N];

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 i : v){
		if(as.ss < i.ff){
			if(as.ff != -1)
				ans += as.ss-as.ff+1;
			as = i;
		}
		else
			umax(as.ss, i.ss);
	}
	printf("%lld\n", ans+as.ss-as.ff+1);
	return 0;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:19:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |  scanf("%d",&n);
      |  ~~~~~^~~~~~~~~
strange_device.cpp:21:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |  scanf("%lld%lld",&a,&b);
      |  ~~~~~^~~~~~~~~~~~~~~~~~
strange_device.cpp:30:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |   scanf("%lld%lld", &l, &r);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 3 ms 964 KB Output is correct
3 Correct 3 ms 864 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 444 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 30 ms 3260 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 198 ms 20972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 296 ms 26976 KB Output is correct
3 Incorrect 277 ms 26928 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 296 ms 26976 KB Output is correct
3 Incorrect 277 ms 26928 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 296 ms 26976 KB Output is correct
3 Incorrect 277 ms 26928 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 31 ms 3148 KB Output is correct
3 Incorrect 30 ms 3284 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 3 ms 964 KB Output is correct
3 Correct 3 ms 864 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 444 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 30 ms 3260 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 440 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 600 KB Output is correct
28 Correct 198 ms 20972 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 296 ms 26976 KB Output is correct
31 Incorrect 277 ms 26928 KB Output isn't correct
32 Halted 0 ms 0 KB -