結果

問題 No.849 yuki国の分割統治
ユーザー 37zigen37zigen
提出日時 2019-07-06 01:12:41
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 1,303 bytes
コンパイル時間 2,430 ms
コンパイル使用メモリ 82,592 KB
実行使用メモリ 81,660 KB
最終ジャッジ日時 2024-04-16 08:20:17
合計ジャッジ時間 26,871 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 177 ms
54,808 KB
testcase_01 AC 177 ms
54,712 KB
testcase_02 AC 180 ms
54,820 KB
testcase_03 AC 176 ms
54,740 KB
testcase_04 AC 176 ms
55,184 KB
testcase_05 AC 179 ms
55,172 KB
testcase_06 AC 172 ms
54,668 KB
testcase_07 RE -
testcase_08 AC 1,086 ms
73,404 KB
testcase_09 AC 1,094 ms
71,784 KB
testcase_10 AC 1,143 ms
70,092 KB
testcase_11 AC 1,072 ms
70,584 KB
testcase_12 AC 1,120 ms
69,852 KB
testcase_13 AC 1,161 ms
71,984 KB
testcase_14 AC 1,155 ms
71,808 KB
testcase_15 AC 1,061 ms
70,108 KB
testcase_16 AC 1,242 ms
77,328 KB
testcase_17 AC 1,089 ms
69,996 KB
testcase_18 AC 1,292 ms
76,552 KB
testcase_19 AC 1,145 ms
70,996 KB
testcase_20 AC 1,220 ms
74,176 KB
testcase_21 AC 1,037 ms
68,984 KB
testcase_22 AC 1,218 ms
75,556 KB
testcase_23 AC 1,199 ms
74,184 KB
testcase_24 AC 1,139 ms
69,996 KB
testcase_25 AC 1,234 ms
81,660 KB
testcase_26 AC 165 ms
54,768 KB
testcase_27 AC 166 ms
54,724 KB
testcase_28 AC 167 ms
55,088 KB
testcase_29 AC 167 ms
54,860 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	void run() {

		Scanner sc = new Scanner(System.in);

		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		long d = sc.nextLong();
		int N = sc.nextInt();
		HashSet<String> set = new HashSet<>();
		long det = a * d - b * c;
		det = Math.abs(det);
		if (det != 0) {
			for (int i = 0; i < N; ++i) {
				long x = sc.nextLong() % det;
				long y = sc.nextLong() % det;
				long s = ((d * x - c * y) % det + det) % det;
				long t = ((-b * x + a * y) % det + det) % det;
				set.add(s + ":" + t);
			}
		} else {
			if (a < 0) {
				a *= -1;
				b *= -1;
			}
			if (c < 0) {
				c *= -1;
				d *= -1;
			}
			long gcd = a != 0 ? gcd(a, c) : gcd(b, d);
			long div = a / gcd;
			a /= div;
			b /= div;
			for (int i = 0; i < N; ++i) {
				long x = sc.nextLong();
				long y = sc.nextLong();
				long s = x % a;
				long t = y - x / a * b;
				set.add(s + ":" + t);
			}
		}
		System.out.println(set.size());
	}

	long gcd(long a, long b) {
		if (a > b) {
			return gcd(b, a);
		}
		if (a == 0)
			return b;
		return gcd(a, b % a);
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}
0