提出 #70445972


ソースコード 拡げる

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

#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fix(x) fixed << setprecision(x)
#define rep(i, start, end) for (auto i = (start); (i) < (end); (i)++)
#define repe(i, start, end) for (auto i = (start); (i) <= (end); (i)++)
#define rrep(i, start, end) for (auto i = (start); (i) >= (end); (i)--)

constexpr auto PI = 3.14159265358979;
constexpr int INF = 1e+9;
constexpr long long INFL = 1e+18;

using ll = long long;
using lld = long double;
// using mint = modint1000000007;
using mint = modint998244353;
using Pair_int = pair<int, int>;
using Pair_ll = pair<ll, ll>;
template <class T>
using Graph = vector<vector<T>>;

template <class T1, class T2>
inline auto div_floor(T1 a, T2 b)
{
    if (b < 0)
        a *= -1, b *= -1;
    if (a >= 0)
        return a / b;
    else
        return (a + 1) / b - 1;
}
template <class T1, class T2>
inline auto div_ceil(T1 a, T2 b)
{
    if (b < 0)
        a *= -1, b *= -1;
    if (a <= 0)
        return a / b;
    else
        return (a - 1) / b + 1;
}
ll floor_sqrt(ll x)
{
    ll y = sqrt(x);
    while (y * y > x)
        y--;
    while ((y + 1) * (y + 1) <= x)
        y++;
    return y;
}
ll pow_int(ll x, ll n)
{
    ll res = 1;
    while (n > 0)
    {
        if (n & 1)
            res *= x;
        x *= x;
        n >>= 1;
    }
    return res;
}
ll pow_mod(ll x, ll n, ll mod)
{
    ll res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}
ll gcd(ll x, ll y)
{
    if (x < y)
        swap(x, y);
    ll r;
    while (y > 0)
    {
        r = x % y;
        x = y;
        y = r;
    }
    return x;
}
ll lcm(ll x, ll y) { return ll(x / gcd(x, y)) * y; }
ll nCk(ll n, ll r)
{
    if (r < 0 || n < r)
        return 0;
    ll ans = 1;
    for (ll i = 1; i <= r; i++)
    {
        ans *= n--;
        ans /= i;
    }
    return ans;
}
int get_rand(int seed, int min, int max)
{
    static mt19937_64 mt64(seed);
    uniform_int_distribution<int> get_rand_int(min, max);
    return get_rand_int(mt64);
}
template <typename T>
inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); }
template <typename T>
inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); }
template <class T1, class T2>
inline auto mod(T1 x, T2 r) { return (x % r + r) % r; }

// ======================================== //

int main()
{
    ll N, M, C;
    cin >> N >> M >> C;
    map<ll, int> mp;
    rep(i, 0, N)
    {
        ll A;
        cin >> A;
        mp[A]++;
    }

    vector<pair<ll, int>> pos;
    for (auto &[key, val] : mp)
    {
        pos.push_back({key, val});
    }

    int k = pos.size();
    vector<pair<ll, int>> pos2 = pos;
    rep(i, 0, k) pos2.push_back({pos[i].first + M, pos[i].second});

    vector<ll> ps(2 * k + 1, 0);
    rep(i, 0, 2 * k) ps[i + 1] = ps[i] + pos2[i].second;

    auto get_x = [&](int start) -> ll
    {
        ll target_num = ps[start] + C;

        auto it = lower_bound(ps.begin() + start + 1, ps.end(), target_num);
        int target_idx = distance(ps.begin(), it) - 1;

        return ps[target_idx + 1] - ps[start];
    };

    ll ans = 0;
    rep(j, 0, k - 1)
    {
        ll q = pos[j + 1].first - pos[j].first;
        ans += q * get_x(j + 1);
    }

    ll q_end = M - pos[k - 1].first;
    ans += q_end * get_x(k);

    ll q_start = pos[0].first;
    ans += q_start * get_x(0);

    cout << ans << endl;

    return 0;
}

提出情報

提出日時
問題 D - On AtCoder Conference
ユーザ Yuulis
言語 C++ 23 (gcc 12.2)
得点 425
コード長 3620 Byte
結果 AC
実行時間 634 ms
メモリ 65688 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 425 / 425
結果
AC × 2
AC × 32
セット名 テストケース
Sample example_00.txt, example_01.txt
All example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt
ケース名 結果 実行時間 メモリ
example_00.txt AC 1 ms 3568 KiB
example_01.txt AC 1 ms 3544 KiB
hand_00.txt AC 148 ms 3516 KiB
hand_01.txt AC 147 ms 3544 KiB
hand_02.txt AC 634 ms 65688 KiB
hand_03.txt AC 43 ms 3492 KiB
hand_04.txt AC 1 ms 3516 KiB
hand_05.txt AC 1 ms 3560 KiB
random_00.txt AC 69 ms 3564 KiB
random_01.txt AC 68 ms 3592 KiB
random_02.txt AC 73 ms 3616 KiB
random_03.txt AC 153 ms 6676 KiB
random_04.txt AC 180 ms 8628 KiB
random_05.txt AC 160 ms 7024 KiB
random_06.txt AC 451 ms 38980 KiB
random_07.txt AC 446 ms 37948 KiB
random_08.txt AC 424 ms 35624 KiB
random_09.txt AC 144 ms 3652 KiB
random_10.txt AC 149 ms 3648 KiB
random_11.txt AC 144 ms 3804 KiB
random_12.txt AC 141 ms 3532 KiB
random_13.txt AC 167 ms 3992 KiB
random_14.txt AC 163 ms 3644 KiB
random_15.txt AC 156 ms 3952 KiB
random_16.txt AC 180 ms 3936 KiB
random_17.txt AC 184 ms 4144 KiB
random_18.txt AC 174 ms 8044 KiB
random_19.txt AC 250 ms 7672 KiB
random_20.txt AC 233 ms 7256 KiB
random_21.txt AC 404 ms 38300 KiB
random_22.txt AC 493 ms 34760 KiB
random_23.txt AC 619 ms 60384 KiB