結果

問題 No.33 アメーバがたくさん
ユーザー ふーらくたる
提出日時 2016-08-08 17:05:56
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 903 bytes
コンパイル時間 908 ms
コンパイル使用メモリ 78,736 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-24 15:18:18
合計ジャッジ時間 1,448 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

typedef long long ll;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    ll d, t;
    map<ll, vector<ll>> x_mod_d;

    cin >> n >> d >> t;
    for (int i = 0; i < n; i++) {
        ll x;
        cin >> x;

        if (x >= 0) x_mod_d[x % d].push_back(x);
        else {
            auto idx = d - (abs(x) % d);
            x_mod_d[idx].push_back(x);
        }
    }

    ll ans = 0;
    for (auto it = x_mod_d.begin(); it != x_mod_d.end(); it++) {
        auto& vec = it->second;
        sort(vec.begin(), vec.end());

        for (auto x_i = 0; x_i < vec.size(); x_i++) {
            if (x_i == 0) ans += 2 * t + 1;
            else {
                ans += min(2 * t + 1, (vec[x_i] - vec[x_i - 1]) / d);
            }
        }
    }
    cout << ans << endl;

    return 0;
}
0