QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#53696#2927. Bracket PairingSilverhorse7#AC ✓1618ms178372kbC++1.3kb2022-10-05 19:42:132022-10-05 19:42:15

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.
  • [2022-10-05 19:42:15]
  • Judged
  • Verdict: AC
  • Time: 1618ms
  • Memory: 178372kb
  • [2022-10-05 19:42:13]
  • Submitted

answer

#include "bits/stdc++.h"

using namespace std;
#define int long long
char avail[] = {'(', ')', '[', ']', '{', '}', '<', '>', '.', '?'};

bool isMatch(char s, char e) {
    if (s == '(' and e == ')')return 1;
    if (s == '<' and e == '>')return 1;
    if (s == '{' and e == '}')return 1;
    if (s == '[' and e == ']')return 1;
    return 0;
}

string t;
map<pair<int, string>, int> dp;

long long rec(int id, string s) {
    if (s.size() > id + 1)return 0;
    if (id < 0)return s.empty();
    if (dp.find({id, s}) != dp.end())return dp[{id, s}];
    long long &ret = dp[{id, s}];
    if (t[id] == '?') {
        for (int i = 1; i < 8; i += 2) {
            s += avail[i];
            ret += rec(id - 1, s);
            s.pop_back();
        }
        if (s.size() > 0 and (s.back() == ')' or s.back() == ']' or s.back() == '}' or s.back() == '>')) {
            s.pop_back();
            ret += rec(id - 1, s);
        }
    }
    if (t[id] == ')' or t[id] == ']' or t[id] == '}' or t[id] == '>') {
        s.push_back(t[id]);
        ret = rec(id - 1, s);
    } else {
        if (s.size() > 0 and isMatch(t[id], s.back())) {
            s.pop_back();
            ret = rec(id - 1, s);
        }
    }
    return ret;
}

signed main() {

    cin >> t;
    cout << rec((int) t.size() - 1, "") << endl;
}

詳細信息

Test #1:

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

input:

??

output:

4

result:

ok single line: '4'

Test #2:

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

input:

????

output:

32

result:

ok single line: '32'

Test #3:

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

input:

????????

output:

3584

result:

ok single line: '3584'

Test #4:

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

input:

]????]

output:

0

result:

ok single line: '0'

Test #5:

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

input:

?????[

output:

0

result:

ok single line: '0'

Test #6:

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

input:

([???]

output:

1

result:

ok single line: '1'

Test #7:

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

input:

??({?]

output:

0

result:

ok single line: '0'

Test #8:

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

input:

??({?]??

output:

4

result:

ok single line: '4'

Test #9:

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

input:

?[()?)()]]

output:

1

result:

ok single line: '1'

Test #10:

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

input:

?()?????

output:

320

result:

ok single line: '320'

Test #11:

score: 0
Accepted
time: 3ms
memory: 3500kb

input:

?????()?

output:

320

result:

ok single line: '320'

Test #12:

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

input:

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

output:

320

result:

ok single line: '320'

Test #13:

score: 0
Accepted
time: 1618ms
memory: 178372kb

input:

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

output:

17611882496

result:

ok single line: '17611882496'

Test #14:

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

input:

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

output:

1

result:

ok single line: '1'

Test #15:

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

input:

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

output:

1

result:

ok single line: '1'

Test #16:

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

input:

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

output:

9

result:

ok single line: '9'

Test #17:

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

input:

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

output:

1

result:

ok single line: '1'

Test #18:

score: 0
Accepted
time: 3ms
memory: 3640kb

input:

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

output:

21

result:

ok single line: '21'

Test #19:

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

input:

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

output:

1

result:

ok single line: '1'

Test #20:

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

input:

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

output:

8

result:

ok single line: '8'

Test #21:

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

input:

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

output:

11

result:

ok single line: '11'

Test #22:

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

input:

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

output:

1

result:

ok single line: '1'

Test #23:

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

input:

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

output:

1

result:

ok single line: '1'

Test #24:

score: 0
Accepted
time: 207ms
memory: 33636kb

input:

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

output:

34880

result:

ok single line: '34880'

Test #25:

score: 0
Accepted
time: 6ms
memory: 4936kb

input:

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

output:

629760

result:

ok single line: '629760'

Test #26:

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

input:

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

output:

889856

result:

ok single line: '889856'

Test #27:

score: 0
Accepted
time: 149ms
memory: 23260kb

input:

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

output:

275382272

result:

ok single line: '275382272'

Test #28:

score: 0
Accepted
time: 1060ms
memory: 158792kb

input:

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

output:

8609792

result:

ok single line: '8609792'

Test #29:

score: 0
Accepted
time: 50ms
memory: 11564kb

input:

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

output:

16621568

result:

ok single line: '16621568'

Test #30:

score: 0
Accepted
time: 1427ms
memory: 178352kb

input:

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

output:

21446656

result:

ok single line: '21446656'

Test #31:

score: 0
Accepted
time: 149ms
memory: 24108kb

input:

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

output:

4677632

result:

ok single line: '4677632'

Test #32:

score: 0
Accepted
time: 344ms
memory: 47188kb

input:

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

output:

41435136

result:

ok single line: '41435136'

Test #33:

score: 0
Accepted
time: 677ms
memory: 80084kb

input:

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

output:

8740864

result:

ok single line: '8740864'

Test #34:

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

input:

()()(?

output:

1

result:

ok single line: '1'

Test #35:

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

input:

(??)

output:

5

result:

ok single line: '5'

Test #36:

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

input:

(<{}>??]

output:

1

result:

ok single line: '1'

Test #37:

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

input:

(?]]

output:

0

result:

ok single line: '0'