Submission #74120913


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    ll L, R, D, U;
    cin >> L >> R >> D >> U;

    ll ans = 0;
    // 原点
    if (0 >= L && 0 <= R && 0 >= D && 0 <= U) ans++;

    ll M = max({abs(L), abs(R), abs(D), abs(U)});
    for (ll k = 2; k <= M; k += 2) {
        // 上边 y = k
        if (D <= k && k <= U) {
            ll left = max(L, -k);
            ll right = min(R, k);
            if (left <= right) ans += right - left + 1;
        }
        // 下边 y = -k
        if (D <= -k && -k <= U) {
            ll left = max(L, -k);
            ll right = min(R, k);
            if (left <= right) ans += right - left + 1;
        }
        // 左边 x = -k
        if (L <= -k && -k <= R) {
            ll low = max(D, -k + 1);
            ll high = min(U, k - 1);
            if (low <= high) ans += high - low + 1;
        }
        // 右边 x = k
        if (L <= k && k <= R) {
            ll low = max(D, -k + 1);
            ll high = min(U, k - 1);
            if (low <= high) ans += high - low + 1;
        }
    }

    cout << ans << endl;
    return 0;
}

Submission Info

Submission Time
Task D - Make Target 2
User nxzwcry
Language C++23 (GCC 15.2.0)
Score 425
Code Size 1161 Byte
Status AC
Exec Time 2 ms
Memory 3664 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 425 / 425
Status
AC × 2
AC × 29
Set Name Test Cases
Sample sample00.txt, sample01.txt
All sample00.txt, sample01.txt, testcase00.txt, testcase01.txt, testcase02.txt, testcase03.txt, testcase04.txt, testcase05.txt, testcase06.txt, testcase07.txt, testcase08.txt, testcase09.txt, testcase10.txt, testcase11.txt, testcase12.txt, testcase13.txt, testcase14.txt, testcase15.txt, testcase16.txt, testcase17.txt, testcase18.txt, testcase19.txt, testcase20.txt, testcase21.txt, testcase22.txt, testcase23.txt, testcase24.txt, testcase25.txt, testcase26.txt
Case Name Status Exec Time Memory
sample00.txt AC 1 ms 3532 KiB
sample01.txt AC 1 ms 3580 KiB
testcase00.txt AC 2 ms 3372 KiB
testcase01.txt AC 2 ms 3532 KiB
testcase02.txt AC 2 ms 3472 KiB
testcase03.txt AC 2 ms 3664 KiB
testcase04.txt AC 2 ms 3384 KiB
testcase05.txt AC 2 ms 3416 KiB
testcase06.txt AC 2 ms 3508 KiB
testcase07.txt AC 2 ms 3524 KiB
testcase08.txt AC 2 ms 3600 KiB
testcase09.txt AC 2 ms 3372 KiB
testcase10.txt AC 2 ms 3416 KiB
testcase11.txt AC 2 ms 3384 KiB
testcase12.txt AC 2 ms 3416 KiB
testcase13.txt AC 2 ms 3648 KiB
testcase14.txt AC 1 ms 3508 KiB
testcase15.txt AC 2 ms 3508 KiB
testcase16.txt AC 2 ms 3384 KiB
testcase17.txt AC 1 ms 3384 KiB
testcase18.txt AC 1 ms 3384 KiB
testcase19.txt AC 2 ms 3612 KiB
testcase20.txt AC 2 ms 3536 KiB
testcase21.txt AC 1 ms 3472 KiB
testcase22.txt AC 1 ms 3536 KiB
testcase23.txt AC 2 ms 3600 KiB
testcase24.txt AC 2 ms 3420 KiB
testcase25.txt AC 2 ms 3524 KiB
testcase26.txt AC 2 ms 3420 KiB