結果

問題 No.1137 Circles
ユーザー MisterMister
提出日時 2020-08-01 09:14:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 182 ms / 2,000 ms
コード長 1,114 bytes
コンパイル時間 1,046 ms
コンパイル使用メモリ 96,052 KB
実行使用メモリ 12,392 KB
最終ジャッジ日時 2023-09-21 22:00:53
合計ジャッジ時間 5,121 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 148 ms
11,584 KB
testcase_02 AC 3 ms
4,376 KB
testcase_03 AC 60 ms
7,560 KB
testcase_04 AC 102 ms
9,616 KB
testcase_05 AC 12 ms
4,396 KB
testcase_06 AC 122 ms
10,340 KB
testcase_07 AC 45 ms
6,612 KB
testcase_08 AC 129 ms
10,648 KB
testcase_09 AC 27 ms
5,636 KB
testcase_10 AC 53 ms
6,972 KB
testcase_11 AC 67 ms
7,620 KB
testcase_12 AC 182 ms
12,392 KB
testcase_13 AC 30 ms
5,716 KB
testcase_14 AC 161 ms
12,072 KB
testcase_15 AC 36 ms
5,928 KB
testcase_16 AC 62 ms
7,480 KB
testcase_17 AC 6 ms
4,380 KB
testcase_18 AC 122 ms
10,368 KB
testcase_19 AC 32 ms
5,788 KB
testcase_20 AC 21 ms
5,076 KB
testcase_21 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

template <class T>
std::map<T, int> compress(std::vector<T>& v) {
    std::sort(v.begin(), v.end());
    v.erase(std::unique(v.begin(), v.end()), v.end());

    std::map<T, int> rev;
    for (int i = 0; i < (int)v.size(); ++i) rev[v[i]] = i;
    return rev;
}

void solve() {
    int n;
    std::cin >> n;

    std::vector<std::pair<int, int>> ps(n);
    std::vector<int> xs;
    for (auto& p : ps) {
        int x, r;
        std::cin >> x >> r;
        x *= 2, r *= 2;

        p.first = x - r + 1;
        p.second = x + r;

        xs.push_back(p.first);
        xs.push_back(p.second);
    }

    auto revx = compress(xs);
    int m = xs.size();

    std::vector<int> imos(m + 1, 0);
    for (auto& p : ps) {
        ++imos[revx[p.first]];
        --imos[revx[p.second]];
    }

    for (int i = 0; i < m; ++i) {
        imos[i + 1] += imos[i];
    }

    std::cout << *std::max_element(imos.begin(), imos.end()) << "\n";
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}
0