結果

問題 No.849 yuki国の分割統治
ユーザー 37zigen37zigen
提出日時 2019-07-06 01:27:03
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,265 ms / 2,000 ms
コード長 1,414 bytes
コンパイル時間 2,539 ms
コンパイル使用メモリ 80,788 KB
実行使用メモリ 81,756 KB
最終ジャッジ日時 2024-04-16 08:21:31
合計ジャッジ時間 28,355 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 178 ms
54,844 KB
testcase_01 AC 179 ms
54,996 KB
testcase_02 AC 181 ms
54,992 KB
testcase_03 AC 180 ms
54,984 KB
testcase_04 AC 182 ms
54,964 KB
testcase_05 AC 180 ms
54,960 KB
testcase_06 AC 174 ms
54,948 KB
testcase_07 AC 1,153 ms
69,088 KB
testcase_08 AC 1,106 ms
74,256 KB
testcase_09 AC 1,142 ms
72,048 KB
testcase_10 AC 1,138 ms
69,716 KB
testcase_11 AC 1,054 ms
72,136 KB
testcase_12 AC 1,100 ms
69,780 KB
testcase_13 AC 1,142 ms
72,044 KB
testcase_14 AC 1,132 ms
72,040 KB
testcase_15 AC 1,180 ms
70,268 KB
testcase_16 AC 1,258 ms
76,616 KB
testcase_17 AC 1,096 ms
69,332 KB
testcase_18 AC 1,265 ms
77,696 KB
testcase_19 AC 1,174 ms
70,896 KB
testcase_20 AC 1,205 ms
74,212 KB
testcase_21 AC 1,115 ms
69,476 KB
testcase_22 AC 1,246 ms
75,368 KB
testcase_23 AC 1,187 ms
74,184 KB
testcase_24 AC 1,168 ms
69,056 KB
testcase_25 AC 1,258 ms
81,756 KB
testcase_26 AC 164 ms
55,056 KB
testcase_27 AC 165 ms
55,068 KB
testcase_28 AC 164 ms
54,704 KB
testcase_29 AC 166 ms
54,968 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 != 0 ? a / gcd : b / gcd;
			a /= div;
			b /= div;
			for (int i = 0; i < N; ++i) {
				long x = sc.nextLong();
				long y = sc.nextLong();
				long s = 0, t = 0;
				if (a != 0) {
					s = x % a;
					t = y - x / a * b;
				} else {
					t = y % b;
					s = x - y / b * a;
				}
				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