답안 #1099495

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1099495 2024-10-11T13:00:03 Z Zero_OP 이상한 기계 (APIO19_strange_device) C++14
100 / 100
559 ms 100324 KB
#include <bits/stdc++.h>

using namespace std;

#define rep(i, l, r) for(int i = (l), _r = (r); i < _r; ++i)
#define FOR(i, l, r) for(int i = (l), _r = (r); i <= _r; ++i)
#define ROF(i, r, l) for(int i = (r), _l = (l); i >= _l; --i)
#define all(v) begin(v), end(v)
#define compact(v) v.erase(unique(all(v)), end(v))
#define sz(v) (int)v.size()
#define dbg(x) "[" #x " = " << (x) << "]"

template<typename T>
bool minimize(T& a, const T& b){
    if(a > b) return a = b, true; return false;
}

template<typename T>
bool maximize(T& a, const T& b){
    if(a < b) return a = b, true; return false;
}

using ll = long long;
using ld = long double;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename T> T random_int(T l, T r){ return uniform_int_distribution<T>(l, r)(rng); }
template<typename T> T random_real(T l, T r){ return uniform_real_distribution<T>(l, r)(rng); }

void testcase(){
    int n; ll A, B;
    cin >> n >> A >> B;

    ll cycle;

    if(A / __gcd(A, B + 1) > 1e18 / B || A / __gcd(A, B + 1) * B > 1e18){
        cycle = LLONG_MAX;
    } else{
        cycle = A / __gcd(A, B + 1) * B;
    }

    map<ll, int> diff;

    rep(_, 0, n){
        ll l, r;
        cin >> l >> r;

        if(r - l + 1 >= cycle){
            cout << cycle << '\n';
            return;
        }

        l %= cycle;
        r %= cycle;

        if(l <= r){
            diff[l] += 1;
            diff[r + 1] -= 1;
        } else{
            diff[0] += 1;
            diff[r + 1] -= 1;
            diff[l] += 1;
            diff[cycle] -= 1;
        }
    }

    int sum = 0;
    ll ans = 0, last = 0;
    for(auto [pos, val] : diff){
        if(sum > 0){
            ans += pos - last;
        }

        sum += val;
        last = pos;
    }

    cout << ans << '\n';
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    #define filename "task"
    if(fopen(filename".inp", "r")){
        freopen(filename".inp", "r", stdin);
        freopen(filename".out", "w", stdout);
    }

    int T = 1; //cin >> T;
    while(T--) testcase();

    return 0;
}

Compilation message

strange_device.cpp: In function 'bool minimize(T&, const T&)':
strange_device.cpp:15:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   15 |     if(a > b) return a = b, true; return false;
      |     ^~
strange_device.cpp:15:35: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   15 |     if(a > b) return a = b, true; return false;
      |                                   ^~~~~~
strange_device.cpp: In function 'bool maximize(T&, const T&)':
strange_device.cpp:20:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   20 |     if(a < b) return a = b, true; return false;
      |     ^~
strange_device.cpp:20:35: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   20 |     if(a < b) return a = b, true; return false;
      |                                   ^~~~~~
strange_device.cpp: In function 'void testcase()':
strange_device.cpp:69:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   69 |     for(auto [pos, val] : diff){
      |              ^
strange_device.cpp: In function 'int main()':
strange_device.cpp:87:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   87 |         freopen(filename".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:88:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   88 |         freopen(filename".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 4 ms 1372 KB Output is correct
3 Correct 4 ms 1372 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 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 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 1 ms 348 KB Output is correct
15 Correct 0 ms 352 KB Output is correct
16 Correct 4 ms 1376 KB Output is correct
17 Correct 44 ms 10224 KB Output is correct
18 Correct 1 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 460 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 352 KB Output is correct
2 Correct 1 ms 472 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 352 KB Output is correct
5 Correct 154 ms 25648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 439 ms 100248 KB Output is correct
3 Correct 464 ms 100044 KB Output is correct
4 Correct 528 ms 100180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 439 ms 100248 KB Output is correct
3 Correct 464 ms 100044 KB Output is correct
4 Correct 528 ms 100180 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 470 ms 100176 KB Output is correct
7 Correct 488 ms 100176 KB Output is correct
8 Correct 486 ms 100064 KB Output is correct
9 Correct 549 ms 100052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 439 ms 100248 KB Output is correct
3 Correct 464 ms 100044 KB Output is correct
4 Correct 528 ms 100180 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 39 ms 10352 KB Output is correct
7 Correct 38 ms 10420 KB Output is correct
8 Correct 41 ms 10336 KB Output is correct
9 Correct 44 ms 10320 KB Output is correct
10 Correct 39 ms 10388 KB Output is correct
11 Correct 37 ms 10324 KB Output is correct
12 Correct 38 ms 10324 KB Output is correct
13 Correct 48 ms 10324 KB Output is correct
14 Correct 37 ms 10332 KB Output is correct
15 Correct 45 ms 10344 KB Output is correct
16 Correct 47 ms 10324 KB Output is correct
17 Correct 42 ms 10288 KB Output is correct
18 Correct 436 ms 100176 KB Output is correct
19 Correct 496 ms 100180 KB Output is correct
20 Correct 526 ms 100176 KB Output is correct
21 Correct 40 ms 10332 KB Output is correct
22 Correct 42 ms 10324 KB Output is correct
23 Correct 72 ms 13140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 48 ms 10340 KB Output is correct
3 Correct 46 ms 10344 KB Output is correct
4 Correct 476 ms 100324 KB Output is correct
5 Correct 46 ms 10324 KB Output is correct
6 Correct 44 ms 10320 KB Output is correct
7 Correct 45 ms 10360 KB Output is correct
8 Correct 44 ms 10324 KB Output is correct
9 Correct 43 ms 10316 KB Output is correct
10 Correct 41 ms 10276 KB Output is correct
11 Correct 42 ms 10320 KB Output is correct
12 Correct 39 ms 10336 KB Output is correct
13 Correct 45 ms 10440 KB Output is correct
14 Correct 512 ms 100168 KB Output is correct
15 Correct 38 ms 10308 KB Output is correct
16 Correct 460 ms 100160 KB Output is correct
17 Correct 470 ms 100272 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 4 ms 1372 KB Output is correct
3 Correct 4 ms 1372 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 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 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 1 ms 348 KB Output is correct
15 Correct 0 ms 352 KB Output is correct
16 Correct 4 ms 1376 KB Output is correct
17 Correct 44 ms 10224 KB Output is correct
18 Correct 1 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 460 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 352 KB Output is correct
25 Correct 1 ms 472 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 352 KB Output is correct
28 Correct 154 ms 25648 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 439 ms 100248 KB Output is correct
31 Correct 464 ms 100044 KB Output is correct
32 Correct 528 ms 100180 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 470 ms 100176 KB Output is correct
35 Correct 488 ms 100176 KB Output is correct
36 Correct 486 ms 100064 KB Output is correct
37 Correct 549 ms 100052 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 39 ms 10352 KB Output is correct
40 Correct 38 ms 10420 KB Output is correct
41 Correct 41 ms 10336 KB Output is correct
42 Correct 44 ms 10320 KB Output is correct
43 Correct 39 ms 10388 KB Output is correct
44 Correct 37 ms 10324 KB Output is correct
45 Correct 38 ms 10324 KB Output is correct
46 Correct 48 ms 10324 KB Output is correct
47 Correct 37 ms 10332 KB Output is correct
48 Correct 45 ms 10344 KB Output is correct
49 Correct 47 ms 10324 KB Output is correct
50 Correct 42 ms 10288 KB Output is correct
51 Correct 436 ms 100176 KB Output is correct
52 Correct 496 ms 100180 KB Output is correct
53 Correct 526 ms 100176 KB Output is correct
54 Correct 40 ms 10332 KB Output is correct
55 Correct 42 ms 10324 KB Output is correct
56 Correct 72 ms 13140 KB Output is correct
57 Correct 0 ms 344 KB Output is correct
58 Correct 48 ms 10340 KB Output is correct
59 Correct 46 ms 10344 KB Output is correct
60 Correct 476 ms 100324 KB Output is correct
61 Correct 46 ms 10324 KB Output is correct
62 Correct 44 ms 10320 KB Output is correct
63 Correct 45 ms 10360 KB Output is correct
64 Correct 44 ms 10324 KB Output is correct
65 Correct 43 ms 10316 KB Output is correct
66 Correct 41 ms 10276 KB Output is correct
67 Correct 42 ms 10320 KB Output is correct
68 Correct 39 ms 10336 KB Output is correct
69 Correct 45 ms 10440 KB Output is correct
70 Correct 512 ms 100168 KB Output is correct
71 Correct 38 ms 10308 KB Output is correct
72 Correct 460 ms 100160 KB Output is correct
73 Correct 470 ms 100272 KB Output is correct
74 Correct 0 ms 348 KB Output is correct
75 Correct 0 ms 344 KB Output is correct
76 Correct 1 ms 348 KB Output is correct
77 Correct 1 ms 348 KB Output is correct
78 Correct 0 ms 348 KB Output is correct
79 Correct 5 ms 1368 KB Output is correct
80 Correct 534 ms 100036 KB Output is correct
81 Correct 520 ms 100180 KB Output is correct
82 Correct 529 ms 100044 KB Output is correct
83 Correct 531 ms 100176 KB Output is correct
84 Correct 559 ms 100176 KB Output is correct
85 Correct 519 ms 100180 KB Output is correct
86 Correct 73 ms 12884 KB Output is correct
87 Correct 0 ms 348 KB Output is correct