Submission #58524
Source Code Expand
import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.Random; import java.util.Scanner; public class Main { static Scanner sc = new Scanner(System.in); static int A, B; static long[] table = new long[50]; static long[] pow26 = new long[50]; static HashMap<Integer, String> map = new HashMap<Integer, String>(); static int memoLen = 5; static void memo(char[] buf, int pos, long hash) { if (pos == memoLen) { map.put((int) (hash % B), String.valueOf(buf)); return; } for (int i = 0; i < 26; ++i) { buf[pos] = (char) (i + 'a'); memo(buf, pos + 1, (hash + table[pos + 1] * (i + 1))); } } public static void main(String[] args) { A = sc.nextInt(); B = sc.nextInt(); table[0] = 1; for (int i = 1; i < table.length; ++i) { table[i] = table[i - 1] * A % B; } { char[] buf = new char[memoLen]; memo(buf, 0, 0); } pow26[1] = 1; for (int i = 1; i < pow26.length - 1; ++i) { pow26[i + 1] = pow26[i] * 26; } HashSet<String> ans = new HashSet<String>(); Random rand = new Random(); char[] buf = new char[20]; while (ans.size() < 100) { long hash = 0; for (int i = 0; i < buf.length; ++i) { int v = rand.nextInt(26); hash += (v + 1) * table[i + memoLen + 1]; hash %= B; buf[i] = (char) (v + 'a'); } for (int i = 1; i <= 26; ++i) { int key = (int) (B - hash - i); if (key < 0) key += B; if (map.containsKey(key)) { String suf = map.get(key); ans.add(String.valueOf(buf) + suf + (char) (i - 1 + 'a')); System.out.println(String.valueOf(buf) + suf + (char) (i - 1 + 'a')); if (ans.size() == 100) break; } } } for (String s : ans) { // System.out.println(hash(s)); System.out.println(s); } } static int hash(String s) { long h = 0; for (int i = 0; i < s.length(); ++i) { h = (h * A + (s.charAt(i) - 'a' + 1)) % B; } return (int) h; } static String suffix(long hash) { ArrayList<Integer> digit = new ArrayList<Integer>(); ArrayList<Character> list = new ArrayList<Character>(); while (hash > 0) { digit.add((int) (hash % 26)); hash /= 26; } for (int i = 0; i < digit.size(); ++i) { if (digit.get(i) == 0) { int pos = i + 1; while (pos < digit.size() && digit.get(pos) == 0) { ++pos; } if (pos == digit.size()) break; for (int j = i; j < pos; ++j) { digit.set(j, 26); } digit.set(pos, digit.get(pos) - 1); } list.add((char) (digit.get(i) - 1 + 'a')); } StringBuilder ret = new StringBuilder(); for (int i = 0; i < list.size(); ++i) { ret.append(list.get(list.size() - 1 - i)); } return ret.toString(); } }
Submission Info
Submission Time | |
---|---|
Task | F - Uinny |
User | tomerun |
Language | Java (OpenJDK 1.7.0) |
Score | 0 |
Code Size | 2783 Byte |
Status | TLE |
Exec Time | 2596 ms |
Memory | 162076 KB |
Judge Result
Set Name | 010_01 | 010_02 | 010_03 | 010_04 | 010_05 | 010_06 | 010_07 | 010_08 | 010_09 | 010_10 | 010_11 | 010_12 | 010_13 | 010_14 | 010_15 | 010_16 | 010_17 | 010_18 | 010_19 | 010_20 | 010_21 | 010_22 | 010_23 | 010_24 | 010_25 | 010_26 | 010_27 | 010_28 | 010_29 | 010_30 | 010_31 | 010_32 | 010_33 | 010_34 | 010_35 | 010_36 | 010_37 | 010_38 | 010_39 | 010_40 | 010_41 | 010_42 | 010_43 | 010_44 | 010_45 | 010_46 | 010_47 | 010_48 | 010_49 | 010_50 | 010_51 | 010_52 | 010_53 | 010_54 | 010_55 | 010_56 | 010_57 | 010_58 | 010_59 | 010_60 | 010_61 | 010_62 | 010_63 | 010_64 | 010_65 | 010_66 | 010_67 | 010_68 | 010_69 | 010_70 | 010_71 | 010_72 | 010_73 | 010_74 | 010_75 | 010_76 | 010_77 | 010_78 | 010_79 | 010_80 | 010_81 | 010_82 | 010_83 | 010_84 | 010_85 | 010_86 | 010_87 | 010_88 | 010_89 | 010_90 | 010_91 | 010_92 | 010_93 | 010_94 | 010_95 | 010_96 | 010_97 | 010_98 | 010_99 | sample | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | 0 / 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Status |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Set Name | Test Cases |
---|---|
010_01 | 010_01.txt |
010_02 | 010_02.txt |
010_03 | 010_03.txt |
010_04 | 010_04.txt |
010_05 | 010_05.txt |
010_06 | 010_06.txt |
010_07 | 010_07.txt |
010_08 | 010_08.txt |
010_09 | 010_09.txt |
010_10 | 010_10.txt |
010_11 | 010_11.txt |
010_12 | 010_12.txt |
010_13 | 010_13.txt |
010_14 | 010_14.txt |
010_15 | 010_15.txt |
010_16 | 010_16.txt |
010_17 | 010_17.txt |
010_18 | 010_18.txt |
010_19 | 010_19.txt |
010_20 | 010_20.txt |
010_21 | 010_21.txt |
010_22 | 010_22.txt |
010_23 | 010_23.txt |
010_24 | 010_24.txt |
010_25 | 010_25.txt |
010_26 | 010_26.txt |
010_27 | 010_27.txt |
010_28 | 010_28.txt |
010_29 | 010_29.txt |
010_30 | 010_30.txt |
010_31 | 010_31.txt |
010_32 | 010_32.txt |
010_33 | 010_33.txt |
010_34 | 010_34.txt |
010_35 | 010_35.txt |
010_36 | 010_36.txt |
010_37 | 010_37.txt |
010_38 | 010_38.txt |
010_39 | 010_39.txt |
010_40 | 010_40.txt |
010_41 | 010_41.txt |
010_42 | 010_42.txt |
010_43 | 010_43.txt |
010_44 | 010_44.txt |
010_45 | 010_45.txt |
010_46 | 010_46.txt |
010_47 | 010_47.txt |
010_48 | 010_48.txt |
010_49 | 010_49.txt |
010_50 | 010_50.txt |
010_51 | 010_51.txt |
010_52 | 010_52.txt |
010_53 | 010_53.txt |
010_54 | 010_54.txt |
010_55 | 010_55.txt |
010_56 | 010_56.txt |
010_57 | 010_57.txt |
010_58 | 010_58.txt |
010_59 | 010_59.txt |
010_60 | 010_60.txt |
010_61 | 010_61.txt |
010_62 | 010_62.txt |
010_63 | 010_63.txt |
010_64 | 010_64.txt |
010_65 | 010_65.txt |
010_66 | 010_66.txt |
010_67 | 010_67.txt |
010_68 | 010_68.txt |
010_69 | 010_69.txt |
010_70 | 010_70.txt |
010_71 | 010_71.txt |
010_72 | 010_72.txt |
010_73 | 010_73.txt |
010_74 | 010_74.txt |
010_75 | 010_75.txt |
010_76 | 010_76.txt |
010_77 | 010_77.txt |
010_78 | 010_78.txt |
010_79 | 010_79.txt |
010_80 | 010_80.txt |
010_81 | 010_81.txt |
010_82 | 010_82.txt |
010_83 | 010_83.txt |
010_84 | 010_84.txt |
010_85 | 010_85.txt |
010_86 | 010_86.txt |
010_87 | 010_87.txt |
010_88 | 010_88.txt |
010_89 | 010_89.txt |
010_90 | 010_90.txt |
010_91 | 010_91.txt |
010_92 | 010_92.txt |
010_93 | 010_93.txt |
010_94 | 010_94.txt |
010_95 | 010_95.txt |
010_96 | 010_96.txt |
010_97 | 010_97.txt |
010_98 | 010_98.txt |
010_99 | 010_99.txt |
sample | sample.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
010_01.txt | TLE | 2508 ms | 161312 KB |
010_02.txt | TLE | 2309 ms | 161360 KB |
010_03.txt | TLE | 2391 ms | 161812 KB |
010_04.txt | TLE | 2397 ms | 161660 KB |
010_05.txt | TLE | 2436 ms | 161700 KB |
010_06.txt | TLE | 2291 ms | 161732 KB |
010_07.txt | TLE | 2323 ms | 161492 KB |
010_08.txt | TLE | 2421 ms | 161628 KB |
010_09.txt | TLE | 2355 ms | 161376 KB |
010_10.txt | TLE | 2468 ms | 161372 KB |
010_11.txt | TLE | 2403 ms | 161752 KB |
010_12.txt | TLE | 2336 ms | 161264 KB |
010_13.txt | TLE | 2341 ms | 161456 KB |
010_14.txt | TLE | 2363 ms | 154560 KB |
010_15.txt | TLE | 2315 ms | 161624 KB |
010_16.txt | TLE | 2373 ms | 161708 KB |
010_17.txt | TLE | 2345 ms | 161172 KB |
010_18.txt | TLE | 2347 ms | 161636 KB |
010_19.txt | TLE | 2376 ms | 161376 KB |
010_20.txt | TLE | 2356 ms | 155220 KB |
010_21.txt | TLE | 2352 ms | 161752 KB |
010_22.txt | TLE | 2240 ms | 88304 KB |
010_23.txt | TLE | 2452 ms | 161552 KB |
010_24.txt | TLE | 2407 ms | 160884 KB |
010_25.txt | TLE | 2437 ms | 161824 KB |
010_26.txt | TLE | 2421 ms | 161728 KB |
010_27.txt | TLE | 2411 ms | 161380 KB |
010_28.txt | TLE | 2453 ms | 161216 KB |
010_29.txt | TLE | 2430 ms | 161480 KB |
010_30.txt | TLE | 2477 ms | 161632 KB |
010_31.txt | TLE | 2408 ms | 161696 KB |
010_32.txt | TLE | 2335 ms | 161584 KB |
010_33.txt | TLE | 2486 ms | 161560 KB |
010_34.txt | TLE | 2436 ms | 161676 KB |
010_35.txt | TLE | 2377 ms | 161292 KB |
010_36.txt | TLE | 2460 ms | 161552 KB |
010_37.txt | TLE | 2410 ms | 161432 KB |
010_38.txt | TLE | 2552 ms | 161624 KB |
010_39.txt | TLE | 2397 ms | 161548 KB |
010_40.txt | TLE | 2405 ms | 162076 KB |
010_41.txt | TLE | 2456 ms | 161768 KB |
010_42.txt | TLE | 2367 ms | 161940 KB |
010_43.txt | TLE | 2406 ms | 161620 KB |
010_44.txt | TLE | 2335 ms | 161540 KB |
010_45.txt | TLE | 2255 ms | 153332 KB |
010_46.txt | TLE | 2371 ms | 161852 KB |
010_47.txt | TLE | 2372 ms | 161044 KB |
010_48.txt | TLE | 2398 ms | 161544 KB |
010_49.txt | TLE | 2428 ms | 155496 KB |
010_50.txt | TLE | 2342 ms | 161488 KB |
010_51.txt | TLE | 2397 ms | 161628 KB |
010_52.txt | TLE | 2316 ms | 161256 KB |
010_53.txt | TLE | 2476 ms | 161372 KB |
010_54.txt | TLE | 2350 ms | 161396 KB |
010_55.txt | TLE | 2401 ms | 161500 KB |
010_56.txt | TLE | 2363 ms | 161632 KB |
010_57.txt | TLE | 2401 ms | 161584 KB |
010_58.txt | TLE | 2385 ms | 161948 KB |
010_59.txt | TLE | 2366 ms | 161612 KB |
010_60.txt | TLE | 2343 ms | 161244 KB |
010_61.txt | TLE | 2421 ms | 161340 KB |
010_62.txt | TLE | 2307 ms | 161324 KB |
010_63.txt | TLE | 2427 ms | 161548 KB |
010_64.txt | TLE | 2394 ms | 161492 KB |
010_65.txt | TLE | 2393 ms | 161260 KB |
010_66.txt | TLE | 2438 ms | 161504 KB |
010_67.txt | TLE | 2400 ms | 161272 KB |
010_68.txt | TLE | 2457 ms | 162008 KB |
010_69.txt | TLE | 2449 ms | 161368 KB |
010_70.txt | TLE | 2454 ms | 161648 KB |
010_71.txt | TLE | 2495 ms | 161700 KB |
010_72.txt | TLE | 2338 ms | 161508 KB |
010_73.txt | TLE | 2469 ms | 156840 KB |
010_74.txt | TLE | 2405 ms | 161516 KB |
010_75.txt | TLE | 2325 ms | 161248 KB |
010_76.txt | TLE | 2417 ms | 161380 KB |
010_77.txt | TLE | 2489 ms | 161760 KB |
010_78.txt | TLE | 2404 ms | 161424 KB |
010_79.txt | TLE | 2545 ms | 161812 KB |
010_80.txt | TLE | 2596 ms | 161636 KB |
010_81.txt | TLE | 2562 ms | 161500 KB |
010_82.txt | TLE | 2437 ms | 161616 KB |
010_83.txt | TLE | 2405 ms | 161248 KB |
010_84.txt | TLE | 2481 ms | 161812 KB |
010_85.txt | TLE | 2485 ms | 161244 KB |
010_86.txt | TLE | 2464 ms | 161684 KB |
010_87.txt | TLE | 2395 ms | 161380 KB |
010_88.txt | TLE | 2539 ms | 162032 KB |
010_89.txt | TLE | 2376 ms | 161288 KB |
010_90.txt | TLE | 2420 ms | 161844 KB |
010_91.txt | TLE | 2455 ms | 161780 KB |
010_92.txt | TLE | 2469 ms | 161252 KB |
010_93.txt | TLE | 2376 ms | 161928 KB |
010_94.txt | TLE | 2439 ms | 161608 KB |
010_95.txt | TLE | 2443 ms | 161668 KB |
010_96.txt | TLE | 2438 ms | 156116 KB |
010_97.txt | TLE | 2400 ms | 161536 KB |
010_98.txt | TLE | 2363 ms | 161272 KB |
010_99.txt | TLE | 2413 ms | 159880 KB |
sample.txt | AC | 1337 ms | 31496 KB |