結果
問題 | No.1170 Never Want to Walk |
ユーザー | Mister |
提出日時 | 2020-08-14 22:12:18 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 242 ms / 2,000 ms |
コード長 | 1,389 bytes |
コンパイル時間 | 1,098 ms |
コンパイル使用メモリ | 93,300 KB |
最終ジャッジ日時 | 2025-01-13 00:01:29 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 37 |
ソースコード
#include <iostream> #include <set> #include <vector> #include <map> #include <queue> void solve() { int n, a, b; std::cin >> n >> a >> b; std::set<int> xs; std::map<int, int> xrev; for (int i = 0; i < n; ++i) { int x; std::cin >> x; xs.insert(x); xrev[x] = i; } std::vector<int> ans(n, -1); while (!xs.empty()) { std::vector<int> g; std::queue<int> que; que.push(*xs.begin()); xs.erase(xs.begin()); while (!que.empty()) { int x = que.front(); que.pop(); g.push_back(x); { int l = x - b, r = x - a; auto it = xs.lower_bound(l); while (it != xs.end() && *it <= r) { que.push(*it); it = xs.erase(it); } } { int l = x + a, r = x + b; auto it = xs.lower_bound(l); while (it != xs.end() && *it <= r) { que.push(*it); it = xs.erase(it); } } } for (auto x : g) { ans[xrev[x]] = g.size(); } } for (auto a : ans) std::cout << a << "\n"; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }