結果

問題 No.435 占い(Extra)
ユーザー 37zigen37zigen
提出日時 2016-12-02 18:45:00
言語 Java21
(openjdk 21)
結果
MLE  
実行時間 -
コード長 1,508 bytes
コンパイル時間 3,269 ms
コンパイル使用メモリ 77,748 KB
実行使用メモリ 63,760 KB
最終ジャッジ日時 2024-04-17 02:53:57
合計ジャッジ時間 19,557 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
41,312 KB
testcase_01 AC 128 ms
41,420 KB
testcase_02 AC 142 ms
41,552 KB
testcase_03 AC 132 ms
41,580 KB
testcase_04 AC 127 ms
41,224 KB
testcase_05 AC 137 ms
41,288 KB
testcase_06 AC 254 ms
46,284 KB
testcase_07 AC 185 ms
42,284 KB
testcase_08 AC 133 ms
41,392 KB
testcase_09 AC 134 ms
40,596 KB
testcase_10 AC 146 ms
41,380 KB
testcase_11 AC 150 ms
41,164 KB
testcase_12 AC 163 ms
41,124 KB
testcase_13 AC 171 ms
41,392 KB
testcase_14 AC 244 ms
42,296 KB
testcase_15 AC 333 ms
46,120 KB
testcase_16 MLE -
testcase_17 MLE -
testcase_18 AC 145 ms
40,548 KB
testcase_19 AC 169 ms
41,192 KB
testcase_20 AC 300 ms
40,916 KB
testcase_21 AC 327 ms
40,904 KB
testcase_22 AC 404 ms
42,560 KB
testcase_23 AC 552 ms
46,704 KB
testcase_24 MLE -
testcase_25 MLE -
testcase_26 AC 298 ms
40,376 KB
testcase_27 AC 338 ms
41,648 KB
testcase_28 AC 122 ms
40,384 KB
testcase_29 AC 320 ms
41,232 KB
testcase_30 AC 312 ms
41,148 KB
testcase_31 AC 291 ms
41,500 KB
testcase_32 AC 324 ms
41,480 KB
testcase_33 MLE -
testcase_34 MLE -
testcase_35 AC 569 ms
47,720 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;

import java.util.*;

public class Q435 {
	static final int[] inv = new int[] { 0, 1, 5, 0, 7, 2, 0, 4, 8 };

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int T = sc.nextInt();
		while (T-- > 0) {
			int n = sc.nextInt();
			int x = sc.nextInt();
			int a = sc.nextInt();
			int b = sc.nextInt();
			int m = sc.nextInt();
			int reducedCombi = 1;
			int count3 = 0;
			int ans = 0;
			boolean f = true;
			int cur = x;
			for (int i = 0; i < n; ++i) {
				int combi = reducedCombi;
				if (i > 0) {
					cur = next(n, cur, a, b, m);
					reducedCombi = reducedCombi * inv[reduce3(i) % 9] * reduce3(n - 1 - i + 1) % 9;
					count3 = count3 - count3(i) + count3(n - 1 - i + 1);
					if (count3 >= 2) {
						combi = 0;
					} else if (count3 == 1) {
						combi = 3 * reducedCombi % 9;
					} else if (count3 == 0) {
						combi = reducedCombi % 9;
					} else if (count3 < 0) {
						throw new AssertionError();
					}
				}


				ans = (ans + combi * (cur % 10)) % 9;
				if (f)
					if (cur % 10 > 0)
						f = false;
			}
			if (f)
				System.out.println(0);
			else if (!f && ans == 0)
				System.out.println(9);
			else
				System.out.println(ans);
		}
	}

	static int count3(int n) {
		int c = 0;
		while (n > 0 && n % 3 == 0) {
			n /= 3;
			++c;
		}
		return c;
	}

	static int reduce3(int n) {
		while (n > 0 && n % 3 == 0)
			n /= 3;
		return n;
	}

	static int next(int n, int cur, int a, int b, int m) {
		return ((cur ^ a) + b) % m;
	}

}
0