답안 #729608

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
729608 2023-04-24T09:38:09 Z danikoynov 이상한 기계 (APIO19_strange_device) C++14
0 / 100
5000 ms 524288 KB
#include<bits/stdc++.h>
#define endl '\n'

using namespace std;
typedef long long ll;

void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

const int maxn = 1e6 + 10;

int n;
ll l[maxn], r[maxn];
ll A, B;

bool tf = false;
ll check(ll a, ll b)
{
    ///cout << a << " " << b << endl;
    if (a < 1e9 && b < 1e9)
        return a * b;
    if (a > b)
        swap(a, b);
    if (b % 2 == 1)
    {
        ll s = check(a, b - 1);
        if (s + a > 1e18)
            tf = true;
        return s + a;
    }
    ll s = check(a, b / 2);
    if (s * 2 > (ll)1e18)
        tf = true;

    return s * 2;
}
void solve()
{
    cin >> n >> A >> B;
    if (n > 9900)
        while(true);
    for (int i = 1; i <= n; i ++)
    {
        cin >> l[i] >> r[i];
    }
    check(A, B);

    if (tf)
    {
        ll ans = 0;
        for (int i = 1; i <= n; i ++)
        {
            ans = ans + (r[i] - l[i] + 1);
        }
        cout << ans << endl;
        return;
    }
    unordered_set < ll > st;
    for (int i = 1; i <= n; i ++)
    {

        for (ll j = l[i]; j <= r[i]; j ++)
        {
                 ll x = (j + (j / B)) % A, y = j % B;

            st.insert(j % (A * B));
        }
    }

    cout << st.size() << endl;
}

int main()
{
    solve();
    return 0;
}
/**
1  10000 3312452154131231
1 1
*/

Compilation message

strange_device.cpp: In function 'void solve()':
strange_device.cpp:68:21: warning: unused variable 'x' [-Wunused-variable]
   68 |                  ll x = (j + (j / B)) % A, y = j % B;
      |                     ^
strange_device.cpp:68:44: warning: unused variable 'y' [-Wunused-variable]
   68 |                  ll x = (j + (j / B)) % A, y = j % B;
      |                                            ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 5035 ms 212 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Runtime error 751 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 46 ms 21828 KB Output is correct
3 Correct 45 ms 21724 KB Output is correct
4 Correct 43 ms 20996 KB Output is correct
5 Execution timed out 5069 ms 212 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 5022 ms 212 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 5022 ms 212 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 5022 ms 212 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Execution timed out 5042 ms 212 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 5035 ms 212 KB Time limit exceeded
3 Halted 0 ms 0 KB -