結果

問題 No.849 yuki国の分割統治
ユーザー MisterMister
提出日時 2020-08-05 13:21:59
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 62 ms / 2,000 ms
コード長 1,203 bytes
コンパイル時間 865 ms
コンパイル使用メモリ 84,424 KB
実行使用メモリ 9,972 KB
最終ジャッジ日時 2023-10-14 13:46:55
合計ジャッジ時間 5,331 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,356 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 1 ms
4,352 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,352 KB
testcase_07 AC 41 ms
4,792 KB
testcase_08 AC 48 ms
6,844 KB
testcase_09 AC 48 ms
6,104 KB
testcase_10 AC 47 ms
5,068 KB
testcase_11 AC 44 ms
5,876 KB
testcase_12 AC 44 ms
4,904 KB
testcase_13 AC 49 ms
6,224 KB
testcase_14 AC 48 ms
5,648 KB
testcase_15 AC 46 ms
6,508 KB
testcase_16 AC 60 ms
8,612 KB
testcase_17 AC 39 ms
4,560 KB
testcase_18 AC 61 ms
8,908 KB
testcase_19 AC 49 ms
5,416 KB
testcase_20 AC 55 ms
7,456 KB
testcase_21 AC 32 ms
4,696 KB
testcase_22 AC 55 ms
8,008 KB
testcase_23 AC 53 ms
7,500 KB
testcase_24 AC 43 ms
5,432 KB
testcase_25 AC 62 ms
9,972 KB
testcase_26 AC 1 ms
4,352 KB
testcase_27 AC 2 ms
4,352 KB
testcase_28 AC 1 ms
4,348 KB
testcase_29 AC 2 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <numeric>
#include <vector>
#include <set>

using lint = long long;

void solve() {
    lint a, b, c, d;
    std::cin >> a >> b >> c >> d;

    int n;
    std::cin >> n;
    std::vector<std::pair<lint, lint>> ps(n);
    for (auto& p : ps) std::cin >> p.first >> p.second;

    lint det = std::abs(a * d - b * c);

    if (det != 0) {
        std::set<std::pair<lint, lint>> ss;

        for (auto p : ps) {
            lint x = d * p.first - c * p.second,
                 y = -b * p.first + a * p.second;
            ss.emplace((x % det + det) % det, (y % det + det) % det);
        }

        std::cout << ss.size() << "\n";

    } else {
        lint dx = std::gcd(a, c),
             dy = std::gcd(b, d);

        if (dx == 0) {
            std::swap(dx, dy);
            for (auto& p : ps) std::swap(p.first, p.second);
        }

        std::set<std::pair<lint, lint>> ss;

        for (auto p : ps) {
            lint k = p.first / dx;
            ss.emplace(p.first - k * dx, p.second - k * dy);
        }

        std::cout << ss.size() << "\n";
    }
}

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

    solve();

    return 0;
}
0