Submission #984358

# Submission time Handle Problem Language Result Execution time Memory
984358 2024-05-16T14:34:01 Z SmuggingSpun Strange Device (APIO19_strange_device) C++14
15 / 100
226 ms 34460 KB
#include<bits/stdc++.h>
#define taskname "A"
using namespace std;
typedef long long ll;
const int lim = 1e6 + 5;
int n;
ll A, B, S = 0, l[lim], r[lim];
namespace sub1{
	void solve(){
		map<pair<ll, ll>, bool>cnt;
		for(int i = 0; i < n; i++){
			for(ll j = l[i]; j <= r[i]; j++){
				cnt[make_pair((j + j / B) % A, j % B)] = true;
			}
		}
		cout << cnt.size();
	}
}
ll next_mod(ll current, ll d, ll r){
	ll R = current % d;
	if(R < r){
		return current + r - R;
	}
	return current + d - R + r;
}
ll prev_mod(ll current, ll d, ll r){
	ll R = current % d;
	if(R > r){
		return current - R + r;
	}
	return current - d + r - R;
}
namespace sub2{
	void solve(){
		ll cnt_cycle = A / __gcd(A, B + 1), init_cnt = (prev_mod(r[0], B, l[0] % B) - l[0]) / B + 1;
		if(l[0] % B < r[0] % B){
			cout << min(init_cnt, cnt_cycle) * (r[0] % B - l[0] % B + 1) + min(init_cnt - 1, cnt_cycle) * (B - r[0] % B - 1 + l[0] % B);
		}
		else{
			cout << min(init_cnt, cnt_cycle) * (B - l[0] % B + r[0] % B + 1) + min(init_cnt - 1, cnt_cycle) * (l[0] % B + B - r[0] % B - 1);
		}
	}
}
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	if(fopen(taskname".inp", "r")){
		freopen(taskname".inp", "r", stdin);
	}
	cin >> n >> A >> B;
	for(int i = 0; i < n; i++){
		cin >> l[i] >> r[i];
		S += r[i] - l[i] + 1;
	}
	if(S <= 1000000){
		sub1::solve();
	}
	else if(n == 1){
		sub2::solve();
	}
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:47:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |   freopen(taskname".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 35 ms 14416 KB Output is correct
3 Correct 56 ms 20048 KB Output is correct
4 Correct 2 ms 2908 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2648 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 6 ms 3164 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 32 ms 9240 KB Output is correct
16 Correct 22 ms 8792 KB Output is correct
17 Correct 48 ms 13396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 104 ms 34252 KB Output is correct
3 Correct 138 ms 34460 KB Output is correct
4 Correct 107 ms 32600 KB Output is correct
5 Incorrect 169 ms 16000 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Incorrect 226 ms 15992 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Incorrect 226 ms 15992 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Incorrect 226 ms 15992 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Incorrect 23 ms 6748 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 35 ms 14416 KB Output is correct
3 Correct 56 ms 20048 KB Output is correct
4 Correct 2 ms 2908 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2648 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 6 ms 3164 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 32 ms 9240 KB Output is correct
16 Correct 22 ms 8792 KB Output is correct
17 Correct 48 ms 13396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2392 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 104 ms 34252 KB Output is correct
26 Correct 138 ms 34460 KB Output is correct
27 Correct 107 ms 32600 KB Output is correct
28 Incorrect 169 ms 16000 KB Output isn't correct
29 Halted 0 ms 0 KB -