結果

問題 No.1170 Never Want to Walk
ユーザー kk
提出日時 2021-04-19 00:39:47
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 384 ms / 2,000 ms
コード長 1,355 bytes
コンパイル時間 2,408 ms
コンパイル使用メモリ 211,624 KB
実行使用メモリ 14,816 KB
最終ジャッジ日時 2023-09-17 08:06:38
合計ジャッジ時間 10,449 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 4 ms
4,380 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 3 ms
4,380 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 AC 3 ms
4,380 KB
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 3 ms
4,376 KB
testcase_24 AC 3 ms
4,380 KB
testcase_25 AC 3 ms
4,376 KB
testcase_26 AC 3 ms
4,376 KB
testcase_27 AC 369 ms
14,400 KB
testcase_28 AC 359 ms
14,140 KB
testcase_29 AC 384 ms
14,600 KB
testcase_30 AC 367 ms
14,560 KB
testcase_31 AC 366 ms
14,436 KB
testcase_32 AC 342 ms
14,308 KB
testcase_33 AC 352 ms
14,156 KB
testcase_34 AC 356 ms
14,600 KB
testcase_35 AC 349 ms
14,632 KB
testcase_36 AC 344 ms
14,280 KB
testcase_37 AC 353 ms
14,352 KB
testcase_38 AC 360 ms
14,816 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

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

  int n, a, b;
  cin >> n >> a >> b;

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

  vector<int> g(n, -1);
  vector<int> cnt(n);
  
  set<pair<int, int> > r;
  for (int i = 0; i < n; i++)
    r.insert(make_pair(x[i], i));
  
  for (int v = 0; v < n; v++) {
    if (g[v] == -1) {
      queue<int> q;
      q.push(v);
      g[v] = v;
      ++cnt[v];
      r.erase(make_pair(x[v], v));
      
      while (!q.empty()) {
        int w = q.front();
        q.pop();

        // 左にあるもの
        auto ls = r.lower_bound(make_pair(x[w] - b, 0));
        auto lt = r.upper_bound(make_pair(x[w] - a, n));
        while (ls != lt) {
          int u = ls->second;
          q.push(u);
          g[u] = v;
          ++cnt[v];
          ++ls;
          r.erase(make_pair(x[u], u));
        }
        
        // 右にあるもの
        auto rs = r.lower_bound(make_pair(x[w] + a, 0));
        auto rt = r.upper_bound(make_pair(x[w] + b, n));
        while (rs != rt) {
          int u = rs->second;
          q.push(u);
          g[u] = v;
          ++cnt[v];
          ++rs;
          r.erase(make_pair(x[u], u));
        }
      }
    }
  }
  
  for (int i = 0; i < n; i++)
    cout << cnt[g[i]] << endl;
  
  return 0;
}
0