CSES - Aalto Competitive Programming 2024 - wk11 - Wed - Results
Submission details
Task:Hacking hashes
Sender:aalto2024l_005
Submission time:2024-11-20 17:35:51 +0200
Language:C++ (C++17)
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#2ACCEPTED0.00 sdetails
#3ACCEPTED0.00 sdetails
#4ACCEPTED0.00 sdetails
#5ACCEPTED0.00 sdetails
#6ACCEPTED0.00 sdetails
#7ACCEPTED0.00 sdetails
#8ACCEPTED0.00 sdetails
#9ACCEPTED0.00 sdetails
#10ACCEPTED0.00 sdetails
#11ACCEPTED0.00 sdetails
#12ACCEPTED0.00 sdetails
#13ACCEPTED0.00 sdetails
#14ACCEPTED0.00 sdetails
#15ACCEPTED0.00 sdetails
#16ACCEPTED0.00 sdetails
#17ACCEPTED0.00 sdetails
#18ACCEPTED0.00 sdetails
#19ACCEPTED0.00 sdetails
#20ACCEPTED0.00 sdetails
#21ACCEPTED0.00 sdetails
#22ACCEPTED0.00 sdetails
#23ACCEPTED0.00 sdetails
#24ACCEPTED0.00 sdetails
#25ACCEPTED0.00 sdetails
#26ACCEPTED0.00 sdetails
#27ACCEPTED0.00 sdetails
#28ACCEPTED0.00 sdetails
#29ACCEPTED0.00 sdetails
#30ACCEPTED0.00 sdetails
#31ACCEPTED0.00 sdetails
#32ACCEPTED0.00 sdetails
#33ACCEPTED0.00 sdetails
#34ACCEPTED0.00 sdetails
#35ACCEPTED0.00 sdetails
#36ACCEPTED0.00 sdetails
#37ACCEPTED0.00 sdetails
#38ACCEPTED0.00 sdetails
#39ACCEPTED0.00 sdetails
#40ACCEPTED0.00 sdetails
#41ACCEPTED0.00 sdetails
#42ACCEPTED0.00 sdetails
#43ACCEPTED0.00 sdetails
#44ACCEPTED0.00 sdetails
#45ACCEPTED0.00 sdetails
#46ACCEPTED0.00 sdetails
#47ACCEPTED0.00 sdetails
#48ACCEPTED0.00 sdetails
#49ACCEPTED0.00 sdetails
#50ACCEPTED0.00 sdetails
#51ACCEPTED0.00 sdetails
#52ACCEPTED0.00 sdetails
#53ACCEPTED0.00 sdetails
#54ACCEPTED0.00 sdetails
#55ACCEPTED0.00 sdetails
#56ACCEPTED0.00 sdetails
#57ACCEPTED0.00 sdetails
#58ACCEPTED0.00 sdetails
#59ACCEPTED0.00 sdetails
#60ACCEPTED0.00 sdetails
#61ACCEPTED0.01 sdetails
#62ACCEPTED0.01 sdetails
#63ACCEPTED0.01 sdetails
#64ACCEPTED0.00 sdetails
#65ACCEPTED0.01 sdetails
#66ACCEPTED0.01 sdetails
#67ACCEPTED0.01 sdetails
#68ACCEPTED0.01 sdetails
#69ACCEPTED0.00 sdetails
#70ACCEPTED0.00 sdetails
#71ACCEPTED0.01 sdetails
#72ACCEPTED0.01 sdetails
#73ACCEPTED0.01 sdetails
#74ACCEPTED0.01 sdetails
#75ACCEPTED0.01 sdetails
#76ACCEPTED0.01 sdetails
#77ACCEPTED0.01 sdetails
#78ACCEPTED0.01 sdetails
#79ACCEPTED0.00 sdetails
#80ACCEPTED0.01 sdetails
#81ACCEPTED0.02 sdetails
#82ACCEPTED0.01 sdetails
#83ACCEPTED0.02 sdetails
#84ACCEPTED0.01 sdetails
#85ACCEPTED0.01 sdetails
#86ACCEPTED0.02 sdetails
#87ACCEPTED0.02 sdetails
#88ACCEPTED0.01 sdetails
#89ACCEPTED0.01 sdetails
#90ACCEPTED0.01 sdetails

Code

#include <iostream>
#include <unordered_map>
#include <string>
#include <random>
#include <chrono>

using namespace std;

typedef long long ll;

ll A, B;

ll compute_hash(const string& s) {
    ll h = 0;
    for (char c : s) {
        h = (h * A + c) % B;
    }
    return h;
}

string generate_random_string(int L, mt19937& rng) {
    string s;
    uniform_int_distribution<int> dist('a', 'z');
    for (int i = 0; i < L; ++i) {
        char c = dist(rng);
        s += c;
    }
    return s;
}

int main() {

    cin >> A >> B;

    unordered_map<ll, string> hash_map;
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

    int max_attempts = 500000;
    int string_length = 10;

    for (int attempt = 0; attempt < max_attempts; ++attempt) {
        string s = generate_random_string(string_length, rng);
        ll h = compute_hash(s);

        if (hash_map.count(h)) {
            string t = hash_map[h];
            if (s != t) {
                cout << s << " " << t << endl;
                return 0;
            }
        } else {
            hash_map[h] = s;
        }
    }

    string s1 = generate_random_string(string_length, rng);
    string s2 = generate_random_string(string_length, rng);
    while (s1 == s2) {
        s2 = generate_random_string(string_length, rng);
    }
    cout << s1 << " " << s2 << endl;

    return 0;
}

Test details

Test 1

Verdict: ACCEPTED

input
6 6

correct output
dxvdzxfqi oheo

user output
rbiosdypit guoigjdnth

Test 2

Verdict: ACCEPTED

input
5 10

correct output
yzzzeszzyc uuhdakc

user output
mjtazasloq yvwcespacq

Test 3

Verdict: ACCEPTED

input
5 2

correct output
oheo yzzzeszzyc

user output
jidxjyzqhs ctadnruaoy

Test 4

Verdict: ACCEPTED

input
6 1

correct output
dxvdzxfqi oheo

user output
kucdadetfz kjmpqrlzpq

Test 5

Verdict: ACCEPTED

input
10 10

correct output
yzzzeszzyc uuhdakc

user output
siuvsnrkac plofaraibw

Test 6

Verdict: ACCEPTED

input
3 1

correct output
dxvdzxfqi oheo

user output
hdbenlqfnv jywmaacrrc

Test 7

Verdict: ACCEPTED

input
9 10

correct output
oheo yzzzeszzyc

user output
sxxbbmopwl qvdjlvztaj

Test 8

Verdict: ACCEPTED

input
1 3

correct output
dxvdzxfqi oheo

user output
ophjrlqszz xwvuccyavt

Test 9

Verdict: ACCEPTED

input
9 1

correct output
dxvdzxfqi oheo

user output
jvbimcutbw chmixcddrl

Test 10

Verdict: ACCEPTED

input
1 4

correct output
oheo yzzzeszzyc

user output
wolwmrwtoo rfjenrbedw

Test 11

Verdict: ACCEPTED

input
78 30

correct output
dxvdzxfqi uuhdakc

user output
ixvnvnqvpj mcqcdcudqd

Test 12

Verdict: ACCEPTED

input
19 7

correct output
dxvdzxfqi uuhdakc

user output
dotbnfgxnc cqyzvarabq

Test 13

Verdict: ACCEPTED

input
16 45

correct output
yrrkt aihwbdczv

user output
joqwdmqnpb fmhfpglwzn

Test 14

Verdict: ACCEPTED

input
78 61

correct output
oedtdfgv zgivhgayf

user output
sydhrfcoak wwqeiviicg

Test 15

Verdict: ACCEPTED

input
52 93

correct output
yzzzeszzyc uuhdakc

user output
zuvgnktykv updaplcham

Test 16

Verdict: ACCEPTED

input
85 82

correct output
dxvdzxfqi onbkb

user output
tgkxkwlvnw vitfsjwtgm

Test 17

Verdict: ACCEPTED

input
23 33

correct output
yzzzeszzyc aekmllmqu

user output
xlyaridmmv fgwgphwajg

Test 18

Verdict: ACCEPTED

input
30 19

correct output
oheo jftb

user output
erdzxdsnaf qblfzuwjtm

Test 19

Verdict: ACCEPTED

input
66 8

correct output
yzzzeszzyc uuhdakc

user output
lkmcdjbutg jcugkutdlk

Test 20

Verdict: ACCEPTED

input
10 44

correct output
uuhdakc gvnyskxly

user output
zusevnupch hwtucbrjut

Test 21

Verdict: ACCEPTED

input
589 888

correct output
irnrs nvmno

user output
yyrvbtoess taryyndylb

Test 22

Verdict: ACCEPTED

input
49 800

correct output
irnrs nvmno

user output
mscnjnwsnf fygjcgznup

Test 23

Verdict: ACCEPTED

input
209 702

correct output
yzzzeszzyc bpuse

user output
wsuzaltbcz vndbutguao

Test 24

Verdict: ACCEPTED

input
518 670

correct output
nvmno mgmo

user output
rvwcljbksa rpmjnlmeag

Test 25

Verdict: ACCEPTED

input
961 295

correct output
aekmllmqu wcpqoadrw

user output
xogddclewt perhpoybel

Test 26

Verdict: ACCEPTED

input
871 697

correct output
xfwgyq eokm

user output
btnbnivkrt layvrtiqrx

Test 27

Verdict: ACCEPTED

input
308 714

correct output
nvmno lcwlpcmzza

user output
wzqjyvturg kcghhiwufu

Test 28

Verdict: ACCEPTED

input
426 481

correct output
onbkb kqupmfo

user output
xhunnwppkw pimtcwulne

Test 29

Verdict: ACCEPTED

input
730 171

correct output
eqdlmuyo wpvfat

user output
cropzicahs fdqegdukmu

Test 30

Verdict: ACCEPTED

input
864 801

correct output
wpvfat onbkb

user output
ujsobwrook hueqqgxunk

Test 31

Verdict: ACCEPTED

input
6442 9170

correct output
wgqgje blui

user output
lueumwzrkf qwhzevfebv

Test 32

Verdict: ACCEPTED

input
2861 290

correct output
wpvfat onbkb

user output
veqtsuednf hogyxlzvsy

Test 33

Verdict: ACCEPTED

input
8589 597

correct output
oheo uuhdakc

user output
fhujsdvvvu drdskftbao

Test 34

Verdict: ACCEPTED

input
2486 6897

correct output
zlscxfnxo ngvkz

user output
fwwyakxpaw lqdtulrhea

Test 35

Verdict: ACCEPTED

input
386 1958

correct output
vdihr miezzgst

user output
ysnpgzvvtv nzroohxckz

Test 36

Verdict: ACCEPTED

input
4581 4498

correct output
uxqojd rhvuifulrn

user output
jrzbjfwhes yfykcddncv

Test 37

Verdict: ACCEPTED

input
7286 877

correct output
irnrs iphgzlf

user output
ujpkkwptsq jsqbhpuwlh

Test 38

Verdict: ACCEPTED

input
9445 1393

correct output
hdwsfcnq veukbhkw

user output
jzyugortum stsfgvzrlc

Test 39

Verdict: ACCEPTED

input
3848 8971

correct output
xshrtktoj fcuzyfii

user output
yytnetuolb mdgnbuuhml

Test 40

Verdict: ACCEPTED

input
5469 57

correct output
dxvdzxfqi yzzzeszzyc

user output
hgttyqkkgs ssxmlkinyj

Test 41

Verdict: ACCEPTED

input
40770 64402

correct output
tced hbmnyt

user output
wvwxjqjuqw rqcnlfozou

Test 42

Verdict: ACCEPTED

input
25093 68059

correct output
ljrc wjxknzhykr

user output
xovqnbbfdm dtcqpheksr

Test 43

Verdict: ACCEPTED

input
37455 79656

correct output
tppoycpya wviirv

user output
qywuelbyvg hjdinrqaoy

Test 44

Verdict: ACCEPTED

input
11506 49687

correct output
xaupctgiid jcdd

user output
jhxsssypuj wjtlxxuwdj

Test 45

Verdict: ACCEPTED

input
83486 43255

correct output
bodw cdmncijoh

user output
vkeypepujo hbpkhgzgsv

Test 46

Verdict: ACCEPTED

input
98903 30455

correct output
xshrtktoj pofnegkmkq

user output
maywzpflzh hydrewvlpy

Test 47

Verdict: ACCEPTED

input
78385 25806

correct output
fnyjzygwa zyfhqqpkk

user output
uhimwfvcit ovllnhtxaf

Test 48

Verdict: ACCEPTED

input
11350 85178

correct output
tsgztkzvwc rkra

user output
ooxgnumbuo mthyfpojtq

Test 49

Verdict: ACCEPTED

input
1750 42650

correct output
rlmle czxwmutnse

user output
atchkgrkch xukqfyuwvh

Test 50

Verdict: ACCEPTED

input
30097 47375

correct output
zlscxfnxo ayfmd

user output
uvsrvalqye mccacmiymw

Test 51

Verdict: ACCEPTED

input
494714 129204

correct output
czxwmutnse hudvk

user output
txsensmsig rbbkmjsrmk

Test 52

Verdict: ACCEPTED

input
675884 327185

correct output
rlmle rejxztcu

user output
whrhiuhadz cfuzmpqemp

Test 53

Verdict: ACCEPTED

input
823296 823560

correct output
ratyx aurscmksx

user output
gfuzxtvmpm xbarsgjggm

Test 54

Verdict: ACCEPTED

input
846854 678908

correct output
rfpuucjk yjndrg

user output
tqdhpzveht dewusonsbp

Test 55

Verdict: ACCEPTED

input
420278 193978

correct output
begabk sqac

user output
jykrfhrpfz smrjbwhvyz

Test 56

Verdict: ACCEPTED

input
93130 695227

correct output
nkomreccwl dfboyzq

user output
tqjcaelavk jsopohlfpb

Test 57

Verdict: ACCEPTED

input
984414 95962

correct output
plsmw rufywewnbq

user output
hzkusfpihs rusbmpayle

Test 58

Verdict: ACCEPTED

input
87370 612080

correct output
psmbxgyf yzwvwyf

user output
saaalzpadh rzzqnlyrur

Test 59

Verdict: ACCEPTED

input
365188 833610

correct output
jbbjpkxs asruylwnc

user output
irzsownnuz ogqkyuelul

Test 60

Verdict: ACCEPTED

input
924244 804799

correct output
bxok beqs

user output
nyevgnpvbm lfgxrpzfqv

Test 61

Verdict: ACCEPTED

input
3012218 7755483

correct output
rzhfdn bhig

user output
ouukirwndf phdletinzg

Test 62

Verdict: ACCEPTED

input
8254242 8634301

correct output
gleo mavrtxor

user output
dkxowowrqr lqssxzlvai

Test 63

Verdict: ACCEPTED

input
337938 5429289

correct output
hexlssw zxdfne

user output
nvktzcayfn cbpdvnojmt

Test 64

Verdict: ACCEPTED

input
5545825 4865884

correct output
copwroka xebbxy

user output
shicphxrpf kglnrfwyxw

Test 65

Verdict: ACCEPTED

input
3795375 7727646

correct output
rgde yqleban

user output
ecdxxxpfhk brdohqtssw

Test 66

Verdict: ACCEPTED

input
2188983 8702106

correct output
zmjbhiiqo gyrickzf

user output
cyyyuuimpq aqjvdlhomk

Test 67

Verdict: ACCEPTED

input
1544663 1956286

correct output
lwvsjair peplyj

user output
ectibavbug fqoluptirx

Test 68

Verdict: ACCEPTED

input
5464835 7522941

correct output
wjctw wqbqsqcdqg

user output
azlhkhluzg madeuqzglu

Test 69

Verdict: ACCEPTED

input
2596718 4049688

correct output
nvyasakcug bsbyew

user output
canvovxzvv hrbiylakzr

Test 70

Verdict: ACCEPTED

input
2965922 4020437

correct output
zthes oazfss

user output
ebdeepdrzd ckcetakchd

Test 71

Verdict: ACCEPTED

input
56122287 60624959

correct output
hgllxkyp oukmzblohw

user output
uayanzcbry exfcifumlp

Test 72

Verdict: ACCEPTED

input
42645140 73661194

correct output
xkdotul jvryawmaj

user output
krnvtuoibo njzijftsyo

Test 73

Verdict: ACCEPTED

input
44585330 18926703

correct output
yqmfko hogdxzgt

user output
enwqqiutzo hivokdvczw

Test 74

Verdict: ACCEPTED

input
56325214 7232406

correct output
wvmuumpi weyyifgfw

user output
euzxsbooai kmeyzhlybm

Test 75

Verdict: ACCEPTED

input
98889561 92098565

correct output
xcesn xvzzheobbo

user output
bujzjeeubs kfqdojfcpw

Test 76

Verdict: ACCEPTED

input
22701272 5642782

correct output
lescyxpmpw hkszwirdqk

user output
latwlxtsvk opscvgoyno

Test 77

Verdict: ACCEPTED

input
91304885 96889971

correct output
rnve dxgzxms

user output
wcgrusizxw exnbacdokw

Test 78

Verdict: ACCEPTED

input
7803372 23247950

correct output
aofeuxbryn bgcepuzv

user output
vbkfgzlpeu cbawoadcwe

Test 79

Verdict: ACCEPTED

input
89317875 1136575

correct output
kfdzbbelk esohyirdk

user output
mngkyzzzpz kiffkoffpa

Test 80

Verdict: ACCEPTED

input
1060874 37270195

correct output
pkkvrpnjgw aoljv

user output
secnhxfzpm ebjwvmvfkf

Test 81

Verdict: ACCEPTED

input
828199235 320792352

correct output
cmqjomgda cyptxxyb

user output
qmdalgdpaq eicgvnqtcp

Test 82

Verdict: ACCEPTED

input
193563111 73343920

correct output
gtswukro ziuzhijy

user output
lovoujaehr orjqsdocmm

Test 83

Verdict: ACCEPTED

input
165531091 479126951

correct output
ozbczatbfr nplek

user output
zdpffgalbl kgzexfloap

Test 84

Verdict: ACCEPTED

input
835051605 652127789

correct output
ypkbe jvzy

user output
faupdixkdg qtnfxibctq

Test 85

Verdict: ACCEPTED

input
551842459 989875543

correct output
ajtuqsqbs tqboquks

user output
ooyalfgdqz vsosdvmtwr

Test 86

Verdict: ACCEPTED

input
911411059 873575358

correct output
bhhhipl bcgsdgu

user output
uthusrtseb vtllyoujek

Test 87

Verdict: ACCEPTED

input
239756971 350744380

correct output
gddvcp osie

user output
wnwjykcwti dzpdjsrqve

Test 88

Verdict: ACCEPTED

input
316394140 195182397

correct output
jthyube jxvfzsh

user output
coeejwnsks fuumwtxedk

Test 89

Verdict: ACCEPTED

input
698334027 81615941

correct output
ikrcixfxr ugacbxbd

user output
daboyhksnn pqbdnhtdmx

Test 90

Verdict: ACCEPTED

input
104725912 462211740

correct output
alzppvu qlyi

user output
djmkooeoew gxiuqfrtyk