QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#108161#2927. Bracket PairingrootcucuAC ✓5ms3616kbC++171.1kb2023-05-23 18:54:242023-05-23 18:54:26

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-23 18:54:26]
  • Judged
  • Verdict: AC
  • Time: 5ms
  • Memory: 3616kb
  • [2023-05-23 18:54:24]
  • Submitted

answer

#include <iostream>
#include <string>
using namespace std;

const string p = "([{<?>}])"; 
int n;
long long ans = 0;
int st[20], sp = 0;
string s;
void f(int op, int cl, int hist){
    if (op + cl == n){
        int m = 1, c, h = hist;
        /*
        for (int i = 0; i < n; i++){
            cout << "()"[(h >> (n-1-i))%2];
        }
        cout << "\n";
        cout << s << "\n";
        */
        for (int i = n; i-- > 0; ){
            c = p.find(s[i]) - 4; 
            if (h % 2){
                st[sp++] = c;
            }
            else {
                int top = st[--sp];
                if (top < 0 || c > 0 || top > 0 && c < 0 && top + c != 0)
                    m *= 0;
//                    return;
                if (top == 0 && c == 0)
                    m *= 4;
            }
            h /= 2;
        }
        // cout << "add " << m << "\n";
        ans += m;
        return;
    }
    if (n >= op * 2 + 2){
        f(op+1, cl, hist*2);
    }
    if (op > cl){
        f(op, cl+1, hist*2+1);
    }
}

int main(void){
    cin >> s;
    n = s.length();
    f(0,0,0);
    cout << ans;
}


詳細信息

Test #1:

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

input:

??

output:

4

result:

ok single line: '4'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3380kb

input:

????

output:

32

result:

ok single line: '32'

Test #3:

score: 0
Accepted
time: 1ms
memory: 3372kb

input:

????????

output:

3584

result:

ok single line: '3584'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3376kb

input:

]????]

output:

0

result:

ok single line: '0'

Test #5:

score: 0
Accepted
time: 2ms
memory: 3372kb

input:

?????[

output:

0

result:

ok single line: '0'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3612kb

input:

([???]

output:

1

result:

ok single line: '1'

Test #7:

score: 0
Accepted
time: 0ms
memory: 3380kb

input:

??({?]

output:

0

result:

ok single line: '0'

Test #8:

score: 0
Accepted
time: 1ms
memory: 3388kb

input:

??({?]??

output:

4

result:

ok single line: '4'

Test #9:

score: 0
Accepted
time: 2ms
memory: 3376kb

input:

?[()?)()]]

output:

1

result:

ok single line: '1'

Test #10:

score: 0
Accepted
time: 2ms
memory: 3372kb

input:

?()?????

output:

320

result:

ok single line: '320'

Test #11:

score: 0
Accepted
time: 2ms
memory: 3612kb

input:

?????()?

output:

320

result:

ok single line: '320'

Test #12:

score: 0
Accepted
time: 2ms
memory: 3416kb

input:

???([]){}???

output:

320

result:

ok single line: '320'

Test #13:

score: 0
Accepted
time: 2ms
memory: 3536kb

input:

????????????????????

output:

17611882496

result:

ok single line: '17611882496'

Test #14:

score: 0
Accepted
time: 2ms
memory: 3444kb

input:

<{[{()}]}<>{}>{?()[]

output:

1

result:

ok single line: '1'

Test #15:

score: 0
Accepted
time: 5ms
memory: 3380kb

input:

[<{}<><?[]>?[]{}<{}>

output:

1

result:

ok single line: '1'

Test #16:

score: 0
Accepted
time: 5ms
memory: 3384kb

input:

()<{}{}><???[]>>[()]

output:

9

result:

ok single line: '9'

Test #17:

score: 0
Accepted
time: 5ms
memory: 3376kb

input:

([{?}}<??){<>}[?}<>]

output:

1

result:

ok single line: '1'

Test #18:

score: 0
Accepted
time: 5ms
memory: 3608kb

input:

{}(?(?()[]??]<>){[]?

output:

21

result:

ok single line: '21'

Test #19:

score: 0
Accepted
time: 1ms
memory: 3428kb

input:

<??>]??{{}[]}>>()?{}

output:

1

result:

ok single line: '1'

Test #20:

score: 0
Accepted
time: 0ms
memory: 3616kb

input:

{???{(({?><>?>})){}}

output:

8

result:

ok single line: '8'

Test #21:

score: 0
Accepted
time: 2ms
memory: 3384kb

input:

?<()[]?<{?>??>>())[]

output:

11

result:

ok single line: '11'

Test #22:

score: 0
Accepted
time: 5ms
memory: 3436kb

input:

?[()?)()][]{[?}>?]{?

output:

1

result:

ok single line: '1'

Test #23:

score: 0
Accepted
time: 5ms
memory: 3560kb

input:

{?(?>)<>>{}<?{}}?]{?

output:

1

result:

ok single line: '1'

Test #24:

score: 0
Accepted
time: 2ms
memory: 3440kb

input:

[?}[[???[??????]??>?

output:

34880

result:

ok single line: '34880'

Test #25:

score: 0
Accepted
time: 0ms
memory: 3372kb

input:

??<???????<>??[??]{?

output:

629760

result:

ok single line: '629760'

Test #26:

score: 0
Accepted
time: 1ms
memory: 3428kb

input:

?????????[?)?}?>[???

output:

889856

result:

ok single line: '889856'

Test #27:

score: 0
Accepted
time: 4ms
memory: 3380kb

input:

????????????}(??????

output:

275382272

result:

ok single line: '275382272'

Test #28:

score: 0
Accepted
time: 2ms
memory: 3616kb

input:

?[??]?{??)??????????

output:

8609792

result:

ok single line: '8609792'

Test #29:

score: 0
Accepted
time: 5ms
memory: 3372kb

input:

???????(??)??{?????>

output:

16621568

result:

ok single line: '16621568'

Test #30:

score: 0
Accepted
time: 4ms
memory: 3440kb

input:

????[]?[<???????????

output:

21446656

result:

ok single line: '21446656'

Test #31:

score: 0
Accepted
time: 5ms
memory: 3440kb

input:

???????}>??????)?)??

output:

4677632

result:

ok single line: '4677632'

Test #32:

score: 0
Accepted
time: 5ms
memory: 3600kb

input:

[??????(??????????{}

output:

41435136

result:

ok single line: '41435136'

Test #33:

score: 0
Accepted
time: 4ms
memory: 3436kb

input:

(?>?[???????????}???

output:

8740864

result:

ok single line: '8740864'

Test #34:

score: 0
Accepted
time: 2ms
memory: 3380kb

input:

()()(?

output:

1

result:

ok single line: '1'

Test #35:

score: 0
Accepted
time: 1ms
memory: 3612kb

input:

(??)

output:

5

result:

ok single line: '5'

Test #36:

score: 0
Accepted
time: 2ms
memory: 3552kb

input:

(<{}>??]

output:

1

result:

ok single line: '1'

Test #37:

score: 0
Accepted
time: 2ms
memory: 3424kb

input:

(?]]

output:

0

result:

ok single line: '0'