結果

問題 No.33 アメーバがたくさん
ユーザー kk
提出日時 2021-02-19 14:50:02
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 978 bytes
コンパイル時間 2,204 ms
コンパイル使用メモリ 212,496 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-14 09:09:08
合計ジャッジ時間 2,979 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

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

  int n;
  long long d, t;
  cin >> n >> d >> t;

  vector<long long> x(n);
  for (int i = 0; i < n; i++)
    cin >> x[i];

  set<long long> mod;
  for (int i = 0; i < n; i++)
    mod.insert((x[i] % d + d) % d);

  long long ret = 0;
  for (long long m: mod) {
    vector<long long> y;
    for (int i = 0; i < n; i++)
      if ((x[i] % d + d) % d == m)
        y.push_back(x[i]);

    sort(y.begin(), y.end());
    vector<pair<long long, long long> > v;
    for (int i = 0; i < y.size(); i++) {
      long long l = y[i] - d * t;
      long long r = y[i] + d * t;
      if (v.empty())
        v.emplace_back(l, r);
      else if (l <= v.back().second)
        v.back().second = max(v.back().second, r);
      else
        v.emplace_back(l, r);
    }

    for (auto &pr: v) {
      ret += (pr.second - pr.first) / d + 1;
    }
  }

  cout << ret << endl;
  
  return 0;
}
0