Submission #59238
Source Code Expand
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 HashMap<Integer, String> map = new HashMap<Integer, String>(); static int memoLen = 4; static void memo(char[] buf, int pos, long hash) { if (pos == memoLen) { // System.out.println(hash + " " + (long)hash(String.valueOf(buf)) * A % B); map.put((int) hash, String.valueOf(buf)); return; } for (int i = 0; i < 26; ++i) { buf[pos] = (char) (i + 'a'); memo(buf, pos + 1, (hash + table[memoLen - pos] * (i + 1)) % B); } } 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); } HashSet<String> ans = new HashSet<String>(); Random rand = new Random(); char[] buf = new char[40]; 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[buf.length - 1 - i] = (char) (v + 'a'); } // System.out.println(hash + " " + (long) hash(String.valueOf(buf)) * table[memoLen + 1] % B); for (int i = 1; i <= 26; ++i) { int key = (int) (B + 1 - hash - i); if (key < 0) key += B; if (key >= B) key -= B; if (map.containsKey(key)) { String suf = map.get(key); ans.add(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; } }
Submission Info
Submission Time | |
---|---|
Task | F - Uinny |
User | tomerun |
Language | Java (OpenJDK 1.7.0) |
Score | 198 |
Code Size | 2091 Byte |
Status | AC |
Exec Time | 1817 ms |
Memory | 95588 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 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 0 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 2 | 2 / 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 | 1356 ms | 81936 KB |
010_02.txt | AC | 1349 ms | 82000 KB |
010_03.txt | AC | 1288 ms | 82508 KB |
010_04.txt | AC | 1372 ms | 81932 KB |
010_05.txt | AC | 1346 ms | 82300 KB |
010_06.txt | AC | 1281 ms | 82416 KB |
010_07.txt | AC | 1338 ms | 82388 KB |
010_08.txt | AC | 1321 ms | 82556 KB |
010_09.txt | AC | 1384 ms | 81648 KB |
010_10.txt | AC | 1279 ms | 82560 KB |
010_11.txt | AC | 1291 ms | 82500 KB |
010_12.txt | AC | 1300 ms | 82344 KB |
010_13.txt | AC | 1260 ms | 82048 KB |
010_14.txt | AC | 1817 ms | 95588 KB |
010_15.txt | AC | 1341 ms | 81780 KB |
010_16.txt | AC | 1285 ms | 82140 KB |
010_17.txt | AC | 1310 ms | 82756 KB |
010_18.txt | AC | 1294 ms | 82120 KB |
010_19.txt | AC | 1310 ms | 81916 KB |
010_20.txt | AC | 1386 ms | 83480 KB |
010_21.txt | AC | 1419 ms | 82676 KB |
010_22.txt | AC | 1346 ms | 81988 KB |
010_23.txt | AC | 1347 ms | 82600 KB |
010_24.txt | AC | 1370 ms | 83172 KB |
010_25.txt | AC | 1345 ms | 82076 KB |
010_26.txt | AC | 1275 ms | 82348 KB |
010_27.txt | AC | 1270 ms | 82252 KB |
010_28.txt | AC | 1313 ms | 81752 KB |
010_29.txt | AC | 1329 ms | 81804 KB |
010_30.txt | AC | 1334 ms | 82320 KB |
010_31.txt | AC | 1294 ms | 82276 KB |
010_32.txt | AC | 1296 ms | 81732 KB |
010_33.txt | AC | 1348 ms | 82820 KB |
010_34.txt | AC | 1309 ms | 82356 KB |
010_35.txt | AC | 1278 ms | 83376 KB |
010_36.txt | AC | 1315 ms | 82500 KB |
010_37.txt | AC | 1209 ms | 82068 KB |
010_38.txt | AC | 1309 ms | 82640 KB |
010_39.txt | AC | 1304 ms | 81772 KB |
010_40.txt | AC | 1215 ms | 82024 KB |
010_41.txt | AC | 1297 ms | 82188 KB |
010_42.txt | AC | 1296 ms | 81660 KB |
010_43.txt | AC | 1265 ms | 82472 KB |
010_44.txt | AC | 1302 ms | 82136 KB |
010_45.txt | AC | 1274 ms | 82452 KB |
010_46.txt | AC | 1380 ms | 83228 KB |
010_47.txt | AC | 1317 ms | 82220 KB |
010_48.txt | AC | 1260 ms | 81976 KB |
010_49.txt | AC | 1338 ms | 83020 KB |
010_50.txt | AC | 1343 ms | 81928 KB |
010_51.txt | AC | 1271 ms | 81764 KB |
010_52.txt | AC | 1328 ms | 82276 KB |
010_53.txt | AC | 1234 ms | 81704 KB |
010_54.txt | AC | 1324 ms | 81652 KB |
010_55.txt | AC | 1249 ms | 81932 KB |
010_56.txt | AC | 1306 ms | 82300 KB |
010_57.txt | AC | 1341 ms | 82224 KB |
010_58.txt | AC | 1300 ms | 81956 KB |
010_59.txt | AC | 1297 ms | 82404 KB |
010_60.txt | AC | 1320 ms | 82684 KB |
010_61.txt | AC | 1298 ms | 82496 KB |
010_62.txt | AC | 1361 ms | 82684 KB |
010_63.txt | AC | 1324 ms | 82044 KB |
010_64.txt | AC | 1361 ms | 82224 KB |
010_65.txt | AC | 1340 ms | 82284 KB |
010_66.txt | AC | 1302 ms | 82180 KB |
010_67.txt | AC | 1249 ms | 82280 KB |
010_68.txt | AC | 1287 ms | 82536 KB |
010_69.txt | AC | 1279 ms | 82584 KB |
010_70.txt | AC | 1318 ms | 82632 KB |
010_71.txt | AC | 1240 ms | 81772 KB |
010_72.txt | AC | 1311 ms | 82480 KB |
010_73.txt | AC | 1253 ms | 82596 KB |
010_74.txt | AC | 1342 ms | 82116 KB |
010_75.txt | AC | 1274 ms | 80588 KB |
010_76.txt | AC | 1292 ms | 82528 KB |
010_77.txt | AC | 1293 ms | 82168 KB |
010_78.txt | AC | 1311 ms | 83384 KB |
010_79.txt | AC | 1313 ms | 82240 KB |
010_80.txt | AC | 1279 ms | 82016 KB |
010_81.txt | AC | 1287 ms | 82400 KB |
010_82.txt | AC | 1367 ms | 82276 KB |
010_83.txt | AC | 1324 ms | 82420 KB |
010_84.txt | AC | 1281 ms | 82012 KB |
010_85.txt | AC | 1409 ms | 82740 KB |
010_86.txt | AC | 1294 ms | 82836 KB |
010_87.txt | AC | 1370 ms | 82756 KB |
010_88.txt | AC | 1360 ms | 82476 KB |
010_89.txt | AC | 1289 ms | 82468 KB |
010_90.txt | AC | 1323 ms | 82304 KB |
010_91.txt | AC | 1282 ms | 82472 KB |
010_92.txt | AC | 1282 ms | 82272 KB |
010_93.txt | AC | 1354 ms | 82272 KB |
010_94.txt | AC | 1338 ms | 82540 KB |
010_95.txt | AC | 1240 ms | 82084 KB |
010_96.txt | AC | 1332 ms | 82512 KB |
010_97.txt | AC | 1310 ms | 81976 KB |
010_98.txt | AC | 1319 ms | 82228 KB |
010_99.txt | AC | 1291 ms | 81512 KB |
sample.txt | AC | 526 ms | 29632 KB |