답안 #1032661

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

int main(){
	// freopen("file.txt", "r", stdin);
	int n, a, b;
	scanf("%d%d%d", &n, &a, &b);
	if (true) {
		// (2x % a, 0)
		// 2x % a == 0
		// if a is odd, then the ans is of length a (the 2 will never
		// contribute)
		// if a is even, then the ans of of length a/2
		ll ans = (a%2 == 0 ? a/2 : a);
		if (b){
		  // w (B + 1) mod A = 0
		  if (b/gcd(a, b+1) >= (INF+1)/a)
		    ans = INF+1;
		  else
		  	ans = a/gcd(a, b+1)*b;
		}
		vector<pair<ll, ll>> v;
		map<ll, ll> mp;
		while(n--){
		  ll l, r;
		  scanf("%lld%lld", &l ,&r);
		  ll _l = l%ans, _r = r%ans;
		  if (r-l+1 >= ans){
		  	printf("%lld\n", ans);
		    return 0;
		  }
		  if(_l > _r)
		    v.pb({_l, ans - 1}), v.pb({0, _r});
		  else
		    v.pb({_l, _r});
		}
		for(auto &[l, r] : v)
		  mp[l] = max(mp[l], r);
		ll r_ = 0;
		ans = 0;
		for(auto &i : mp){
		  if(i.ss < r_)
		    continue;
		  r_ = max(r_, i.ff);
		  ans += i.ss-r_+1;
		  r_ = i.ss+1;
		}
		printf("%lld\n", ans);
		return 0;
	}
	set<pair<ll, ll>> st;
	while(n--){
		ll l, r;
		scanf("%lld%lld", &l, &r);
		for(ll x = l; x <= r; ++x)
		  st.insert({(x+x/b)%a, x%b});
	}
    ll answer = st.size();
    printf("%lld\n", answer);
	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%d%d", &n, &a, &b);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:38:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |     scanf("%lld%lld", &l ,&r);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~
strange_device.cpp:66:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |   scanf("%lld%lld", &l, &r);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 4 ms 1496 KB Output is correct
3 Correct 6 ms 1604 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 1 ms 608 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 444 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 352 KB Output is correct
14 Correct 0 ms 352 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 4 ms 1500 KB Output is correct
17 Correct 44 ms 11972 KB Output is correct
18 Correct 0 ms 348 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 352 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 0 ms 356 KB Output is correct
2 Correct 1 ms 352 KB Output is correct
3 Correct 1 ms 352 KB Output is correct
4 Correct 1 ms 608 KB Output is correct
5 Correct 186 ms 41220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 352 KB Output is correct
2 Correct 472 ms 115808 KB Output is correct
3 Incorrect 523 ms 115648 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 352 KB Output is correct
2 Correct 472 ms 115808 KB Output is correct
3 Incorrect 523 ms 115648 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 352 KB Output is correct
2 Correct 472 ms 115808 KB Output is correct
3 Incorrect 523 ms 115648 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 46 ms 11892 KB Output is correct
3 Incorrect 38 ms 11980 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 4 ms 1496 KB Output is correct
3 Correct 6 ms 1604 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 1 ms 608 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 444 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 352 KB Output is correct
14 Correct 0 ms 352 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 4 ms 1500 KB Output is correct
17 Correct 44 ms 11972 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 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 356 KB Output is correct
25 Correct 1 ms 352 KB Output is correct
26 Correct 1 ms 352 KB Output is correct
27 Correct 1 ms 608 KB Output is correct
28 Correct 186 ms 41220 KB Output is correct
29 Correct 0 ms 352 KB Output is correct
30 Correct 472 ms 115808 KB Output is correct
31 Incorrect 523 ms 115648 KB Output isn't correct
32 Halted 0 ms 0 KB -