QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#546850#4824. Bracket-and-bar Sequencesluqyou0 3ms3840kbC++141.9kb2024-09-04 14:40:232024-09-04 14:40:23

Judging History

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

  • [2024-09-04 14:40:23]
  • 评测
  • 测评结果:0
  • 用时:3ms
  • 内存:3840kb
  • [2024-09-04 14:40:23]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
#define fi first
#define sc second
#define pii pair<int,int>
#define pb push_back
string op,s;
int n;
vector<int> v;
void work(int l,int r){
    if(l>r) return v.pb(2),void();
    stack<int> st;
    int cnt=0,p=0;
    for(int i=l;i<r;i++){
        if(s[i]=='(') cnt++;
        else if(s[i]==')') cnt--;
        if(cnt==0) p=i;
    }
    if(!p){
        cnt=0;
        for(int i=l;i<=r;i++){
            if(s[i]=='(') cnt++;
            else if(s[i]==')') cnt--;
            else if(cnt==1) p=i;
        }
        work(l+1,p-1),work(p+1,r-1),v.pb(1);
    }
    else work(l,p),work(p+1,r),v.pb(0);
}
void solve(){
    v.clear();
    if(op=="encode"){
        cin>>n>>s,n*=3,s=" "+s;
        work(1,n);
        int num=0;
        for(int x:v) num=(num*3+x);
        cout<<num<<endl;
    }
    else{
        int num;
        cin>>n>>num;
        stack<string> st;
        while(num) v.pb(num%3),num/=3;
        reverse(v.begin(),v.end());
        for(int x:v){
            if(x==0){
                string s1=st.top(),s2;
                st.pop(),s2=st.top(),st.pop();
                st.push(s1+s2);
            }
            if(x==1){
                string s1=st.top(),s2;
                st.pop(),s2=st.top(),st.pop();
                st.push("("+s1+"|"+s2+")");
            }
            if(x==2) st.push("");
        }
        string res=st.top();
        reverse(res.begin(),res.end());
        for(char c:res) cout<<((c=='('?')':(c=='|'?'|':'(')));
        cout<<endl;
    }
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    int t=1;
    cin>>op>>t;
    while(t--) solve();
    return 0;
}
/*
Samples
input:

output:

THINGS TODO:
检查freopen,尤其是后缀名
检查空间
检查调试语句是否全部注释
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

25
18862
1567965

input:

decode
3
1
25
4
18862
5
1567965

output:

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

result:

ok 3 lines

Test #2:

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

input:

encode
1
1
(|)

output:

25

input:

decode
1
1
25

output:

(|)

result:

ok single line: '(|)'

Test #3:

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

input:

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

output:

232
25
238

input:

decode
3
2
232
1
25
2
238

output:

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

result:

ok 3 lines

Test #4:

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

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:

170175
18939
18921
19353
19423
2173
2155
18867
2101
18907
2149
2095
13784250
1531614
1531596
1534134
1534494
170544
170490
1532676
170328
1532946
170472
170310
1567668
174216
174198
1573338
176088
174630
1573408
174916
174862
176158
176368
19642
19588
174700
19426
174820
19570
19408
1528302
169842
1...

input:

decode
1000
3
170175
3
18939
3
18921
3
19353
3
19423
3
2173
3
2155
3
18867
3
2101
3
18907
3
2149
3
2095
4
13784250
4
1531614
4
1531596
4
1534134
4
1534494
4
170544
4
170490
4
1532676
4
170328
4
1532946
4
170472
4
170310
4
1567668
4
174216
4
174198
4
1573338
4
176088
4
174630
4
1573408
4
174916
4
174...

output:

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

result:

ok 1000 lines

Test #5:

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

input:

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

output:

14149630
127446196
14168344
14163970
14268946
14285956
1591150
1586776
14150848
1573654
14160568
1585318
1572196
1147015750
127447042
127446556
127515082
127524802
14170648
14169190
127475716
14164816
127483006
14168704
14164330
128420500
14269792
14269306
128573590
14320336
14280970
128575480
14288...

input:

decode
1000
6
14149630
6
127446196
6
14168344
6
14163970
6
14268946
6
14285956
6
1591150
6
1586776
6
14150848
6
1573654
6
14160568
6
1585318
6
1572196
6
1147015750
6
127447042
6
127446556
6
127515082
6
127524802
6
14170648
6
14169190
6
127475716
6
14164816
6
127483006
6
14168704
6
14164330
6
1284205...

output:

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

result:

ok 1000 lines

Test #6:

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

input:

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

output:

1119025525
90610654003
1157266315
1142892255
10067939355
127440583
1118502709
90440333292
1114221549
1117322877
1147144143
1118659717
813946345158
10055864955
1159947577
127483105
10410829473
10048426599
128900227
13795321
127367623
1147822563
1118650129
1114129555
14151715
1114247289
1118614017
115...

input:

decode
1000
7
1119025525
7
90610654003
7
1157266315
7
1142892255
7
10067939355
7
127440583
7
1118502709
8
90440333292
7
1114221549
7
1117322877
7
1147144143
7
1118659717
8
813946345158
7
10055864955
7
1159947577
7
127483105
7
10410829473
7
10048426599
7
128900227
7
13795321
7
127367623
7
1147822563
...

output:

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

result:

ok 1000 lines

Test #7:

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

input:

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

output:

1147024351
1114221697
1142941467
124348107
127466821
10068055563
1116523993
1142574807
1119026541
10048459773
10071267627
124059505
813969646536
7325517963612
1114409127
1147177317
1147276047
1116534855
90440333148
90441074388
1155329319
1157221387
1117553551
123759853
10055893053
1117540389
1426773...

input:

decode
1000
7
1147024351
7
1114221697
7
1142941467
7
124348107
7
127466821
7
10068055563
7
1116523993
7
1142574807
7
1119026541
7
10048459773
7
10071267627
7
124059505
8
813969646536
8
7325517963612
7
1114409127
7
1147177317
7
1147276047
7
1116534855
8
90440333148
8
90441074388
7
1155329319
7
115722...

output:

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

result:

ok 1000 lines

Test #8:

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

input:

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

output:

10057686991
1118945631
1114362507
128372169
1116497433
124157767
128582041
10057686847
813946440432
1155785419
1142564929
10286469903
1114134231
123816859
123765933
1118505045
128430559
126954361
124156705
1117527753
128900047
10027207857
127516647
10323178401
1118620929
1116494755
1118674263
114257...

input:

decode
1000
7
10057686991
7
1118945631
7
1114362507
7
128372169
7
1116497433
7
124157767
7
128582041
7
10057686847
8
813946440432
7
1155785419
7
1142564929
7
10286469903
7
1114134231
7
123816859
7
123765933
7
1118505045
7
128430559
7
126954361
7
124156705
7
1117527753
7
128900047
7
10027207857
7
127...

output:

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

result:

ok 1000 lines

Test #9:

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

input:

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

output:

1147629675
127013313
10071236649
813965336328
14267875
1142535423
126991039
10285446373
92588414961
1117322215
1147664653
1118495127
10048423647
10286509251
128371747
10027195239
10066455777
10067821435
128424139
813965475198
1157160621
10057675791
1147655379
813946332054
128368867
128430505
1241580...

input:

decode
1000
7
1147629675
7
127013313
7
10071236649
8
813965336328
7
14267875
7
1142535423
7
126991039
7
10285446373
7
92588414961
7
1117322215
7
1147664653
7
1118495127
7
10048423647
7
10286509251
7
128371747
7
10027195239
7
10066455777
7
10067821435
7
128424139
8
813965475198
7
1157160621
7
1005767...

output:

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

result:

ok 1000 lines

Test #10:

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

input:

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

output:

1117514671
10048453495
10071232995
1147318651
124278339
92908275339
1147727497
1117027335
124277475
1143060321
1146967491
10322683329
124159377
1114370247
10287424515
128900721
128369563
127342335
129054451
1118479503
813946352070
10029318087
1118387689
127348885
7325518228518
1156707201
1114368825
...

input:

decode
1000
7
1117514671
7
10048453495
7
10071232995
7
1147318651
7
124278339
7
92908275339
7
1147727497
7
1117027335
7
124277475
7
1143060321
7
1146967491
7
10322683329
7
124159377
7
1114370247
7
10287424515
7
128900721
7
128369563
7
127342335
7
129054451
7
1118479503
8
813946352070
7
10029318087
7...

output:

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

result:

ok 1000 lines

Test #11:

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

input:

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

output:

1147018033
127366123
90521552343
10285488183
128953209
1118385111
90518986263
14168587
10055892981
1114243419
1117514685
127445197
10325481555
10055893035
813946344366
128881281
14326267
10056687267
1116548377
1117519405
124353907
90438480241
1114221009
14164357
10058304513
1116554349
7325518226322
...

input:

decode
1000
7
1147018033
7
127366123
7
90521552343
7
10285488183
7
128953209
7
1118385111
7
90518986263
7
14168587
7
10055892981
7
1114243419
7
1117514685
7
127445197
7
10325481555
7
10055893035
8
813946344366
7
128881281
7
14326267
7
10056687267
7
1116548377
7
1117519405
7
124353907
7
90438480241
7...

output:

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

result:

ok 1000 lines

Test #12:

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

input:

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

output:

1160568337
1161489855
1147634551
1147832473
1117521183
92569283089
126948675
1155821335
10330492285
1147370653
1147348183
124178935
1117610427
124177489
7325517135468
126992401
123759327
127538209
1155319519
13810567
1143063201
10055919747
1117422345
1146238273
1117322581
1118648185
1116495895
11425...

input:

decode
1000
7
1160568337
7
1161489855
7
1147634551
7
1147832473
7
1117521183
7
92569283089
7
126948675
7
1155821335
7
10330492285
7
1147370653
7
1147348183
7
124178935
7
1117610427
7
124177489
8
7325517135468
7
126992401
7
123759327
7
127538209
7
1155319519
7
13810567
7
1143063201
7
10055919747
7
11...

output:

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

result:

ok 1000 lines

Test #13:

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

input:

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

output:

1156758213
10048453581
14111647
813946466154
13751041
127360825
1156758877
124061611
10445106637
127484317
127444417
10287598413
124159225
10048720107
128605513
1114191849
127483051
10067851861
1116534121
128405289
1117410375
1117589691
1117435467
124055113
10058493729
1117068159
126991057
100676080...

input:

decode
1000
7
1156758213
7
10048453581
7
14111647
8
813946466154
7
13751041
7
127360825
7
1156758877
7
124061611
7
10445106637
7
127484317
7
127444417
7
10287598413
7
124159225
7
10048720107
7
128605513
7
1114191849
7
127483051
7
10067851861
7
1116534121
7
128405289
7
1117410375
7
1117589691
7
11174...

output:

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

result:

ok 1000 lines

Test #14:

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

input:

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

output:

10410390894
7339543950216
90641099568
90607844802
92966379016
1117082050
90598092118
814528358332
90267309480
1143069690
90438482626
10028192026
10316586286
10072844094
92929799380
90263363502
90589370070
123818206
10439085324
90610479804
10397878372
10058025990
92964080602
10285449006
10326337390
1...

input:

decode
1000
8
10410390894
8
7339543950216
8
90641099568
8
90607844802
8
92966379016
8
1117082050
8
90598092118
8
814528358332
8
90267309480
8
1143069690
8
90438482626
8
10028192026
8
10316586286
8
10072844094
8
92929799380
8
90263363502
8
90589370070
8
123818206
8
10439085324
8
90610479804
8
1039787...

output:

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

result:

ok 1000 lines

Test #15:

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

input:

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

output:

90610680733
10065470335
10415501221
812018077081
815388488211
66053425768635
815299810837
833204333379
92922966703
7527744210787
93965909827
93581906871
93581788633
832939136965
92973907765
836425921717
93968249169
814682899407
7342763252493
90440974069
92979056083
815494318275
90525118503
812200184...

input:

decode
1000
9
90610680733
9
10065470335
9
10415501221
9
812018077081
9
815388488211
9
66053425768635
9
815299810837
9
833204333379
9
92922966703
9
7527744210787
9
93965909827
9
93581906871
9
93581788633
9
832939136965
9
92973907765
9
836425921717
9
93968249169
9
814682899407
9
7342763252493
9
904409...

output:

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

result:

ok 1000 lines

Test #16:

score: 0
Wrong Answer on the first run

input:

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

output:

3893079603015914700
10024505152
10460323678
812286250950
814730731356
65983733924286
7339075843930
93578194258
65980009587216
7498773865632
90608479150
593366954964816
846763307094
7332313520712
92935508556
835263593238
835272130134
610000100340850
90524944450
815494085770
7531041179278
815303274346...

input:


output:


result:

wrong answer Integer parameter [name=x_i] equals to 3893079603015914700, violates the range [0, 2*10^18] (test case 1)