結果
問題 | No.321 (P,Q)-サンタと街の子供たち |
ユーザー | Grenache |
提出日時 | 2015-12-14 19:47:18 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,606 bytes |
コンパイル時間 | 3,707 ms |
コンパイル使用メモリ | 75,216 KB |
実行使用メモリ | 58,684 KB |
最終ジャッジ日時 | 2023-10-13 16:42:27 |
合計ジャッジ時間 | 12,310 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 40 ms
49,432 KB |
testcase_01 | AC | 41 ms
49,436 KB |
testcase_02 | AC | 42 ms
49,624 KB |
testcase_03 | AC | 41 ms
49,496 KB |
testcase_04 | AC | 42 ms
49,432 KB |
testcase_05 | AC | 40 ms
49,412 KB |
testcase_06 | AC | 40 ms
47,428 KB |
testcase_07 | AC | 44 ms
49,440 KB |
testcase_08 | AC | 43 ms
49,448 KB |
testcase_09 | AC | 41 ms
49,312 KB |
testcase_10 | AC | 40 ms
49,444 KB |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | AC | 40 ms
49,296 KB |
testcase_14 | WA | - |
testcase_15 | AC | 299 ms
58,044 KB |
testcase_16 | AC | 182 ms
55,440 KB |
testcase_17 | AC | 50 ms
49,944 KB |
testcase_18 | AC | 200 ms
56,884 KB |
testcase_19 | WA | - |
testcase_20 | AC | 292 ms
57,748 KB |
testcase_21 | WA | - |
testcase_22 | AC | 138 ms
56,012 KB |
testcase_23 | AC | 264 ms
58,684 KB |
testcase_24 | AC | 155 ms
56,416 KB |
testcase_25 | WA | - |
testcase_26 | AC | 272 ms
57,292 KB |
testcase_27 | WA | - |
testcase_28 | AC | 257 ms
57,548 KB |
testcase_29 | AC | 311 ms
57,780 KB |
testcase_30 | AC | 99 ms
53,596 KB |
testcase_31 | AC | 72 ms
51,964 KB |
testcase_32 | AC | 205 ms
57,248 KB |
testcase_33 | WA | - |
testcase_34 | AC | 188 ms
55,740 KB |
testcase_35 | WA | - |
testcase_36 | AC | 107 ms
53,856 KB |
testcase_37 | AC | 233 ms
57,460 KB |
testcase_38 | AC | 213 ms
56,956 KB |
testcase_39 | WA | - |
testcase_40 | AC | 307 ms
57,624 KB |
testcase_41 | WA | - |
testcase_42 | AC | 294 ms
57,664 KB |
testcase_43 | AC | 188 ms
56,504 KB |
testcase_44 | AC | 251 ms
57,732 KB |
ソースコード
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; if (p % q == 0) { tmp = q; } else { tmp = gcd(p, q); } if ((p / tmp + 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); } } }