結果

問題 No.435 占い(Extra)
ユーザー 37zigen37zigen
提出日時 2016-12-02 18:46:41
言語 Java21
(openjdk 21)
結果
MLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,577 bytes
コンパイル時間 4,146 ms
コンパイル使用メモリ 76,980 KB
実行使用メモリ 77,216 KB
最終ジャッジ日時 2024-04-17 02:55:20
合計ジャッジ時間 18,284 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 153 ms
41,332 KB
testcase_01 AC 162 ms
41,244 KB
testcase_02 AC 164 ms
41,436 KB
testcase_03 AC 168 ms
41,588 KB
testcase_04 AC 162 ms
41,016 KB
testcase_05 AC 169 ms
41,320 KB
testcase_06 AC 290 ms
45,892 KB
testcase_07 AC 231 ms
42,064 KB
testcase_08 AC 164 ms
41,836 KB
testcase_09 AC 169 ms
41,788 KB
testcase_10 AC 175 ms
41,544 KB
testcase_11 AC 186 ms
41,396 KB
testcase_12 AC 199 ms
41,404 KB
testcase_13 AC 211 ms
42,060 KB
testcase_14 AC 281 ms
42,184 KB
testcase_15 AC 383 ms
46,136 KB
testcase_16 MLE -
testcase_17 MLE -
testcase_18 AC 194 ms
41,172 KB
testcase_19 AC 201 ms
41,580 KB
testcase_20 AC 366 ms
41,424 KB
testcase_21 AC 394 ms
41,352 KB
testcase_22 AC 446 ms
42,316 KB
testcase_23 AC 643 ms
47,332 KB
testcase_24 MLE -
testcase_25 MLE -
testcase_26 AC 370 ms
41,376 KB
testcase_27 AC 413 ms
41,764 KB
testcase_28 AC 164 ms
41,452 KB
testcase_29 AC 402 ms
41,636 KB
testcase_30 AC 355 ms
41,436 KB
testcase_31 AC 604 ms
41,236 KB
testcase_32 AC 792 ms
41,644 KB
testcase_33 MLE -
testcase_34 MLE -
testcase_35 AC 659 ms
47,272 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;

import java.io.PrintWriter;
import java.util.Scanner;

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);
		PrintWriter pw=new PrintWriter(System.out);
		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)
				pw.println(0);
			else if (!f && ans == 0)
				pw.println(9);
			else
				pw.println(ans);
		}
		pw.close();
	}

	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