結果

問題 No.3015 アンチローリングハッシュ
ユーザー GrenacheGrenache
提出日時 2017-02-22 21:30:54
言語 Java21
(openjdk 21)
結果
AC  
実行時間 281 ms / 2,000 ms
コード長 1,805 bytes
コンパイル時間 4,704 ms
コンパイル使用メモリ 76,496 KB
実行使用メモリ 65,764 KB
最終ジャッジ日時 2023-08-29 01:31:50
合計ジャッジ時間 9,867 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
55,952 KB
testcase_01 AC 123 ms
56,128 KB
testcase_02 AC 121 ms
56,084 KB
testcase_03 AC 122 ms
56,288 KB
testcase_04 AC 122 ms
56,040 KB
testcase_05 AC 121 ms
56,296 KB
testcase_06 AC 134 ms
55,872 KB
testcase_07 AC 121 ms
55,760 KB
testcase_08 AC 123 ms
56,160 KB
testcase_09 AC 134 ms
56,044 KB
testcase_10 AC 144 ms
56,608 KB
testcase_11 AC 191 ms
58,032 KB
testcase_12 AC 122 ms
56,176 KB
testcase_13 AC 119 ms
55,892 KB
testcase_14 AC 123 ms
56,076 KB
testcase_15 AC 131 ms
56,224 KB
testcase_16 AC 122 ms
56,320 KB
testcase_17 AC 161 ms
56,136 KB
testcase_18 AC 281 ms
65,764 KB
testcase_19 AC 280 ms
64,888 KB
testcase_20 AC 276 ms
65,424 KB
testcase_21 AC 213 ms
58,740 KB
testcase_22 AC 122 ms
55,816 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;



public class Main_yukicoder3015 {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int a = sc.nextInt();
		int b = sc.nextInt();

		long hash = 1;
		TreeSet<Pair> hs = new TreeSet<>();
		for (int i = 0; i < 1_000_000; i++) {
			Pair tmp = new Pair(hash, i);
			hs.add(tmp);

			Pair l = hs.lower(tmp);
			if (l != null && l.a == tmp.a) {
//				pr.printf("%d %d\n", a, b);
//				pr.println(l);
//				pr.println(tmp);

				StringBuilder ret1 = new StringBuilder();
				for (int j = 0; j <= i; j++) {
					ret1.append('a');
				}
				StringBuilder ret2 = new StringBuilder(ret1);
				ret1.setCharAt(i - l.b, 'b');
				ret2.setCharAt(i - tmp.b, 'b');

				pr.println(ret1);
				pr.println(ret2);
				break;
			}

			hash *= a;
			hash %= b;
		}

	}

	private static class Pair implements Comparable<Pair> {
		long a;
		int b;

		Pair(long a, int b) {
			this.a = a;
			this.b = b;
		}

		@Override
		public int compareTo(Pair o) {
			if (a == o.a) {
				return Integer.compare(b, o.b);
			}
			return Long.compare(a, o.a);
		}

		@Override
		public int hashCode() {
			return Long.hashCode(a);
		}

		@Override
		public boolean equals(Object obj) {
			return a == ((Pair)obj).a && b == ((Pair)obj).b;
//			return a == ((Pair)obj).a;
		}

		@Override
		public String toString() {
			StringBuilder ret = new StringBuilder();

			ret.append(a);
			ret.append(',');
			ret.append(b);

			return ret.toString();
		}
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}
0