QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#331975#4824. Bracket-and-bar Sequencesxtof_durr0 4ms4044kbC++143.3kb2024-02-19 02:59:542024-02-19 02:59:55

Judging History

你现在查看的是最新测评结果

  • [2024-02-19 02:59:55]
  • 评测
  • 测评结果:0
  • 用时:4ms
  • 内存:4044kb
  • [2024-02-19 02:59:54]
  • 提交

answer

/* Christoph Durr - 2024
Bracket-and-bar Sequences
https://qoj.ac/contest/1465/problem/4824

There are two main ingredients to the solution

## Simplifying the syntax

F = emptystring or '(' F '|' F ')' F 

## Encoding

We use the binary encoding where '(' corresponds to 1 and '|' or ')' to 0.
The code length is 3n

*/

#include <iostream>
#include <stack>
#include <cassert> 

using namespace std;

typedef unsigned long long ll;
typedef pair<int, ll> pil;

char word[1024] = "((|)|)(|)";
int pos=0;

// T[n] = number of strings of length 3n
ll T[26] = {1, 1};
ll L[25][25][25];           // lower bound of signature interval
ll U[25][25][25] = {1};     // upper bound

void fill() {
    for (int n = 2; n <= 25; n++) {
        for (int a=0; a < n; a++)
            for (int b=0; a + b < n; b++) {
                int c = n - 1 - a - b;
                L[a][b][c] = T[n];
                T[n] += T[a] * T[b] * T[c];
                U[a][b][c] = T[n];
            }
        // cout << "T[" << n << "] = " << T[n] << endl;
        // log(T[25], 2) == 63.8...
    }
}

void signature(int n, ll code, int &a, int &b, int &c) {
    ll total = 0;
    for (a=0; a < n; a++)
        for (b=0; a+b < n; b++) {
            c = n - 1 - a - b;
            if (U[a][b][c] > code)
                return;
        }
    // we should never reach this point
    cout << "code was " << code << " n=" << n << endl;
    assert(false);
}

void decode(int n, ll code) {
    if (n == 0)
        return;
    assert(code < T[n]);
    int a, b, c;
    signature(n, code, a, b, c);
    int ia, ib, ic;
    code -= L[a][b][c];
    ic = code % T[c];
    code /= T[c];
    ib = code % T[b];
    code /= T[b];
    ia = code;
    cout << "(";
    decode(a, ia);
    cout << "|";
    decode(b, ib);
    cout << ")";
    decode(c, ic);
}

void consume(char expectation) {
    assert(word[pos] == expectation);
    pos++;
}

/* encodes the string in `word`.
   assumes that initially pos == 0
*/ 
pil encode() {
    const char head = word[pos];
    if (word[pos] != '(')
        return {0, 0};
    consume('(');
    pil A = encode();
    consume('|');
    pil B = encode();
    consume(')');
    pil C = encode();
    int a = A.first;
    int b = B.first;
    int c = C.first;
    ll ia = A.second;
    ll ib = B.second;
    ll ic = C.second;
    int n = a + b + c + 1;
    ll code = L[a][b][c] + ic + T[c] * (ib + T[b] * ia);
    return {n, code};
}

int main(int argc, char const *argv[])
{
    fill();
    string mode;
    int test_cases, n;
    ll code;
    cin >> mode >> test_cases;
    if (mode == "encode")
        while (test_cases --> 0) {
            cin >> n >> word;   
            pos = 0;
            cout << encode().second << endl;
        }
    else // decode
        while (test_cases --> 0) {
            cin >> n >> code;  
            decode(n, code);
            cout << endl;
        }
    return 0;
}

int _main(int argc, char const *argv[])
{
    fill();
    for (int a=0; a<=2; a++)
        for (int b=0; b<=2; b++)
            for (int c=0; c<=2; c++) 
                cout << a << " " << b << " " << c << " L=" << L[a][b][c] 
                    << " U=" << U[a][b][c] << endl;
    cout << encode().second << endl;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3820kb

input:

encode
3
1
(|)
4
((((|)|)|)|)
5
(|(|))((|(|))|)

output:

0
54
65

input:

decode
3
1
0
4
54
5
65

output:

(|)
((((|)|)|)|)
(|(|))((|(|))|)

result:

ok 3 lines

Test #2:

score: 100
Accepted
time: 1ms
memory: 3980kb

input:

encode
1
1
(|)

output:

0

input:

decode
1
1
0

output:

(|)

result:

ok single line: '(|)'

Test #3:

score: 100
Accepted
time: 1ms
memory: 3840kb

input:

encode
3
2
((|)|)
1
(|)
2
(|(|))

output:

2
0
1

input:

decode
3
2
2
1
0
2
1

output:

((|)|)
(|)
(|(|))

result:

ok 3 lines

Test #4:

score: 100
Accepted
time: 3ms
memory: 3964kb

input:

encode
1000
3
(|)(|)(|)
3
(|)(|(|))
3
(|)((|)|)
3
(|(|))(|)
3
(|(|)(|))
3
(|(|(|)))
3
(|((|)|))
3
((|)|)(|)
3
((|)|(|))
3
((|)(|)|)
3
((|(|))|)
3
(((|)|)|)
4
(|)(|)(|)(|)
4
(|)(|)(|(|))
4
(|)(|)((|)|)
4
(|)(|(|))(|)
4
(|)(|(|)(|))
4
(|)(|(|(|)))
4
(|)(|((|)|))
4
(|)((|)|)(|)
4
(|)((|)|(|))
4
(|)((|)...

output:

0
1
2
3
4
5
6
7
8
9
10
11
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
...

input:

decode
1000
3
0
3
1
3
2
3
3
3
4
3
5
3
6
3
7
3
8
3
9
3
10
3
11
4
0
4
1
4
2
4
3
4
4
4
5
4
6
4
7
4
8
4
9
4
10
4
11
4
12
4
13
4
14
4
15
4
16
4
17
4
18
4
19
4
20
4
21
4
22
4
23
4
24
4
25
4
26
4
27
4
28
4
29
4
30
4
31
4
32
4
33
4
34
4
35
4
36
4
37
4
38
4
39
4
40
4
41
4
42
4
43
4
44
4
45
4
46
4
47
4
48
4
4...

output:

(|)(|)(|)
(|)(|(|))
(|)((|)|)
(|(|))(|)
(|(|)(|))
(|(|(|)))
(|((|)|))
((|)|)(|)
((|)|(|))
((|)(|)|)
((|(|))|)
(((|)|)|)
(|)(|)(|)(|)
(|)(|)(|(|))
(|)(|)((|)|)
(|)(|(|))(|)
(|)(|(|)(|))
(|)(|(|(|)))
(|)(|((|)|))
(|)((|)|)(|)
(|)((|)|(|))
(|)((|)(|)|)
(|)((|(|))|)
(|)(((|)|)|)
(|(|))(|)(|)
(|(|))(|(|)...

result:

ok 1000 lines

Test #5:

score: 100
Accepted
time: 3ms
memory: 3812kb

input:

encode
1000
6
(|((((|)|)|)|)(|))
6
(|((|)(|)(|)|(|)))
6
(|((|)(|(|))|(|)))
6
(|((|)((|)|)|(|)))
6
(|((|(|))(|)|(|)))
6
(|((|(|)(|))|(|)))
6
(|((|(|(|)))|(|)))
6
(|((|((|)|))|(|)))
6
(|(((|)|)(|)|(|)))
6
(|(((|)|(|))|(|)))
6
(|(((|)(|)|)|(|)))
6
(|(((|(|))|)|(|)))
6
(|((((|)|)|)|(|)))
6
(|((|)(|)(|)(...

output:

660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
...

input:

decode
1000
6
660
6
661
6
662
6
663
6
664
6
665
6
666
6
667
6
668
6
669
6
670
6
671
6
672
6
673
6
674
6
675
6
676
6
677
6
678
6
679
6
680
6
681
6
682
6
683
6
684
6
685
6
686
6
687
6
688
6
689
6
690
6
691
6
692
6
693
6
694
6
695
6
696
6
697
6
698
6
699
6
700
6
701
6
702
6
703
6
704
6
705
6
706
6
707
...

output:

(|((((|)|)|)|)(|))
(|((|)(|)(|)|(|)))
(|((|)(|(|))|(|)))
(|((|)((|)|)|(|)))
(|((|(|))(|)|(|)))
(|((|(|)(|))|(|)))
(|((|(|(|)))|(|)))
(|((|((|)|))|(|)))
(|(((|)|)(|)|(|)))
(|(((|)|(|))|(|)))
(|(((|)(|)|)|(|)))
(|(((|(|))|)|(|)))
(|((((|)|)|)|(|)))
(|((|)(|)(|)(|)|))
(|((|)(|)(|(|))|))
(|((|)(|)((|)|)...

result:

ok 1000 lines

Test #6:

score: 100
Accepted
time: 3ms
memory: 4040kb

input:

encode
1000
7
((|)(|(|(|)(|)))|(|))
7
((|)(|(|)(|)(|))(|)|)
7
(|(|(|)((|)|))(|(|)))
7
((|(|))|(|))(|(|))(|)
7
(|)((|(|)((|)|)(|))|)
7
(((|(|)(|))|((|)|))|)
7
((|)((|(|))(|(|))|)|)
8
(|)(|)(|(|))((|((|)|))|)
7
((|)|)((|)|)(((|)|)|)
7
(|)((|)|)(((|)|(|))|)
7
(|((|)|(|)))(|(|)(|))
7
((|)|(|(|)((|)|))(|...

output:

6073
6400
2819
4784
1250
7347
6555
322
4030
779
1966
4409
157
5064
2789
3304
2248
5145
3167
4603
3224
2398
6452
7680
6971
4044
399
1988
7098
1127
5551
2741
5886
1714
3828
6601
7708
2328
7191
647
1972
833
4241
3049
2638
2630
6022
3386
1676
3643
6313
4111
4482
1630
401
7656
5266
4380
3527
5359
7429
61...

input:

decode
1000
7
6073
7
6400
7
2819
7
4784
7
1250
7
7347
7
6555
8
322
7
4030
7
779
7
1966
7
4409
8
157
7
5064
7
2789
7
3304
7
2248
7
5145
7
3167
7
4603
7
3224
7
2398
7
6452
7
7680
7
6971
7
4044
7
399
7
1988
7
7098
7
1127
7
5551
7
2741
7
5886
7
1714
7
3828
7
6601
7
7708
7
2328
7
7191
7
647
7
1972
7
833
...

output:

((|)(|(|(|)(|)))|(|))
((|)(|(|)(|)(|))(|)|)
(|(|(|)((|)|))(|(|)))
((|(|))|(|))(|(|))(|)
(|)((|(|)((|)|)(|))|)
(((|(|)(|))|((|)|))|)
((|)((|(|))(|(|))|)|)
(|)(|)(|(|))((|((|)|))|)
((|)|)((|)|)(((|)|)|)
(|)((|)|)(((|)|(|))|)
(|((|)|(|)))(|(|)(|))
((|)|(|(|)((|)|))(|))
(|)(|)(|)((|)|(|))((|)|)
((|)((|)...

result:

ok 1000 lines

Test #7:

score: 100
Accepted
time: 2ms
memory: 3820kb

input:

encode
1000
7
(|(|)(|)(|(((|)|)|)))
7
(((|)|)((|)|)(|(|))|)
7
(|(|))((|)(|)|(|(|)))
7
(|)(|((|((|(|))|))|))
7
(|((|)|(|))(|((|)|)))
7
(|)((|(|)(|(|)))(|)|)
7
(((|)(|)(|)|)|(|(|)))
7
((|(|))|)((|)|)(|(|))
7
(|)(|(|((|)(|)|(|))))
7
(((|)(|)|)|(|))(|)(|)
7
(|)(|(|(|)((|)|))(|))
7
((|)(|)|(((|)|)|(|)))
...

output:

2477
7083
1614
701
3237
1232
5743
4690
583
5204
533
4910
379
62
3981
2163
1896
5965
314
448
5850
2836
6553
7320
5415
4309
3601
1537
1719
7692
4651
3441
232
7148
6326
5328
2919
4897
582
2108
618
4981
1817
2646
6316
3823
3553
5348
1364
1469
4530
577
1599
240
2615
5772
7175
5035
681
2712
4557
6453
288
...

input:

decode
1000
7
2477
7
7083
7
1614
7
701
7
3237
7
1232
7
5743
7
4690
7
583
7
5204
7
533
7
4910
8
379
8
62
7
3981
7
2163
7
1896
7
5965
8
314
8
448
7
5850
7
2836
7
6553
7
7320
7
5415
7
4309
7
3601
7
1537
7
1719
7
7692
7
4651
7
3441
7
232
7
7148
7
6326
7
5328
7
2919
7
4897
7
582
7
2108
7
618
7
4981
7
181...

output:

(|(|)(|)(|(((|)|)|)))
(((|)|)((|)|)(|(|))|)
(|(|))((|)(|)|(|(|)))
(|)(|((|((|(|))|))|))
(|((|)|(|))(|((|)|)))
(|)((|(|)(|(|)))(|)|)
(((|)(|)(|)|)|(|(|)))
((|(|))|)((|)|)(|(|))
(|)(|(|((|)(|)|(|))))
(((|)(|)|)|(|))(|)(|)
(|)(|(|(|)((|)|))(|))
((|)(|)|(((|)|)|(|)))
(|)(|)(|(|(|(|))))(|)(|)
(|)(|)(|)(|...

result:

ok 1000 lines

Test #8:

score: 100
Accepted
time: 3ms
memory: 4024kb

input:

encode
1000
7
(((|)|(|)(|)(|)(|))|)
7
(|)(|(|(|)))((|(|))|)
7
((|)|)(|((|)|))(|(|))
7
(|(|(|)))((|(|(|)))|)
7
(((|)(|)|)|(|(|)))(|)
7
((|)((((|)|)|)|)|(|))
7
(|((|((|)|(|))(|))|))
7
((|)(((|)(|)(|)|)|)|)
8
(|)(|)(|)(|(|))((|)|(|))
7
(|(|(|))(|)((|(|))|))
7
((((|(|))|)(|)(|)|)|)
7
(|(|))((|)(|)|)((|)...

output:

7140
350
3950
1804
5241
6105
3724
6585
63
2731
7655
1603
3927
7276
4740
1215
2749
5372
5647
6004
3842
3928
2117
2360
442
7734
508
4699
1414
3333
2544
4405
2031
5534
4094
347
4535
5253
5949
5977
2643
4350
6279
2812
7319
907
4133
2426
2923
4245
7037
1976
3323
3507
2219
7683
3262
5404
5599
4201
908
480...

input:

decode
1000
7
7140
7
350
7
3950
7
1804
7
5241
7
6105
7
3724
7
6585
8
63
7
2731
7
7655
7
1603
7
3927
7
7276
7
4740
7
1215
7
2749
7
5372
7
5647
7
6004
7
3842
7
3928
7
2117
7
2360
7
442
7
7734
7
508
7
4699
7
1414
7
3333
7
2544
7
4405
7
2031
7
5534
7
4094
8
347
7
4535
7
5253
7
5949
7
5977
7
2643
7
4350
...

output:

(((|)|(|)(|)(|)(|))|)
(|)(|(|(|)))((|(|))|)
((|)|)(|((|)|))(|(|))
(|(|(|)))((|(|(|)))|)
(((|)(|)|)|(|(|)))(|)
((|)((((|)|)|)|)|(|))
(|((|((|)|(|))(|))|))
((|)(((|)(|)(|)|)|)|)
(|)(|)(|)(|(|))((|)|(|))
(|(|(|))(|)((|(|))|))
((((|(|))|)(|)(|)|)|)
(|(|))((|)(|)|)((|)|)
((|)|)(|)(((|)|(|))|)
((((|)|)|(|...

result:

ok 1000 lines

Test #9:

score: 100
Accepted
time: 0ms
memory: 3856kb

input:

encode
1000
7
((|(|)(|(|)))|)((|)|)
7
(|(|))((|(|(|(|))))|)
7
(|)(|(|((|)(|)|)))(|)
8
(|)(|)(|(|)(|))(|(|(|)))
7
(|((((|(|))|)|(|))|))
7
(((|(|))|)|)(|)((|)|)
7
((|(|))((|)|)|((|)|))
7
(((|(|))(|)|)(|)(|)|)
7
(|(|))(|(|)(|)(|)(|))
7
(((|)((|)|)|(|))(|)|)
7
((|(|)((|(|))|))(|)|)
7
(|)((|(|))(|)|((|)|...

output:

5452
1669
427
333
3819
5155
5657
7294
1516
7323
6734
1020
5981
1589
5313
5484
1112
5625
6845
434
2153
1097
2334
180
5662
2769
1044
5059
1158
993
454
2860
7744
1722
96
5132
1373
3415
1047
5086
5742
188
4606
4901
2673
6781
5350
6155
2390
5642
2880
3152
4632
2274
38
4555
2669
4727
189
1010
2502
1562
28...

input:

decode
1000
7
5452
7
1669
7
427
8
333
7
3819
7
5155
7
5657
7
7294
7
1516
7
7323
7
6734
7
1020
7
5981
7
1589
7
5313
7
5484
7
1112
7
5625
7
6845
8
434
7
2153
7
1097
7
2334
8
180
7
5662
7
2769
7
1044
7
5059
7
1158
7
993
8
454
7
2860
7
7744
7
1722
8
96
7
5132
7
1373
7
3415
7
1047
7
5086
7
5742
8
188
7
4...

output:

((|(|)(|(|)))|)((|)|)
(|(|))((|(|(|(|))))|)
(|)(|(|((|)(|)|)))(|)
(|)(|)(|(|)(|))(|(|(|)))
(|((((|(|))|)|(|))|))
(((|(|))|)|)(|)((|)|)
((|(|))((|)|)|((|)|))
(((|(|))(|)|)(|)(|)|)
(|(|))(|(|)(|)(|)(|))
(((|)((|)|)|(|))(|)|)
((|(|)((|(|))|))(|)|)
(|)((|(|))(|)|((|)|))
((((|)(|)|)|)(|)|)(|)
(|(|))((|)|...

result:

ok 1000 lines

Test #10:

score: 100
Accepted
time: 3ms
memory: 3820kb

input:

encode
1000
7
((((|)|(|)(|))|)(|)|)
7
(((|)(|)|)(|)(|(|))|)
7
(|)(|((|(|)(|))(|)|))
7
(|(|)(((|)|)|(|))(|))
7
(|)((|(|))|(|(|(|))))
7
((|(|)(|)(|)(|))|)(|)
7
(|((|)(|(|)((|)|))|))
7
(((|)|(|))|)((|)|)(|)
7
(|)(((|(|))|(|))|(|))
7
(|(|))(|((|)|))(|(|))
7
(|(|)(|))(|(|((|)|)))
7
((|(|)(|))|(|))(|)(|)
...

output:

7403
7196
688
2632
942
5866
3623
5136
1141
1502
1725
5189
1142
3975
1604
2304
7326
2008
3137
4270
159
3944
6384
3348
89
1939
4086
5188
5300
5870
1524
7413
2335
6490
5959
3829
4269
563
5604
3429
814
686
2488
5988
6543
6934
3558
5021
289
6141
975
2651
3893
941
3693
1907
685
4498
1574
3494
2624
7332
50...

input:

decode
1000
7
7403
7
7196
7
688
7
2632
7
942
7
5866
7
3623
7
5136
7
1141
7
1502
7
1725
7
5189
7
1142
7
3975
7
1604
7
2304
7
7326
7
2008
7
3137
7
4270
8
159
7
3944
7
6384
7
3348
8
89
7
1939
7
4086
7
5188
7
5300
7
5870
7
1524
7
7413
7
2335
7
6490
7
5959
7
3829
7
4269
7
563
7
5604
7
3429
7
814
7
686
7
...

output:

((((|)|(|)(|))|)(|)|)
(((|)(|)|)(|)(|(|))|)
(|)(|((|(|)(|))(|)|))
(|(|)(((|)|)|(|))(|))
(|)((|(|))|(|(|(|))))
((|(|)(|)(|)(|))|)(|)
(|((|)(|(|)((|)|))|))
(((|)|(|))|)((|)|)(|)
(|)(((|(|))|(|))|(|))
(|(|))(|((|)|))(|(|))
(|(|)(|))(|(|((|)|)))
((|(|)(|))|(|))(|)(|)
(|)((((|)|)|(|))|(|))
((|)|)(|(|)(((...

result:

ok 1000 lines

Test #11:

score: 100
Accepted
time: 3ms
memory: 3832kb

input:

encode
1000
7
(|((|)(|)|(|))(|(|)))
7
(|(((|)|)(|((|)|))|))
7
(|)((|)((|)|)|)(|)(|)
7
(|(|))(|)(((|)(|)|)|)
7
(|(|(|((|)|(|)))))(|)
7
((|)(|(|))|(|))((|)|)
7
(|)((|)(|)|)(|(|))(|)
7
(|(((|)|(|(|)))|(|)))
7
(((|)((|)|)(|)|)|)(|)
7
((|)|)((((|)(|)|)|)|)
7
(((|)|(|)(|))|)((|)|)
7
(|(((|)(|)|)|(|(|))))
...

output:

3356
3752
967
1480
2289
5182
874
3583
6003
4146
5497
3485
5856
5416
187
5914
3115
5426
7489
7531
6435
6331
6028
3775
5822
266
233
7010
6509
7585
5327
5242
6647
3545
5056
4139
410
4761
2737
2781
2342
1900
2607
3256
959
3455
4462
1380
3185
1276
5061
2130
1106
5235
1067
7031
602
246
5399
6081
6946
2374...

input:

decode
1000
7
3356
7
3752
7
967
7
1480
7
2289
7
5182
7
874
7
3583
7
6003
7
4146
7
5497
7
3485
7
5856
7
5416
8
187
7
5914
7
3115
7
5426
7
7489
7
7531
7
6435
7
6331
7
6028
7
3775
7
5822
7
266
8
233
7
7010
7
6509
7
7585
7
5327
7
5242
7
6647
7
3545
7
5056
7
4139
7
410
7
4761
7
2737
7
2781
7
2342
7
1900
...

output:

(|((|)(|)|(|))(|(|)))
(|(((|)|)(|((|)|))|))
(|)((|)((|)|)|)(|)(|)
(|(|))(|)(((|)(|)|)|)
(|(|(|((|)|(|)))))(|)
((|)(|(|))|(|))((|)|)
(|)((|)(|)|)(|(|))(|)
(|(((|)|(|(|)))|(|)))
(((|)((|)|)(|)|)|)(|)
((|)|)((((|)(|)|)|)|)
(((|)|(|)(|))|)((|)|)
(|(((|)(|)|)|(|(|))))
((|(|)((|)|))(|)|)(|)
((|)((|)|)(|)|...

result:

ok 1000 lines

Test #12:

score: 100
Accepted
time: 3ms
memory: 4024kb

input:

encode
1000
7
(|(|(|(|)(|)(|(|)))))
7
(|(|(|(|(|)))(|)))(|)
7
(|(((|)(|(|))|)|)(|))
7
(|((|)(|(|(|))(|))|))
7
(|)((|)(|)|(((|)|)|))
7
((|(|))(|)(|)(|)(|)|)
7
(((|(|))|)|)((|(|))|)
7
((|(|(|))((|)(|)|))|)
7
(|(|)(|(|(|))(|))(|))
7
(|((|)|(|)(|(|)))(|))
7
(|((|)|(|)(|)(|(|))))
7
((|)|((|)(|(|(|)))|))
...

output:

2992
2279
3537
3624
936
6597
5163
6843
2527
3253
3265
4554
1378
6491
158
6639
6050
2690
6121
4470
1555
748
1412
3361
6083
6534
6226
5156
4513
4293
3038
367
6191
6445
2131
519
2542
7728
5392
3011
1430
3974
5649
5853
2268
3910
5157
4299
1807
5483
5943
4366
7370
207
5303
6012
1547
5370
5289
1297
297
38...

input:

decode
1000
7
2992
7
2279
7
3537
7
3624
7
936
7
6597
7
5163
7
6843
7
2527
7
3253
7
3265
7
4554
7
1378
7
6491
8
158
7
6639
7
6050
7
2690
7
6121
7
4470
7
1555
7
748
7
1412
7
3361
7
6083
7
6534
7
6226
7
5156
7
4513
7
4293
7
3038
7
367
7
6191
7
6445
7
2131
7
519
7
2542
7
7728
7
5392
7
3011
7
1430
7
3974...

output:

(|(|(|(|)(|)(|(|)))))
(|(|(|(|(|)))(|)))(|)
(|(((|)(|(|))|)|)(|))
(|((|)(|(|(|))(|))|))
(|)((|)(|)|(((|)|)|))
((|(|))(|)(|)(|)(|)|)
(((|(|))|)|)((|(|))|)
((|(|(|))((|)(|)|))|)
(|(|)(|(|(|))(|))(|))
(|((|)|(|)(|(|)))(|))
(|((|)|(|)(|)(|(|))))
((|)|((|)(|(|(|)))|))
(|)(((|)(|(|(|)))|)|)
((|)((|)|(|((|...

result:

ok 1000 lines

Test #13:

score: 100
Accepted
time: 3ms
memory: 3836kb

input:

encode
1000
7
(|(|((|)|))(|))((|)|)
7
((|)(|)|)(|)(|(|(|)))
7
((((|(|))|(|(|)))|)|)
8
(|)(|)(|)(|(((|)|)|)(|))
7
((((((|)|)|)|)|)|(|))
7
(((|((|)|)((|)|))|)|)
7
(|(|((|)|))(|)((|)|))
7
((|)(|)|(|((|(|))|)))
7
(|(|(|(|)(|)(|)))(|))
7
(|(|)((|)|(((|)|)|)))
7
((((|((|)(|)|))|)|)|)
7
(|(|))(|(|)(|))(|(|...

output:

2063
4609
7668
127
6323
7599
2802
4896
2866
2620
7724
1496
6093
5215
2951
5962
3316
6414
7699
1991
901
1362
1405
5368
1050
4182
5656
601
2128
5686
5079
5106
1119
2030
3305
1507
4818
3487
469
933
2344
2800
1527
6527
544
6978
947
7422
3259
2584
133
263
765
7195
1664
466
2582
4717
4108
464
2667
5024
50...

input:

decode
1000
7
2063
7
4609
7
7668
8
127
7
6323
7
7599
7
2802
7
4896
7
2866
7
2620
7
7724
7
1496
7
6093
7
5215
7
2951
7
5962
7
3316
7
6414
7
7699
7
1991
7
901
7
1362
7
1405
7
5368
7
1050
7
4182
7
5656
7
601
7
2128
7
5686
7
5079
7
5106
7
1119
7
2030
7
3305
7
1507
7
4818
7
3487
8
469
7
933
7
2344
7
2800...

output:

(|(|((|)|))(|))((|)|)
((|)(|)|)(|)(|(|(|)))
((((|(|))|(|(|)))|)|)
(|)(|)(|)(|(((|)|)|)(|))
((((((|)|)|)|)|)|(|))
(((|((|)|)((|)|))|)|)
(|(|((|)|))(|)((|)|))
((|)(|)|(|((|(|))|)))
(|(|(|(|)(|)(|)))(|))
(|(|)((|)|(((|)|)|)))
((((|((|)(|)|))|)|)|)
(|(|))(|(|)(|))(|(|))
((|)(((|)|)|(|))|(|))
((|)(|)(|)|...

result:

ok 1000 lines

Test #14:

score: 100
Accepted
time: 3ms
memory: 3760kb

input:

encode
1000
8
(|(|((|)|)))(|(|)((|)|))
8
(|)(|(|)((|)(|)(|)|)(|))
8
(|)((|(|(|)(|))(|(|)))|)
8
(|)((|(((|)|)|))(|)|)(|)
8
(|((|)(|(|)(|(|)(|)))|))
8
(((|)|(|))(|((|)|(|)))|)
8
((|)(((|(|))(|)|)(|)|)|)
8
((|)((|)|)((|)(|)|)(|)|)
8
((|)|)(|(|(|)((|)|)(|)))
8
(|(|))(|((|)|(|((|)|))))
8
((((|)(|)(|)|(|)...

output:

10349
2642
6847
5865
19982
39686
36863
36276
21868
8374
42844
27311
19054
2286
19647
21674
1568
27317
10288
30886
30279
4487
13925
30058
14983
2387
4814
34171
34003
2959
16421
30099
15468
41287
38199
15560
20277
33168
11271
26121
7622
8451
19979
23536
4278
25896
4482
27418
19397
27580
795
22649
4075...

input:

decode
1000
8
10349
8
2642
8
6847
8
5865
8
19982
8
39686
8
36863
8
36276
8
21868
8
8374
8
42844
8
27311
8
19054
8
2286
8
19647
8
21674
8
1568
8
27317
8
10288
8
30886
8
30279
8
4487
8
13925
8
30058
8
14983
8
2387
8
4814
8
34171
8
34003
8
2959
8
16421
8
30099
8
15468
8
41287
8
38199
8
15560
8
20277
8
...

output:

(|(|((|)|)))(|(|)((|)|))
(|)(|(|)((|)(|)(|)|)(|))
(|)((|(|(|)(|))(|(|)))|)
(|)((|(((|)|)|))(|)|)(|)
(|((|)(|(|)(|(|)(|)))|))
(((|)|(|))(|((|)|(|)))|)
((|)(((|(|))(|)|)(|)|)|)
((|)((|)|)((|)(|)|)(|)|)
((|)|)(|(|(|)((|)|)(|)))
(|(|))(|((|)|(|((|)|))))
((((|)(|)(|)|(|)(|))|)|)
(((|)|)|((|)(|)(|)|(|)))
...

result:

ok 1000 lines

Test #15:

score: 100
Accepted
time: 3ms
memory: 3816kb

input:

encode
1000
9
((|)((|((|)(|)|(|(|))))|)|)
9
((((|)(|(|))|(((|)|)|))|)|)
9
(|((|((|)(((|)|)|)|))|(|)))
9
(((((|)|)|)((|)(|)|)(|)|)|)
9
(|)(((|(|))(|(|))|)(|)|(|))
9
(|)(|((|)|)(|)(|)(|)((|)|))
9
((((|)(|(|))|)(|)|)(|(|))|)
9
(|(|))(((|)(|)|(|(|))(|))|)
9
(|(((|)|(|))|(|)((|)|))(|))
9
(((|(|)((|)(|)|)...

output:

210377
244195
111679
243674
35141
17444
234742
50515
105300
236559
111626
53861
240729
161348
110770
81295
63219
130644
11643
204111
112847
170292
42024
164612
26202
24164
152649
172482
41102
140116
236978
100344
115047
150388
979
118601
33689
102680
50941
15890
66360
97240
147306
154189
179103
6103...

input:

decode
1000
9
210377
9
244195
9
111679
9
243674
9
35141
9
17444
9
234742
9
50515
9
105300
9
236559
9
111626
9
53861
9
240729
9
161348
9
110770
9
81295
9
63219
9
130644
9
11643
9
204111
9
112847
9
170292
9
42024
9
164612
9
26202
9
24164
9
152649
9
172482
9
41102
9
140116
9
236978
9
100344
9
115047
9
...

output:

((|)((|((|)(|)|(|(|))))|)|)
((((|)(|(|))|(((|)|)|))|)|)
(|((|((|)(((|)|)|)|))|(|)))
(((((|)|)|)((|)(|)|)(|)|)|)
(|)(((|(|))(|(|))|)(|)|(|))
(|)(|((|)|)(|)(|)(|)((|)|))
((((|)(|(|))|)(|)|)(|(|))|)
(|(|))(((|)(|)|(|(|))(|))|)
(|(((|)|(|))|(|)((|)|))(|))
(((|(|)((|)(|)|)(|))|)(|)|)
(|((|((|(|))|)(|)(|)...

result:

ok 1000 lines

Test #16:

score: 100
Accepted
time: 3ms
memory: 4040kb

input:

encode
1000
10
(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)
10
((((((((((|)|)|)|)|)|)|)|)|)|)
10
(|(|(|(|(|(|(|(|(|(|))))))))))
10
((|)|)((|)|(((|)|)|)(|((|)|)))
10
(|)((|)|((|((|)(|((|)|))|))|))
10
(|)(((|)|)((|(|))((|)|)(|)|)|)
10
((|)(|((|)|))(|)((|(|))|(|))|)
10
(((((((|(|(|)))|)|)|)(|)|)|)|)
10
(((|)|((|)|))...

output:

0
1430714
537507
715357
140744
225947
1193807
1429007
931168
286086
785996
1017557
351382
239737
354663
311192
312987
453662
790727
994491
463116
905894
1316532
1267151
24580
1063105
984871
786698
1382779
1413581
895685
79240
1137938
504731
187121
1401830
813221
554635
525121
300892
366856
870236
78...

input:

decode
1000
10
0
10
1430714
10
537507
10
715357
10
140744
10
225947
10
1193807
10
1429007
10
931168
10
286086
10
785996
10
1017557
10
351382
10
239737
10
354663
10
311192
10
312987
10
453662
10
790727
10
994491
10
463116
10
905894
10
1316532
10
1267151
10
24580
10
1063105
10
984871
10
786698
10
1382...

output:

(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)
((((((((((|)|)|)|)|)|)|)|)|)|)
(|(|(|(|(|(|(|(|(|(|))))))))))
((|)|)((|)|(((|)|)|)(|((|)|)))
(|)((|)|((|((|)(|((|)|))|))|))
(|)(((|)|)((|(|))((|)|)(|)|)|)
((|)(|((|)|))(|)((|(|))|(|))|)
(((((((|(|(|)))|)|)|)(|)|)|)|)
(((|)|((|)|))|)(|)(|)((|)(|)|)
(|(|))(((|)|)(|)(|(|(...

result:

ok 1000 lines

Test #17:

score: 100
Accepted
time: 4ms
memory: 4016kb

input:

encode
1000
11
(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)
11
(((((((((((|)|)|)|)|)|)|)|)|)|)|)
11
(|(|(|(|(|(|(|(|(|(|(|)))))))))))
11
((|)|)((|(|))(|)(|)(|)|((|)(|)|))
11
(|((((|)|)|)|((|(|(((|)|)|)))|)))
11
((|)|(((|)|(|((|((|)|))|)(|)))|))
11
(((|)|)|)((|(|)(((|)|)|))(|(|))|)
11
((|)((|)|)|((|)((|)|)|(|(|...

output:

0
8414639
3138807
4207320
3522475
4703863
4846786
5266804
5500361
4643860
1987995
4449675
6450787
972418
5509894
2543996
2224998
1259294
5683957
1413140
2877497
8128440
5157715
1486742
2192804
5823001
8073334
8394986
584238
4429229
6125916
5772486
2949582
3269057
8388305
457931
4635580
352581
207043...

input:

decode
1000
11
0
11
8414639
11
3138807
11
4207320
11
3522475
11
4703863
11
4846786
11
5266804
11
5500361
11
4643860
11
1987995
11
4449675
11
6450787
11
972418
11
5509894
11
2543996
11
2224998
11
1259294
11
5683957
11
1413140
11
2877497
11
8128440
11
5157715
11
1486742
11
2192804
11
5823001
11
807333...

output:

(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)
(((((((((((|)|)|)|)|)|)|)|)|)|)|)
(|(|(|(|(|(|(|(|(|(|(|)))))))))))
((|)|)((|(|))(|)(|)(|)|((|)(|)|))
(|((((|)|)|)|((|(|(((|)|)|)))|)))
((|)|(((|)|(|((|((|)|))|)(|)))|))
(((|)|)|)((|(|)(((|)|)|))(|(|))|)
((|)((|)|)|((|)((|)|)|(|(|(|)))))
((|(|)(|)(|))|((|(|))(|)|)(|...

result:

ok 1000 lines

Test #18:

score: 100
Accepted
time: 3ms
memory: 3820kb

input:

encode
1000
12
(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)
12
((((((((((((|)|)|)|)|)|)|)|)|)|)|)|)
12
(|(|(|(|(|(|(|(|(|(|(|(|))))))))))))
12
((|)|)((|)(|(|))(|(|))(|)((|)(|)|)|)
12
(((|(|((|)|))(|))(|)|)|)(((|)|)|(|))
12
((|)|)(|(|)((|(|((|)(|)|)))(|(|))|))
12
((|(|((|)|(|))(|)((|)|)(|)(|)(|)))|)
12
(|((|...

output:

0
50067107
18565647
25033554
35028684
24323098
44825853
21477528
27289202
24577426
47564582
15937726
9946337
4501212
31300634
4999013
279153
20968361
33204334
14336744
38337322
38963489
18571663
8631867
30864812
37846762
30150501
45027409
49281210
24973307
9774746
38397479
7559984
26729117
1809900
1...

input:

decode
1000
12
0
12
50067107
12
18565647
12
25033554
12
35028684
12
24323098
12
44825853
12
21477528
12
27289202
12
24577426
12
47564582
12
15937726
12
9946337
12
4501212
12
31300634
12
4999013
12
279153
12
20968361
12
33204334
12
14336744
12
38337322
12
38963489
12
18571663
12
8631867
12
30864812
1...

output:

(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)
((((((((((((|)|)|)|)|)|)|)|)|)|)|)|)
(|(|(|(|(|(|(|(|(|(|(|(|))))))))))))
((|)|)((|)(|(|))(|(|))(|)((|)(|)|)|)
(((|(|((|)|))(|))(|)|)|)(((|)|)|(|))
((|)|)(|(|)((|(|((|)(|)|)))(|(|))|))
((|(|((|)|(|))(|)((|)|)(|)(|)(|)))|)
(|((|)((|)|(|(|))((|)|))|(|))(|)(|))
((|)...

result:

ok 1000 lines

Test #19:

score: 100
Accepted
time: 3ms
memory: 4044kb

input:

encode
1000
13
(((|)|(|((|)|)(|))(|)((|)|))(|((|)|))|)
13
(|((|)((|)|)((((|)|)((|)|)|)(|)|(|))|))
13
(|(|(|(|))(|)(|)(|(|((|)|)))(|(|))))(|)
13
((|(((|)|)(|(|))|((|)|(|))))((|(|))|)|)
13
(|)(((((|)|)|)(|)(|)(|(((|)|)|(|)))|)|)
13
((|((|)(|)(|)((|)|)|))|)(|)(|((|)(|)|))
13
(|(|)(|)((|(|(|(|)))(|))(|(...

output:

276760186
134809902
86865302
263865986
49462892
205673056
93583218
12212268
110223754
178158826
195352959
62437335
64227968
31655175
252916074
172059090
49489187
93065726
205226276
152429787
120524121
99764872
174099593
52192258
257494005
57163054
258238534
80887537
222773181
54370651
288251925
1005...

input:

decode
1000
13
276760186
13
134809902
13
86865302
13
263865986
13
49462892
13
205673056
13
93583218
13
12212268
13
110223754
13
178158826
13
195352959
13
62437335
13
64227968
13
31655175
13
252916074
13
172059090
13
49489187
13
93065726
13
205226276
13
152429787
13
120524121
13
99764872
13
174099593...

output:

(((|)|(|((|)|)(|))(|)((|)|))(|((|)|))|)
(|((|)((|)|)((((|)|)((|)|)|)(|)|(|))|))
(|(|(|(|))(|)(|)(|(|((|)|)))(|(|))))(|)
((|(((|)|)(|(|))|((|)|(|))))((|(|))|)|)
(|)(((((|)|)|)(|)(|)(|(((|)|)|(|)))|)|)
((|((|)(|)(|)((|)|)|))|)(|)(|((|)(|)|))
(|(|)(|)((|(|(|(|)))(|))(|((|)|))|(|)))
(|)(|((|(|(|)(|)))|)...

result:

ok 1000 lines

Test #20:

score: 100
Accepted
time: 4ms
memory: 3964kb

input:

encode
1000
14
(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)
14
((((((((((((((|)|)|)|)|)|)|)|)|)|)|)|)|)|)
14
(|(|(|(|(|(|(|(|(|(|(|(|(|(|))))))))))))))
14
((|)|(|))(|((|)|))((|)((|)|(|)(|(|)))(|)|)
14
(|((|)|(|)((((|)|)|)(|)(|)|(|(((|)|)|)))))
14
(((|)|(|))|(|(|)(|))(|(|)))(|(((|)|(|))|))
14
(|)(|)(|(...

output:

0
1822766519
669682579
911383260
717606149
1097898903
12327981
1499648914
1377918540
1186758758
731217804
1499277309
520544541
1506477088
812380857
445973534
729613835
1380846779
646968531
536901802
70123125
924215437
36516911
1174050886
102977673
603306286
368085643
1001524429
1402074870
788545935
...

input:

decode
1000
14
0
14
1822766519
14
669682579
14
911383260
14
717606149
14
1097898903
14
12327981
14
1499648914
14
1377918540
14
1186758758
14
731217804
14
1499277309
14
520544541
14
1506477088
14
812380857
14
445973534
14
729613835
14
1380846779
14
646968531
14
536901802
14
70123125
14
924215437
14
3...

output:

(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)
((((((((((((((|)|)|)|)|)|)|)|)|)|)|)|)|)|)
(|(|(|(|(|(|(|(|(|(|(|(|(|(|))))))))))))))
((|)|(|))(|((|)|))((|)((|)|(|)(|(|)))(|)|)
(|((|)|(|)((((|)|)|)(|)(|)|(|(((|)|)|)))))
(((|)|(|))|(|(|)(|))(|(|)))(|(((|)|(|))|))
(|)(|)(|(|)(|(|))((|)(|)(|)|))(|((|)|))(|)...

result:

ok 1000 lines

Test #21:

score: 100
Accepted
time: 3ms
memory: 3824kb

input:

encode
1000
15
((|(|))|(|(|((|((|)(|)|)(|(|)))|)))((|)|(|)))
15
(|)(|)(|(|(|)(|((|)(|((|)|))|)(|)))((|)(|)|))
15
((|)|)((|)(|)(|(|(|)(|)(|))((|)|))(|)|(|(|)))
15
(|(|)((|)|(((|)|)(|)(|)(|)|(|)))((|)|))((|)|)
15
((|(|(|)((|)|)((|)|((|(|))(|)|))))|)(|(|))(|)
15
(|)((|)|(|(|)))(((|)((|)|)|)|(|(|)(|((|)...

output:

6425124984
105210525
5454943576
2964749895
8134228987
920387118
986674272
2820643318
9506148457
10156164121
5285653115
10827774916
5224939986
5091892295
6511326032
9678212384
4484694386
9054161639
3047325936
10774632540
5287863062
1671186270
7171501936
8208250436
6131864634
8308390363
9151854076
870...

input:

decode
1000
15
6425124984
15
105210525
15
5454943576
15
2964749895
15
8134228987
15
920387118
15
986674272
15
2820643318
15
9506148457
15
10156164121
15
5285653115
15
10827774916
15
5224939986
15
5091892295
15
6511326032
15
9678212384
15
4484694386
15
9054161639
15
3047325936
15
10774632540
15
52878...

output:

((|(|))|(|(|((|((|)(|)|)(|(|)))|)))((|)|(|)))
(|)(|)(|(|(|)(|((|)(|((|)|))|)(|)))((|)(|)|))
((|)|)((|)(|)(|(|(|)(|)(|))((|)|))(|)|(|(|)))
(|(|)((|)|(((|)|)(|)(|)(|)|(|)))((|)|))((|)|)
((|(|(|)((|)|)((|)|((|(|))(|)|))))|)(|(|))(|)
(|)((|)|(|(|)))(((|)((|)|)|)|(|(|)(|((|)|))))
(|)((|)|((|)((|(|)((|)(|...

result:

ok 1000 lines

Test #22:

score: 0
Stage 2: Program answer Runtime Error

input:

encode
1000
16
(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)
16
((((((((((((((((|)|)|)|)|)|)|)|)|)|)|)|)|)|)|)|)
16
(|(|(|(|(|(|(|(|(|(|(|(|(|(|(|(|))))))))))))))))
16
((|)|(|(|)))(|)((|)(|(|(|(|))))((|)|(|))(|(|))|)
16
((((|)|)(|)|(|)(|)(|(|)((|)((|)|)|))(|))(|)|(|))
16
(|(|))(|((|)|(|((|)(|(|(|...

output:

0
68328754958
24931096953
34164377479
56484756272
11843406352
30757520625
65936331392
34289423728
38090676859
18056661858
22808466940
61181409532
53381843764
142613790
58359972905
42577928527
19186841720
6387154105
12183669973
47175250026
30257325990
51794452586
21527235857
54179717019
7562000184
29...

input:

decode
1000
16
0
16
68328754958
16
24931096953
16
34164377479
16
56484756272
16
11843406352
16
30757520625
16
65936331392
16
34289423728
16
38090676859
16
18056661858
16
22808466940
16
61181409532
16
53381843764
16
142613790
16
58359972905
16
42577928527
16
19186841720
16
6387154105
16
12183669973
1...

output:

(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)(|)

result: