結果

問題 No.849 yuki国の分割統治
コンテスト
ユーザー MICHAEL
提出日時 2026-06-06 22:37:43
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,582 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,477 ms
コンパイル使用メモリ 335,680 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-06-06 22:37:52
合計ジャッジ時間 3,968 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 4
other WA * 26
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 200005;
struct P {
    LL x, y;
};
P a[maxn];
bool cmp(P p, P q) {
    if (p.x != q.x) {
        return p.x < q.x;
    }
    return p.y < q.y;
}
LL LLabs(LL x) {
    if (x < 0)
        return -x;
    else
        return x;
}
int main() {
    freopen("group.in", "r", stdin);
    freopen("group.out", "w", stdout);
    LL a1, b1, c1, d1;
    cin >> a1 >> b1 >> c1 >> d1;
    int n;
    cin >> n;
    LL det = a1 * d1 - b1 * c1;
    for (int i = 1; i <= n; i++) {
        LL x, y;
        cin >> x >> y;
        if (a1 == 0 && b1 == 0 && c1 == 0 && d1 == 0) {
            a[i].x = x;
            a[i].y = y;
        } else if (det != 0) {
            LL u = __int128(d1 * x) - __int128(c1 * y);
            LL v = -__int128(b1 * x) + __int128(a1 * y);
            LL m = LLabs(det);
            u %= m;
            v %= m;
            if (u < 0) {
                u += m;
            }
            if (v < 0) {
                v += m;
            }
            a[i].x = u;
            a[i].y = v;
        } else {
            LL dx = a1, dy = b1;
            if (dx == 0 && dy == 0) {
                dx = c1;
                dy = d1;
            }
            LL k = __int128(dx * y) - __int128(dy * x);
            a[i].x = k;
            a[i].y = 0;
        }
    }
    sort(a + 1, a + n + 1, cmp);
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        if (i == 1 || a[i].x != a[i - 1].x || a[i].y != a[i - 1].y) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}
0