Submission #58560
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 = 4; 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) { long start = System.currentTimeMillis(); 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 && System.currentTimeMillis() - start < 1400) { 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 | 2875 Byte |
Status | AC |
Exec Time | 1908 ms |
Memory | 109940 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 | AC | 1309 ms | 83720 KB |
010_02.txt | AC | 1432 ms | 83208 KB |
010_03.txt | AC | 1360 ms | 82948 KB |
010_04.txt | AC | 1340 ms | 83168 KB |
010_05.txt | AC | 1369 ms | 84292 KB |
010_06.txt | AC | 1352 ms | 83032 KB |
010_07.txt | AC | 1421 ms | 83452 KB |
010_08.txt | AC | 1317 ms | 82884 KB |
010_09.txt | AC | 1389 ms | 83676 KB |
010_10.txt | AC | 1908 ms | 109940 KB |
010_11.txt | AC | 1346 ms | 83216 KB |
010_12.txt | AC | 1313 ms | 82888 KB |
010_13.txt | AC | 1381 ms | 83616 KB |
010_14.txt | AC | 1845 ms | 98072 KB |
010_15.txt | AC | 1409 ms | 83356 KB |
010_16.txt | AC | 1341 ms | 83592 KB |
010_17.txt | AC | 1330 ms | 83584 KB |
010_18.txt | AC | 1432 ms | 83684 KB |
010_19.txt | AC | 1442 ms | 83496 KB |
010_20.txt | AC | 1353 ms | 85200 KB |
010_21.txt | AC | 1299 ms | 83136 KB |
010_22.txt | AC | 1838 ms | 93204 KB |
010_23.txt | AC | 1276 ms | 83000 KB |
010_24.txt | AC | 1412 ms | 83252 KB |
010_25.txt | AC | 1330 ms | 83576 KB |
010_26.txt | AC | 1338 ms | 83700 KB |
010_27.txt | AC | 1369 ms | 83396 KB |
010_28.txt | AC | 1334 ms | 82876 KB |
010_29.txt | AC | 1341 ms | 83440 KB |
010_30.txt | AC | 1290 ms | 83080 KB |
010_31.txt | AC | 1314 ms | 83084 KB |
010_32.txt | AC | 1360 ms | 83224 KB |
010_33.txt | AC | 1352 ms | 83044 KB |
010_34.txt | AC | 1409 ms | 83720 KB |
010_35.txt | AC | 1463 ms | 84028 KB |
010_36.txt | AC | 1475 ms | 83192 KB |
010_37.txt | AC | 1322 ms | 83052 KB |
010_38.txt | AC | 1377 ms | 83180 KB |
010_39.txt | AC | 1354 ms | 82864 KB |
010_40.txt | AC | 1329 ms | 83512 KB |
010_41.txt | AC | 1331 ms | 83164 KB |
010_42.txt | AC | 1349 ms | 83224 KB |
010_43.txt | AC | 1329 ms | 82524 KB |
010_44.txt | AC | 1410 ms | 83664 KB |
010_45.txt | AC | 1426 ms | 84028 KB |
010_46.txt | AC | 1425 ms | 83372 KB |
010_47.txt | AC | 1423 ms | 84300 KB |
010_48.txt | AC | 1337 ms | 83132 KB |
010_49.txt | AC | 1382 ms | 85484 KB |
010_50.txt | AC | 1396 ms | 82984 KB |
010_51.txt | AC | 1259 ms | 83544 KB |
010_52.txt | AC | 1389 ms | 82940 KB |
010_53.txt | AC | 1322 ms | 83536 KB |
010_54.txt | AC | 1381 ms | 83080 KB |
010_55.txt | AC | 1419 ms | 83968 KB |
010_56.txt | AC | 1437 ms | 83004 KB |
010_57.txt | AC | 1376 ms | 83740 KB |
010_58.txt | AC | 1361 ms | 82936 KB |
010_59.txt | AC | 1309 ms | 83788 KB |
010_60.txt | AC | 1368 ms | 83764 KB |
010_61.txt | AC | 1362 ms | 83596 KB |
010_62.txt | AC | 1432 ms | 83020 KB |
010_63.txt | AC | 1399 ms | 83556 KB |
010_64.txt | AC | 1390 ms | 83188 KB |
010_65.txt | AC | 1436 ms | 83536 KB |
010_66.txt | AC | 1415 ms | 82924 KB |
010_67.txt | AC | 1375 ms | 82708 KB |
010_68.txt | AC | 1358 ms | 83072 KB |
010_69.txt | AC | 1345 ms | 83700 KB |
010_70.txt | AC | 1329 ms | 83160 KB |
010_71.txt | AC | 1358 ms | 82988 KB |
010_72.txt | AC | 1380 ms | 83636 KB |
010_73.txt | AC | 1875 ms | 109576 KB |
010_74.txt | AC | 1411 ms | 82984 KB |
010_75.txt | AC | 1333 ms | 82864 KB |
010_76.txt | AC | 1369 ms | 82968 KB |
010_77.txt | AC | 1341 ms | 83260 KB |
010_78.txt | AC | 1375 ms | 83204 KB |
010_79.txt | AC | 1336 ms | 83020 KB |
010_80.txt | AC | 1349 ms | 82852 KB |
010_81.txt | AC | 1424 ms | 83912 KB |
010_82.txt | AC | 1453 ms | 83872 KB |
010_83.txt | AC | 1429 ms | 83308 KB |
010_84.txt | AC | 1346 ms | 83164 KB |
010_85.txt | AC | 1488 ms | 84100 KB |
010_86.txt | AC | 1261 ms | 83164 KB |
010_87.txt | AC | 1395 ms | 82972 KB |
010_88.txt | AC | 1293 ms | 83684 KB |
010_89.txt | AC | 1375 ms | 83100 KB |
010_90.txt | AC | 1346 ms | 83680 KB |
010_91.txt | AC | 1411 ms | 83620 KB |
010_92.txt | AC | 1397 ms | 82840 KB |
010_93.txt | AC | 1365 ms | 84076 KB |
010_94.txt | AC | 1383 ms | 83004 KB |
010_95.txt | AC | 1269 ms | 82496 KB |
010_96.txt | AC | 1861 ms | 109720 KB |
010_97.txt | AC | 1311 ms | 83132 KB |
010_98.txt | AC | 1396 ms | 83808 KB |
010_99.txt | AC | 1365 ms | 83052 KB |
sample.txt | AC | 608 ms | 30936 KB |