답안 #977109

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
977109 2024-05-07T11:48:08 Z Batorgil952 이상한 기계 (APIO19_strange_device) C++14
5 / 100
367 ms 17584 KB
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
 
using namespace std;
 
ll GCD(ll x, ll y){
	while(x*y!=0){
		if(x>y) x%=y;
		else y%=x;
	}
	return x+y;
}
 
int main(){
	ll n, i, A, B, l, r, k, m, ma, ans;
	vector< pair< ll, ll > > v;
	
	scanf("%lld",&n);
	scanf("%lld",&A);
	scanf("%lld",&B);
	
	m=GCD(B+1, A);
	A/=m;
	ma=1000000000000000002;
	if(ma/A<B){
		k=ma;
	}
	else{
		k=A*B;
	}
//	cout<<k<<endl;
	
	ans=0;
	for(i=1; i<=n; i++){
		scanf("%lld",&l);
		scanf("%lld",&r);
		if(r-l+1>=k){
			ans=k;
		}
		if(l%k<=r%k) v.pb(mp(l%k, r%k));
		else{
			v.pb(mp(l%k, k-1));
			v.pb(mp(0, r%k));
		}
	}
	
	
	if(ans==k){
		printf("%lld\n", k);
		return 0;
	}
	sort(v.begin(), v.end());
	
	l=v[0].ff;
	r=v[0].ss;
	for(i=1; i<n; i++){
		if(v[i].ff<=r){
			r=max(r, v[i].ss);
		}
		else{
			ans+=(r-l+1);
			l=v[i].ff;
			r=v[i].ss;
		}
	}
	ans+=(r-l+1);
	
	printf("%lld\n", ans);
	
	return 0;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:22:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |  scanf("%lld",&n);
      |  ~~~~~^~~~~~~~~~~
strange_device.cpp:23:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |  scanf("%lld",&A);
      |  ~~~~~^~~~~~~~~~~
strange_device.cpp:24:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |  scanf("%lld",&B);
      |  ~~~~~^~~~~~~~~~~
strange_device.cpp:39:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |   scanf("%lld",&l);
      |   ~~~~~^~~~~~~~~~~
strange_device.cpp:40:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |   scanf("%lld",&r);
      |   ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 3 ms 724 KB Output is correct
3 Incorrect 4 ms 724 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 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 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 500 KB Output is correct
2 Incorrect 1 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 361 ms 17584 KB Output is correct
3 Incorrect 308 ms 17064 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 361 ms 17584 KB Output is correct
3 Incorrect 308 ms 17064 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 361 ms 17584 KB Output is correct
3 Incorrect 308 ms 17064 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 34 ms 2548 KB Output is correct
3 Correct 33 ms 2512 KB Output is correct
4 Correct 367 ms 17276 KB Output is correct
5 Correct 41 ms 2512 KB Output is correct
6 Correct 33 ms 2508 KB Output is correct
7 Correct 36 ms 2508 KB Output is correct
8 Correct 33 ms 2512 KB Output is correct
9 Correct 33 ms 2512 KB Output is correct
10 Correct 33 ms 2512 KB Output is correct
11 Correct 36 ms 2512 KB Output is correct
12 Incorrect 32 ms 2512 KB Output isn't correct
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 3 ms 724 KB Output is correct
3 Incorrect 4 ms 724 KB Output isn't correct
4 Halted 0 ms 0 KB -