結果

問題 No.33 アメーバがたくさん
ユーザー PachicobuePachicobue
提出日時 2017-06-29 17:23:23
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,338 bytes
コンパイル時間 1,770 ms
コンパイル使用メモリ 170,448 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 04:54:24
合計ジャッジ時間 2,223 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

#define show(x) cout << #x << " = " << x << endl

using namespace std;
using ll = long long;
using pii = pair<int, int>;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz=" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p)
{
    os << "(" << p.first << "," << p.second
       << ")";
    return os;
}

constexpr ll MOD = 1e9 + 7;

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 100;

int main()
{
    int N;
    ll D, T;
    cin >> N >> D >> T;
    const ll INT = D * T;
    vector<pair<ll, ll>> x(N);

    for (auto i = 0; i < N; i++) {
        ll x_;
        cin >> x_;
        x[i] = make_pair((x_ % D + D) % D, x_);
    }
    sort(x.begin(), x.end());
    int i = 0;
    ll num = 0;
    while (i < N) {
        const ll mod = x[i].first;
        const ll inf = x[i].second - INT;
        ll sup = x[i].second + INT;
        while (i < N) {
            i++;
            if (x[i].first != mod or x[i].second - INT > sup) {
                break;
            }
            sup = x[i].second + INT;
        }
        num += ((sup - inf) / D) + 1;
    }
    cout << num << endl;

    return 0;
}
0