結果

問題 No.2627 Unnatural Pitch
ユーザー sidekick257sidekick257
提出日時 2024-04-24 15:47:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,769 bytes
コンパイル時間 935 ms
コンパイル使用メモリ 81,292 KB
実行使用メモリ 45,568 KB
最終ジャッジ日時 2024-04-24 15:47:24
合計ジャッジ時間 7,126 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 176 ms
31,488 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 307 ms
45,440 KB
testcase_05 AC 314 ms
45,568 KB
testcase_06 AC 250 ms
32,896 KB
testcase_07 AC 75 ms
5,376 KB
testcase_08 AC 136 ms
17,280 KB
testcase_09 AC 326 ms
45,440 KB
testcase_10 AC 312 ms
45,440 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 WA -
testcase_16 AC 225 ms
23,168 KB
testcase_17 AC 323 ms
40,960 KB
testcase_18 AC 218 ms
19,456 KB
testcase_19 AC 275 ms
30,208 KB
testcase_20 AC 77 ms
11,520 KB
testcase_21 AC 187 ms
30,080 KB
testcase_22 AC 273 ms
37,888 KB
testcase_23 AC 169 ms
28,288 KB
testcase_24 AC 131 ms
15,488 KB
testcase_25 AC 187 ms
28,800 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <map>
#include <vector>
using namespace std;
using ll = long long;

int main() {
    ll N, K, L, U;
    cin >> N >> K >> L >> U;
    vector<ll> A(N);
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
    }
    ll diffs = U - L;
    // 「L より小さいものの個数」 <= 「U より大きいものの個数」
    ll ok = 0;
    ll ng = 1000000000002;
    while (ng - ok > 1) {
        ll mid = (ok + ng) / 2;
        ll lower = 0;
        ll upper = 0;
        for (ll i = 0; i < N; i++) {
            if (A[i] < mid) {
                lower++;
            }
            if (A[i] > mid + diffs) {
                upper++;
            }
        }
        if (lower <= upper) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    map<ll, ll> mp;
    for (ll i = 0; i < N; i++) {
        mp[A[i]]++;
    }
    ll ans = 1000000000000000002;

    ll now_score = 0;
    ll now_L = ok - K;
    ll now_U = now_L + diffs;

    vector<ll> left_rem(K, 0);   // 左側の値の余り
    vector<ll> right_rem(K, 0);  // 右側の値の余り
    for (ll i = 0; i < N; i++) {
        if (A[i] < now_L) {
            now_score += ((now_L - A[i] + K - 1) / K);
            left_rem[A[i] % K]++;
        }
        if (A[i] > now_U) {
            now_score += ((A[i] - now_U + K - 1) / K);
            right_rem[A[i] % K]++;
        }
    }
    ans = min(ans, now_score);
    for (ll i = 0; i <= K; i++) {
        left_rem[(now_L % K + K) % K] += mp[now_L];
        now_score += left_rem[(now_L % K + K) % K];
        now_L++;
        now_U++;
        now_score -= right_rem[(now_U % K + K) % K];
        right_rem[(now_U % K + K) % K] -= mp[now_U];
        ans = min(ans, now_score);
    }
    cout << ans << endl;
}
0