QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#79999#2927. Bracket PairingperspectiveAC ✓2ms3464kbC++232.1kb2023-02-21 16:41:222023-02-21 16:42:00

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-02-21 16:42:00]
  • Judged
  • Verdict: AC
  • Time: 2ms
  • Memory: 3464kb
  • [2023-02-21 16:41:22]
  • Submitted

answer

#include<bits/stdc++.h>

using namespace std;

#define task "sol"
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define zs(v) ((int)(v).size())
#define BIT(x, i) (((x) >> (i)) & 1)
#define CNTBIT __builtin_popcountll
#define ALL(v) (v).begin(),(v).end()
#define endl '\n'

typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;

const int dx[4]={-1, 0, 1, 0}, dy[4]={0, 1, 0, -1};
const int dxx[8]={-1, -1, 0, 1, 1, 1, 0, -1}, dyy[8]={0, 1, 1, 1, 0, -1, -1, -1};
const ll mod = 1000000007; /// 998244353
const ll base = 331;

ll dp[25][25];
string s;
int n;

bool isClose(char c) {
    return (c == ')' || c == '>' || c == ']' || c == '}');
}
bool isOpen(char c) {
    return (c == '(' || c == '<' || c == '[' || c == '{');
}
bool check(char x, char y) {
    if (x == '(' && y == ')') {
        return 1;
    }
    if (x == '[' && y == ']') {
        return 1;
    }
    if (x == '{' && y == '}') {
        return 1;
    }
    if (x == '<' && y == '>') {
        return 1;
    }
    return 0;
}

int getMult(char x, char y) {
    if (x == y && x == '?') return 4;
    if (check(x, y)) return 1;
    if (isOpen(x) && y == '?') return 1;
    if (x == '?' && isClose(y)) return 1;
    return 0;
}

void solve() {
    cin >> s;
    n = s.size();
    if (!n) {
        cout << 1;
        return;
    }
    s = ' ' + s;
    memset(dp, 0ll, sizeof(dp));
    for (int i = 1; i <= n; ++i) {
        dp[i][i - 1] = 1;
    }
    for (int len = 2; len <= n; len += 2) {
        for (int i = 1; i <= n - len + 1; ++i) {
            int j = i + len - 1;
            for (int k = i + 1; k < j; k += 2) {
                dp[i][j] += dp[i + 1][k - 1] * getMult(s[i], s[k]) * dp[k + 1][j];
                // dp[i][j] += dp[i][k] * getMult(s[k + 1], s[j]) * dp[k + 2][j - 1];
            }
            dp[i][j] += getMult(s[i], s[j]) * dp[i + 1][j - 1];
        }
    }
    cout << dp[1][n];
}
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    solve();
}

详细

Test #1:

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

input:

??

output:

4

result:

ok single line: '4'

Test #2:

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

input:

????

output:

32

result:

ok single line: '32'

Test #3:

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

input:

????????

output:

3584

result:

ok single line: '3584'

Test #4:

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

input:

]????]

output:

0

result:

ok single line: '0'

Test #5:

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

input:

?????[

output:

0

result:

ok single line: '0'

Test #6:

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

input:

([???]

output:

1

result:

ok single line: '1'

Test #7:

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

input:

??({?]

output:

0

result:

ok single line: '0'

Test #8:

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

input:

??({?]??

output:

4

result:

ok single line: '4'

Test #9:

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

input:

?[()?)()]]

output:

1

result:

ok single line: '1'

Test #10:

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

input:

?()?????

output:

320

result:

ok single line: '320'

Test #11:

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

input:

?????()?

output:

320

result:

ok single line: '320'

Test #12:

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

input:

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

output:

320

result:

ok single line: '320'

Test #13:

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

input:

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

output:

17611882496

result:

ok single line: '17611882496'

Test #14:

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

input:

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

output:

1

result:

ok single line: '1'

Test #15:

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

input:

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

output:

1

result:

ok single line: '1'

Test #16:

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

input:

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

output:

9

result:

ok single line: '9'

Test #17:

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

input:

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

output:

1

result:

ok single line: '1'

Test #18:

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

input:

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

output:

21

result:

ok single line: '21'

Test #19:

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

input:

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

output:

1

result:

ok single line: '1'

Test #20:

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

input:

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

output:

8

result:

ok single line: '8'

Test #21:

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

input:

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

output:

11

result:

ok single line: '11'

Test #22:

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

input:

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

output:

1

result:

ok single line: '1'

Test #23:

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

input:

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

output:

1

result:

ok single line: '1'

Test #24:

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

input:

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

output:

34880

result:

ok single line: '34880'

Test #25:

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

input:

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

output:

629760

result:

ok single line: '629760'

Test #26:

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

input:

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

output:

889856

result:

ok single line: '889856'

Test #27:

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

input:

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

output:

275382272

result:

ok single line: '275382272'

Test #28:

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

input:

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

output:

8609792

result:

ok single line: '8609792'

Test #29:

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

input:

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

output:

16621568

result:

ok single line: '16621568'

Test #30:

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

input:

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

output:

21446656

result:

ok single line: '21446656'

Test #31:

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

input:

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

output:

4677632

result:

ok single line: '4677632'

Test #32:

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

input:

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

output:

41435136

result:

ok single line: '41435136'

Test #33:

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

input:

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

output:

8740864

result:

ok single line: '8740864'

Test #34:

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

input:

()()(?

output:

1

result:

ok single line: '1'

Test #35:

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

input:

(??)

output:

5

result:

ok single line: '5'

Test #36:

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

input:

(<{}>??]

output:

1

result:

ok single line: '1'

Test #37:

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

input:

(?]]

output:

0

result:

ok single line: '0'