CSES - Aalto Competitive Programming 2024 - wk5 - Mon - Results
Submission details
Task:Freight trains
Sender:aalto2024e_002
Submission time:2024-09-30 17:21:00 +0300
Language:C++ (C++17)
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#20.00 sdetails
#30.00 sdetails
#40.00 sdetails
#50.00 sdetails
#60.00 sdetails
#70.00 sdetails
#80.00 sdetails
#90.00 sdetails
#100.00 sdetails
#110.00 sdetails
#120.00 sdetails
#130.00 sdetails
#140.00 sdetails
#150.00 sdetails
#160.00 sdetails
#170.00 sdetails
#180.00 sdetails
#190.00 sdetails
#200.01 sdetails
#210.00 sdetails
#220.00 sdetails
#230.00 sdetails
#240.00 sdetails
#250.00 sdetails
#260.00 sdetails
#270.00 sdetails
#280.00 sdetails
#290.00 sdetails
#300.00 sdetails
#310.00 sdetails
#320.00 sdetails
#330.00 sdetails
#340.00 sdetails
#350.00 sdetails
#360.00 sdetails
#370.00 sdetails
#380.00 sdetails
#390.00 sdetails
#400.00 sdetails
#410.00 sdetails
#420.00 sdetails
#430.00 sdetails
#440.00 sdetails
#450.00 sdetails
#460.00 sdetails
#470.00 sdetails
#480.00 sdetails
#490.00 sdetails
#500.00 sdetails
#510.00 sdetails
#520.00 sdetails
#530.00 sdetails
#540.00 sdetails
#550.00 sdetails
#560.00 sdetails
#570.00 sdetails
#580.00 sdetails
#590.00 sdetails
#600.00 sdetails
#610.00 sdetails
#620.05 sdetails
#630.05 sdetails
#640.05 sdetails
#650.05 sdetails
#660.05 sdetails
#670.05 sdetails
#680.05 sdetails
#690.05 sdetails
#700.05 sdetails
#710.05 sdetails

Compiler report

input/code.cpp: In function 'int comp(std::string&, std::string&)':
input/code.cpp:40:21: warning: comparison of integer expressions of different signedness: 'int' and 'size_t' {aka 'long unsigned int'} [-Wsign-compare]
   40 |   for (int i = 0; i < length_a + length_b; i++) {
      |                   ~~^~~~~~~~~~~~~~~~~~~~~
input/code.cpp:41:22: warning: comparison of integer expressions of different signedness: 'int' and 'size_t' {aka 'long unsigned int'} [-Wsign-compare]
   41 |     char char_a = (i < length_a) ? a[i] : b[i - length_a];
      |                    ~~^~~~~~~~~~
input/code.cpp:42:22: warning: comparison of integer expressions of different signedness: 'int' and 'size_t' {aka 'long unsigned int'} [-Wsign-compare]
   42 |     char char_b = (i < length_b) ? b[i] : a[i - length_b];
      |                    ~~^~~~~~~~~~

Code

#include <bits/stdc++.h>
using namespace std;

#define PRINT_ARR(arr, n)                                                      \
  do {                                                                         \
    for (int i = 0; i < n; i++) {                                              \
      cout << arr[i] << " ";                                                   \
    }                                                                          \
    cout << "\n";                                                              \
  } while (0)

typedef long long ll;

// int cmp(string a, string b, string c) {
//   int i =0;
//   if (a.size() < 2 && b.size() < 2) {
//     return
//   }
//   while (i < a.size() && i < b.size() && a[i] == b[i])
//     i++;
//   if (a[i-1] != b[i-1])
//
// }
int cmp(string &a, string &b) {
  size_t la = a.length();
  size_t lb = b.length();
  size_t i = 0;
  size_t ll = min(la, lb);
  while (i < ll && a[i] == b[i])
    i++;
  if (i < ll) {
    return a[i] < b[i];
  }
  return la > lb;
}

int comp(string &a, string &b) {
  size_t length_a = a.length();
  size_t length_b = b.length();
  for (int i = 0; i < length_a + length_b; i++) {
    char char_a = (i < length_a) ? a[i] : b[i - length_a];
    char char_b = (i < length_b) ? b[i] : a[i - length_b];
    if (char_a < char_b) {
      return true;
    } else if (char_a > char_b) {
      return false;
    }
  }
  return false;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;
  cin >> n;

  vector<string> arr(n);
  string t;
  if (n == 1) {
    cin >> t;
    cout << t << endl;
    return 0;
  }

  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }

  sort(arr.begin(), arr.end(), cmp);

  PRINT_ARR(arr, n);

  int l = 0, r = 1;
  while (l < n && r < n) {
    // cout << arr[l] << " " << arr[r] << " " << comp(arr[l], arr[r]) << endl;
    if (comp(arr[l], arr[r])) {
      cout << arr[l];
      l = max(l, r) + 1;
    } else {
      cout << arr[r];
      r = max(l, r) + 1;

    }
  }
  cout << arr[min(l, r)] << endl;

}

Test details

Test 1

Verdict: ACCEPTED

input
1
gl

correct output
gl

user output
gl

Test 2

Verdict:

input
2
adedf
ff

correct output
adedfff

user output
adedf ff 
adedfff

Test 3

Verdict:

input
2
jb
lj

correct output
jblj

user output
jb lj 
jblj

Test 4

Verdict:

input
2
qlipb
sr

correct output
qlipbsr

user output
qlipb sr 
qlipbsr

Test 5

Verdict:

input
3
f
llk
onfj

correct output
fllkonfj

user output
f llk onfj 
fllkonfj

Test 6

Verdict:

input
3
jaeo
mob
nk

correct output
jaeomobnk

user output
jaeo mob nk 
jaeomobnk

Test 7

Verdict:

input
3
nemlo
psqhy
sg

correct output
nemlopsqhysg

user output
nemlo psqhy sg 
nemlopsqhysg

Test 8

Verdict:

input
4
dia
eh
fbcae
gf

correct output
diaehfbcaegf

user output
dia eh fbcae gf 
diaehfbcaegf

Test 9

Verdict:

input
4
c
cbfaa
egbg
fc

correct output
cbfaacegbgfc

user output
cbfaa c egbg fc 
cbfaacegbgfc

Test 10

Verdict:

input
4
cbc
cdd
ceed
dbeea

correct output
cbccddceeddbeea

user output
cbc cdd ceed dbeea 
cbccddceeddbeea

Test 11

Verdict:

input
4
bfec
bgbaf
fcg
fdbbg

correct output
bfecbgbaffcgfdbbg

user output
bfec bgbaf fcg fdbbg 
bfecbgbaffcgfdbbg

Test 12

Verdict:

input
5
aoefh
ge
imgjj
kmj
...

correct output
aoefhgeimgjjkmjmhhi

user output
aoefh ge imgjj kmj mhhi 
aoefhgeimgjjkmjmhhi

Test 13

Verdict:

input
5
bcbec
ei
fdigc
ilabd
...

correct output
bcbeceifdigcilabdlg

user output
bcbec ei fdigc ilabd lg 
bcbeceifdigcilabdlg

Test 14

Verdict:

input
5
a
d
db
glfff
...

correct output
adbdglfffih

user output
a db d glfff ih 
adbdglfffih

Test 15

Verdict:

input
5
ab
d
ebhin
k
...

correct output
abdebhinknab

user output
ab d ebhin k nab 
abdebhinknab

Test 16

Verdict:

input
5
fasgx
o
oezws
qua
...

correct output
fasgxoezwsoquaspfd

user output
fasgx oezws o qua spfd 
fasgxoezwsoquaspfd

Test 17

Verdict:

input
5
bcggd
dcg
e
fc
...

correct output
bcggddcgefcg

user output
bcggd dcg e fc g 
bcggddcgefcg

Test 18

Verdict:

input
5
cmo
cx
hftbb
mil
...

correct output
cmocxhftbbmiltksr

user output
cmo cx hftbb mil tksr 
cmocxhftbbmiltksr

Test 19

Verdict:

input
5
ab
ababa
b
ca
...

correct output
ababaabbcaccb

user output
ababa ab b ca ccb 
ababaabbcaccb

Test 20

Verdict:

input
5
o
rjj
sfj
ti
...

correct output
orjjsfjtiw

user output
o rjj sfj ti w 
orjjsfjtiw

Test 21

Verdict:

input
5
a
aa
aaa
abbab
...

correct output
aaaaaaabbabba

user output
aaa aa abbab a ba 
aaaaaaabbabba

Test 22

Verdict:

input
10
aoefh
f
ge
hlmgh
...

correct output
aoefhfgehlmghimgjjjkmjmhhinmol...

user output
aoefh f ge hlmgh imgjj j kmj m...

Test 23

Verdict:

input
10
bcbec
cjjil
dbigk
ei
...

correct output
bcbeccjjildbigkeifdigcgfbikfil...

user output
bcbec cjjil dbigk ei fdigc gfb...

Test 24

Verdict:

input
10
a
cij
d
db
...

correct output
acijdbddhhekcgibfgglfffihkg

user output
a cij db dhh d ekc gibfg glfff...

Test 25

Verdict:

input
10
ab
d
ebhin
fk
...

correct output
abdebhinfkgjdinaiodgkacknab

user output
ab d ebhin fk gjd ina iodg kac...

Test 26

Verdict:

input
10
buywl
fasgx
gb
jzpek
...

correct output
buywlfasgxgbjzpekoezwsoquaspfd...

user output
buywl fasgx gb jzpek oezws o q...

Test 27

Verdict:

input
10
acg
bcggd
dcg
dede
...

correct output
acgbcggddcgdedeefcfdbbfgabbg

user output
acg bcggd dcg dede e fc fdbb f...

Test 28

Verdict:

input
10
cmo
cx
dpr
dtir
...

correct output
cmocxdprdtirhftbbmfmiltksrttkb...

user output
cmo cx dpr dtir hftbb mf mil t...

Test 29

Verdict:

input
10
ab
ababa
abbc
b
...

correct output
ababaababbcbbbcaccbcccccc

user output
ababa abbc ab bb b ca ccb ccc ...

Test 30

Verdict:

input
10
dmq
gl
j
jqso
...

correct output
dmqgljjqsoorjjsfjtiulvw

user output
dmq gl jqso j o rjj sfj ti ulv...

Test 31

Verdict:

input
10
a
aa
aaa
abbab
...

correct output
aaaaaaabbabbabbabbabbbbbabbbbb

user output
aaa aa abbab a ba bbab bba bbb...

Test 32

Verdict:

input
100
aa
acmfac
afmolcn
alllbndbli
...

correct output
aaacmfacafmolcnalllbndbliamdal...

user output
aa acmfac afmolcn alllbndbli a...
Truncated

Test 33

Verdict:

input
100
a
acjgj
ae
aegdb
...

correct output
aacjgjaeaegdbafcbahledfchagaja...

user output
acjgj aegdb ae afcb ahledfchag...
Truncated

Test 34

Verdict:

input
100
a
aah
abaeeaifc
abajl
...

correct output
aaahabaeeaifcabajlaehaejcdegka...

user output
aah abaeeaifc abajl aeh aejcde...
Truncated

Test 35

Verdict:

input
100
a
aa
abg
abndfmmmk
...

correct output
aaaabgabndfmmmkacggjdeacogeada...

user output
aa abg abndfmmmk acggjde acoge...
Truncated

Test 36

Verdict:

input
100
afn
aic
ajrkgzldb
amcyqyh
...

correct output
afnaicajrkgzldbamcyqyhandanxhj...

user output
afn aic ajrkgzldb amcyqyh and ...
Truncated

Test 37

Verdict:

input
100
aacdeffdd
abaacbae
abfbbff
ac
...

correct output
aacdeffddabaacbaeabfbbffacacbg...

user output
aacdeffdd abaacbae abfbbff acb...
Truncated

Test 38

Verdict:

input
100
abnfxhutgk
ajkdoqmdqp
asxeblm
badpwpsqhn
...

correct output
abnfxhutgkajkdoqmdqpasxeblmbad...

user output
abnfxhutgk ajkdoqmdqp asxeblm ...
Truncated

Test 39

Verdict:

input
100
a
aa
aaaaacaca
aaaabcabc
...

correct output
aaaaaaaacacaaaaabcabcaaabaaaab...

user output
aaaaacaca aaaabcabc aaaba aaab...
Truncated

Test 40

Verdict:

input
100
a
aiesfhkro
aivvkdc
ajrtj
...

correct output
aaiesfhkroaivvkdcajrtjaqfnivlb...

user output
aiesfhkro aivvkdc ajrtj aqfniv...
Truncated

Test 41

Verdict:

input
100
a
aa
aaaa
aaaaa
...

correct output
aaaaaaaaaaaaaaaaaaaaaaaaaaabab...

user output
aaaaaaaaa aaaaaabab aaaaaba aa...
Truncated

Test 42

Verdict:

input
200
a
aa
abbhjifdb
acmfac
...

correct output
aaaabbhjifdbacmfacadiadnhkaehh...

user output
aa abbhjifdb acmfac adi adnhk ...
Truncated

Test 43

Verdict:

input
200
a
aa
abihiahg
acjgj
...

correct output
aaaabihiahgacjgjadaeaegdbafcba...

user output
aa abihiahg acjgj ad aegdb ae ...
Truncated

Test 44

Verdict:

input
200
a
aah
abaeeaifc
abajl
...

correct output
aaahabaeeaifcabajlaehaejcdegka...

user output
aah abaeeaifc abajl aeh aejcde...
Truncated

Test 45

Verdict:

input
200
a
aa
aan
abg
...

correct output
aaaaanabgabndfmmmkacggjdeacoge...

user output
aan aa abg abndfmmmk acggjde a...
Truncated

Test 46

Verdict:

input
200
ad
aegewtfc
afn
aic
...

correct output
adaegewtfcafnaicajrkgzldbamcyq...

user output
ad aegewtfc afn aic ajrkgzldb ...
Truncated

Test 47

Verdict:

input
200
a
aa
aacdeffdd
aaeceaeb
...

correct output
aaaaacdeffddaaeceaebabaacbaeab...

user output
aacdeffdd aaeceaeb aa abaacbae...
Truncated

Test 48

Verdict:

input
200
abnfxhutgk
aghv
ajkdoqmdqp
ajpvvalnu
...

correct output
abnfxhutgkaghvajkdoqmdqpajpvva...

user output
abnfxhutgk aghv ajkdoqmdqp ajp...
Truncated

Test 49

Verdict:

input
200
a
aa
aaaaacaca
aaaabcabc
...

correct output
aaaaaaaacacaaaaabcabcaaaacbcaa...

user output
aaaaacaca aaaabcabc aaaacbc aa...
Truncated

Test 50

Verdict:

input
200
a
abam
aiesfhkro
aivvkdc
...

correct output
aabamaiesfhkroaivvkdcajrtjakam...

user output
abam aiesfhkro aivvkdc ajrtj a...
Truncated

Test 51

Verdict:

input
200
a
aaicd
acbjfaj
achddjj
...

correct output
aaaicdacbjfajachddjjacifadaecf...

user output
aaicd acbjfaj achddjj acif ad ...
Truncated

Test 52

Verdict:

input
1000
a
aa
aaccbkcd
aaj
...

correct output
aaaaaccbkcdaajaanabaabanikjabb...

user output
aaccbkcd aaj aan aa abanikj ab...
Truncated

Test 53

Verdict:

input
1000
a
aa
aabecajcf
aabg
...

correct output
aaaaabecajcfaabgaabjllgdlkaadg...

user output
aabecajcf aabg aabjllgdlk aadg...
Truncated

Test 54

Verdict:

input
1000
a
aa
aablaga
aah
...

correct output
aaaaablagaaahaajaaklkjjababaee...

user output
aablaga aah aaj aaklkjj aa aba...
Truncated

Test 55

Verdict:

input
1000
a
aa
aagjd
aajdlmacjn
...

correct output
aaaaagjdaajdlmacjnaakjdngdfaal...

user output
aagjd aajdlmacjn aakjdngdf aal...
Truncated

Test 56

Verdict:

input
1000
a
aalguz
abcce
abggxup
...

correct output
aaalguzabcceabggxupabujabxldxy...

user output
aalguz abcce abggxup abuj abxl...
Truncated

Test 57

Verdict:

input
1000
a
aa
aaabaaaaf
aaaeb
...

correct output
aaaaaabaaaafaaaebaabeadaabfffd...

user output
aaabaaaaf aaaeb aabead aabfffd...
Truncated

Test 58

Verdict:

input
1000
a
aamuthxggq
abnfxhutgk
adaumgqm
...

correct output
aaamuthxggqabnfxhutgkadaumgqma...

user output
aamuthxggq abnfxhutgk adaumgqm...
Truncated

Test 59

Verdict:

input
1000
a
aa
aaa
aaaa
...

correct output
aaaaaaaaaaaaaaaaaaaaaaaaaaabaa...

user output
aaaaaab aaaaaa aaaaababb aaaaa...
Truncated

Test 60

Verdict:

input
1000
a
aanmhqqnpc
ab
abam
...

correct output
aaanmhqqnpcababamabginwqvvacba...

user output
aanmhqqnpc abam abginwqvv ab a...
Truncated

Test 61

Verdict:

input
1000
a
aa
aaaca
aae
...

correct output
aaaaaacaaaeaaekcaagjeahdaahhdf...

user output
aaaca aaekc aae aagjeahd aahhd...
Truncated

Test 62

Verdict:

input
100000
a
aa
aaa
aaaagle
...

correct output
aaaaaaaaaagleaaabaaabiaaaaccgh...

user output
aaaagle aaabia aaab aaaccghlob...
Truncated

Test 63

Verdict:

input
100000
a
aa
aaa
aaaagf
...

correct output
aaaaaaaaaagfaaaaihlblgaaaalkll...

user output
aaaagf aaaaihlblg aaaalklle aa...
Truncated

Test 64

Verdict:

input
100000
a
aa
aaa
aaaa
...

correct output
aaaaaaaaaaaaaabkaaaaelbjbaaaaf...

user output
aaaabk aaaaelbjb aaaaflf aaaag...
Truncated

Test 65

Verdict:

input
100000
a
aa
aaa
aaaa
...

correct output
aaaaaaaaaaaaaahleaaaajaaabaaab...

user output
aaaahle aaaaj aaaa aaabekb aaa...
Truncated

Test 66

Verdict:

input
100000
a
aa
aaa
aaacxrqz
...

correct output
aaaaaaaaacxrqzaaahaaaahaaaplto...

user output
aaacxrqz aaaha aaah aaapltod a...
Truncated

Test 67

Verdict:

input
100000
a
aa
aaa
aaaa
...

correct output
aaaaaaaaaaaaaaaaaaaaaadbaaaaaa...

user output
aaaaaaadb aaaaaaadfd aaaaaadfg...
Truncated

Test 68

Verdict:

input
100000
a
aa
aaa
aaail
...

correct output
aaaaaaaaailaaaitehaeaaaitxaaam...

user output
aaail aaaitehae aaaitx aaammcf...
Truncated

Test 69

Verdict:

input
100000
a
aa
aaa
aaaa
...

correct output
aaaaaaaaaaaaaaabghaaaabcaffaaa...

user output
aaaaabgh aaaabcaff aaaabchdfi ...
Truncated

Test 70

Verdict:

input
100000
a
aa
aaa
aaaaggo
...

correct output
aaaaaaaaaaggoaaacwpgjkvaaaftbl...

user output
aaaaggo aaacwpgjkv aaaftbl aaa...
Truncated

Test 71

Verdict:

input
100000
a
aa
aaa
aaaa
...

correct output
aaaaaaaaaaaaaabaaaagkaaabaaabb...

user output
aaaab aaaagk aaaa aaabbkka aaa...
Truncated