結果

問題 No.33 アメーバがたくさん
ユーザー xuzijian629xuzijian629
提出日時 2018-10-28 02:25:27
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 922 bytes
コンパイル時間 2,967 ms
コンパイル使用メモリ 210,664 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-12 07:56:17
合計ジャッジ時間 3,896 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 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