結果

問題 No.321 (P,Q)-サンタと街の子供たち
ユーザー nebukuro09nebukuro09
提出日時 2017-06-14 10:07:02
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 62 ms / 2,000 ms
コード長 1,136 bytes
コンパイル時間 637 ms
コンパイル使用メモリ 116,688 KB
実行使用メモリ 7,388 KB
最終ジャッジ日時 2024-06-12 20:03:00
合計ジャッジ時間 3,248 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 41
権限があれば一括ダウンロードができます
コンパイルメッセージ
/home/linuxbrew/.linuxbrew/opt/dmd/include/dlang/dmd/std/numeric.d(2999): Warning: cannot inline function `std.numeric.gcdImpl!uint.gcdImpl`

ソースコード

diff #

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;

void main() {
    auto s = readln.split.map!(to!int);
    auto P = s[0];
    auto Q = s[1];
    auto N = readln.chomp.to!int;
    if (P > Q) swap(P, Q);

    if (P == 0 && Q == 0) {
        int ans = 0;
        while (N--) {
            s = readln.split.map!(to!int);
            if (s[0] == 0 && s[1] == 0) ans++;
        }
        ans.writeln;
        return;
    } else if (P == 0) {
        int ans = 0;
        while (N--) {
            s = readln.split.map!(to!int);
            if (s[0] % Q == 0 && s[1] % Q == 0) ans ++;
        }
        ans.writeln;
        return;
    }
    
    auto G = gcd(P, Q);
    P /= G;
    Q /= G;
    
    int ans = 0;
    
    while (N--) {
        s = readln.split.map!(to!int);
        auto x = s[0];
        auto y = s[1];
        if (x % G != 0 || y % G != 0) continue;
        x /= G;
        y /= G;
        if (P % 2 == 0 || Q % 2 == 0 || (x + y) % 2 == 0) ans += 1;
    }

    ans.writeln;
}
0