結果

問題 No.321 (P,Q)-サンタと街の子供たち
ユーザー GrenacheGrenache
提出日時 2015-12-15 00:06:30
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,534 bytes
コンパイル時間 3,624 ms
コンパイル使用メモリ 75,032 KB
実行使用メモリ 58,596 KB
最終ジャッジ日時 2023-10-13 16:49:53
合計ジャッジ時間 12,125 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
49,568 KB
testcase_01 AC 42 ms
49,500 KB
testcase_02 AC 44 ms
49,348 KB
testcase_03 AC 42 ms
49,388 KB
testcase_04 AC 40 ms
49,632 KB
testcase_05 AC 41 ms
49,268 KB
testcase_06 AC 40 ms
49,460 KB
testcase_07 AC 44 ms
49,400 KB
testcase_08 AC 42 ms
49,412 KB
testcase_09 AC 41 ms
49,364 KB
testcase_10 AC 41 ms
49,456 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 42 ms
49,288 KB
testcase_14 WA -
testcase_15 AC 301 ms
57,984 KB
testcase_16 AC 186 ms
55,772 KB
testcase_17 AC 51 ms
49,624 KB
testcase_18 AC 197 ms
58,372 KB
testcase_19 WA -
testcase_20 AC 271 ms
57,824 KB
testcase_21 WA -
testcase_22 AC 140 ms
55,992 KB
testcase_23 AC 244 ms
57,176 KB
testcase_24 AC 160 ms
55,976 KB
testcase_25 WA -
testcase_26 AC 293 ms
57,992 KB
testcase_27 WA -
testcase_28 AC 217 ms
56,960 KB
testcase_29 AC 301 ms
56,060 KB
testcase_30 AC 101 ms
53,816 KB
testcase_31 AC 72 ms
51,832 KB
testcase_32 AC 204 ms
56,460 KB
testcase_33 WA -
testcase_34 AC 184 ms
56,412 KB
testcase_35 WA -
testcase_36 AC 103 ms
52,964 KB
testcase_37 AC 228 ms
56,964 KB
testcase_38 AC 216 ms
56,932 KB
testcase_39 WA -
testcase_40 AC 273 ms
57,844 KB
testcase_41 WA -
testcase_42 AC 265 ms
57,872 KB
testcase_43 AC 190 ms
56,324 KB
testcase_44 AC 268 ms
57,468 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Iterator;


public class Main_yukicoder321_1 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Printer pr = new Printer(System.out);

        int p = sc.nextInt();
        int q = sc.nextInt();
        if (p < q) {
        	int tmp = p;
        	p = q;
        	q = tmp;
        }

        int n = sc.nextInt();
        int ret = 0;
        for (int i = 0; i < n; i++) {
        	int x = Math.abs(sc.nextInt());
        	int y = Math.abs(sc.nextInt());

        	if (p == 0) {
        		if (x == 0 && y == 0) {
        			ret++;
        		}
        	} else if (q == 0) {
        		if (x % p == 0 && y % p == 0) {
        			ret++;
        		}
        	} else {
        		int tmp;
        		tmp = gcd(p, q);

        		if (p / tmp % 2 == 0 || q / tmp % 2 == 0) {
        			if (x % tmp == 0 && y % tmp == 0) {
        				ret++;
        			}
        		} else {
            		if (x % (2 * tmp) == 0 && y % (2 * tmp) == 0 && (x + y) % (2 * tmp) == 0 && (x - y) % (2 * tmp) == 0) {
            			ret++;
            		}
        		}
        	}
        }

        pr.println(ret);

        pr.close();
        sc.close();
    }

	private static int gcd(int n, int m) {
		if (m == 0) {
			return n;
		} else {
			return gcd(m, n % m);
		}
	}

	@SuppressWarnings("unused")
	private static class Scanner {
		BufferedReader br;
		Iterator<String> it;

		Scanner (InputStream in) {
			br = new BufferedReader(new InputStreamReader(in));
		}

		String next() throws RuntimeException  {
			try {
				if (it == null || !it.hasNext()) {
					it = Arrays.asList(br.readLine().split(" ")).iterator();
				}
				return it.next();
			} catch (IOException e) {
				throw new IllegalStateException();
			}
		}

		int nextInt() throws RuntimeException {
			return Integer.parseInt(next());
		}

		long nextLong() throws RuntimeException {
			return Long.parseLong(next());
		}

		float nextFloat() throws RuntimeException {
			return Float.parseFloat(next());
		}

		double nextDouble() throws RuntimeException {
			return Double.parseDouble(next());
		}

		void close() {
			try {
				br.close();
			} catch (IOException e) {
//				throw new IllegalStateException();
			}
		}
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}
0