結果

問題 No.33 アメーバがたくさん
ユーザー ふーらくたるふーらくたる
提出日時 2016-08-08 17:05:56
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 903 bytes
コンパイル時間 745 ms
コンパイル使用メモリ 78,732 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 20:18:56
合計ジャッジ時間 1,321 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

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