結果

問題 No.435 占い(Extra)
ユーザー 37zigen37zigen
提出日時 2016-12-02 18:57:54
言語 Java21
(openjdk 21)
結果
MLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,737 bytes
コンパイル時間 3,394 ms
コンパイル使用メモリ 78,528 KB
実行使用メモリ 65,576 KB
最終ジャッジ日時 2024-10-08 12:19:54
合計ジャッジ時間 13,666 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
36,820 KB
testcase_01 AC 51 ms
36,992 KB
testcase_02 AC 49 ms
37,104 KB
testcase_03 AC 49 ms
37,056 KB
testcase_04 AC 48 ms
37,088 KB
testcase_05 AC 51 ms
37,132 KB
testcase_06 AC 106 ms
39,412 KB
testcase_07 AC 55 ms
36,976 KB
testcase_08 AC 54 ms
36,920 KB
testcase_09 AC 52 ms
36,944 KB
testcase_10 AC 78 ms
37,956 KB
testcase_11 AC 76 ms
38,108 KB
testcase_12 AC 99 ms
38,624 KB
testcase_13 AC 131 ms
41,232 KB
testcase_14 AC 141 ms
41,308 KB
testcase_15 AC 193 ms
42,236 KB
testcase_16 MLE -
testcase_17 MLE -
testcase_18 AC 96 ms
38,700 KB
testcase_19 AC 132 ms
41,588 KB
testcase_20 AC 249 ms
38,416 KB
testcase_21 AC 287 ms
41,316 KB
testcase_22 AC 279 ms
41,828 KB
testcase_23 AC 332 ms
42,684 KB
testcase_24 MLE -
testcase_25 MLE -
testcase_26 AC 243 ms
38,524 KB
testcase_27 AC 280 ms
41,512 KB
testcase_28 AC 47 ms
36,888 KB
testcase_29 AC 277 ms
41,320 KB
testcase_30 AC 246 ms
38,396 KB
testcase_31 AC 246 ms
41,400 KB
testcase_32 AC 265 ms
41,468 KB
testcase_33 AC 444 ms
44,936 KB
testcase_34 MLE -
testcase_35 AC 342 ms
42,300 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Iterator;

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 = Integer.parseInt(sc.next());
			int x = Integer.parseInt(sc.next());
			int a = Integer.parseInt(sc.next());
			int b = Integer.parseInt(sc.next());
			int m = Integer.parseInt(sc.next());
			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();
		sc.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;
	}

	@SuppressWarnings("unused")
	private static class Scanner {
		BufferedReader br;
		Iterator<String> it;

		Scanner(InputStream in) {
			br = new BufferedReader(new InputStreamReader(in));
		}

		String next() throws RuntimeException {
			try {
				if (it == null || !it.hasNext()) {
					it = Arrays.asList(br.readLine().split(" ")).iterator();
				}
				return it.next();
			} catch (IOException e) {
				throw new IllegalStateException();
			}
		}

		int nextInt() throws RuntimeException {
			return Integer.parseInt(next());
		}

		long nextLong() throws RuntimeException {
			return Long.parseLong(next());
		}

		float nextFloat() throws RuntimeException {
			return Float.parseFloat(next());
		}

		double nextDouble() throws RuntimeException {
			return Double.parseDouble(next());
		}

		void close() {
			try {
				br.close();
			} catch (IOException e) {
				// throw new IllegalStateException();
			}
		}
	}

}
0