結果

問題 No.33 アメーバがたくさん
ユーザー xuzijian629xuzijian629
提出日時 2018-10-28 02:25:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 922 bytes
コンパイル時間 2,365 ms
コンパイル使用メモリ 212,124 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-29 22:20:58
合計ジャッジ時間 2,970 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

int main() {
    unordered_map<i64, vi> as;
    i64 n, d, t;
    cin >> n >> d >> t;
    for (int i = 0; i < n; i++) {
        i64 x;
        cin >> x;
        as[((x % d) + d) % d].push_back(x);
    }
    for (auto& a: as) {
        sort(a.second.begin(), a.second.end());
    }
    i64 ans = 0;
    for (auto& a: as) {
        if (a.second.size() == 1) {
            ans += 2 * t + 1;
            continue;
        }

        i64 nax = a.second.front() + t * d;
        ans += 2 * t + 1;
        for (int i = 1; i < a.second.size(); i++) {
            i64 k = a.second[i] - t * d;
            if (k > nax) {
                ans += 2 * t + 1;
            } else {
                ans += 2 * t - (nax - k) / d;
            }
            nax = a.second[i] + t * d;
        }
    }
    cout << ans << endl;
}
0