結果

問題 No.896 友達以上恋人未満
ユーザー 37zigen37zigen
提出日時 2019-09-27 21:42:19
言語 Java21
(openjdk 21)
結果
MLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,071 bytes
コンパイル時間 3,465 ms
コンパイル使用メモリ 77,360 KB
実行使用メモリ 205,576 KB
最終ジャッジ日時 2023-10-25 02:25:45
合計ジャッジ時間 9,081 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
57,588 KB
testcase_01 AC 127 ms
57,080 KB
testcase_02 AC 129 ms
55,632 KB
testcase_03 AC 126 ms
57,636 KB
testcase_04 AC 126 ms
57,124 KB
testcase_05 AC 554 ms
98,448 KB
testcase_06 AC 578 ms
96,736 KB
testcase_07 AC 554 ms
99,760 KB
testcase_08 AC 494 ms
99,240 KB
testcase_09 AC 720 ms
133,976 KB
testcase_10 MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

	void run() {
		Scanner sc = new Scanner(System.in);
		int M = sc.nextInt();
		int N = sc.nextInt();
		long mulX = sc.nextLong();
		long addX = sc.nextLong();
		long mulY = sc.nextLong();
		long addY = sc.nextLong();
		long MOD = sc.nextLong();
		long[] z = new long[(int) MOD];
		long[] x = new long[M];
		long[] y = new long[M];
		long[] a = new long[M];
		long[] b = new long[M];
		for (int i = 0; i < M; ++i) {
			x[i] = sc.nextLong();
		}
		for (int i = 0; i < M; ++i) {
			y[i] = sc.nextLong();
			z[(int) x[i]] += y[i];
		}
		for (int i = 0; i < M; ++i) {
			a[i] = sc.nextLong();
		}
		for (int i = 0; i < M; ++i) {
			b[i] = sc.nextLong();
		}
		long curx = x[M - 1], cury = y[M - 1];
		for (int i = M; i < N; ++i) {
			curx = (curx * mulX + addX) & (MOD - 1);
			cury = (cury * mulY + addY) & (MOD - 1);
			z[(int) curx] += cury;
		}

		boolean[] isPrime = new boolean[(int) MOD];
		Arrays.fill(isPrime, true);
		isPrime[0] = false;
		isPrime[1] = false;
		for (int i = 2; i < isPrime.length; ++i) {
			if (isPrime[i])
				for (int j = 2 * i; j < isPrime.length; j += i)
					isPrime[j] = false;
		}
		for (int i = 2; i < isPrime.length; ++i) {
			if (!isPrime[i])
				continue;
			for (int j = (z.length - 1) / i; j >= 1; --j) {
				z[j] += z[j * i];
			}
		}
		long ans = 0;
		for (int i = 0; i < M; ++i) {
			long v = z2(a[i], z) - z2(a[i] * b[i], z);
			System.out.println(v);
			ans ^= v;
		}
		long cura = a[M - 1] & (MOD - 1), curb = b[M - 1] & (MOD - 1);
		for (int i = M; i < N; ++i) {
			cura = ((((cura * mulX) & (MOD - 1)) + addX + MOD - 1) & (MOD - 1)) + 1;
			curb = ((((curb * mulY) & (MOD - 1)) + addY + MOD - 1) & (MOD - 1)) + 1;
			long v = z2(cura, z) - z2(cura * curb, z);
			ans ^= v;
		}
		System.out.println(ans);
	}

	long z2(long v, long[] z) {
		if (v >= z.length)
			return 0;
		else
			return z[(int) v];
	}

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