QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#446153#8521. Pattern Search IIucup-team1069WA 4ms118652kbC++202.5kb2024-06-16 22:42:382024-06-16 22:42:38

Judging History

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

  • [2024-06-16 22:42:38]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:118652kb
  • [2024-06-16 22:42:38]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define sz(x) (int)x.size()

const int N = 3e5 + 20;
const int mod = 1e9 + 7;
const int inf = 1e9;

string s[30], t;
int dp[30][N], pd[30][N], can[30][N], nac[30][N];

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    const int K = 23;
    s[0] = "b";
    s[1] = "a";
    cin >> t;
    int n = sz(t);
    t = "#" + t;
    for (int j = 1; j <= n; ++j) {
        if (s[0][0] == t[j]) {
            can[0][j] = 1;
            dp[0][j] = 1;
        }
        if (s[1][0] == t[j]) {
            can[1][j] = 1;
            dp[1][j] = 1;
        }
    }
    for (int i = 2; i <= K; ++i) {
        s[i] = s[i - 1] + s[i - 2];
        for (int j = 1; j <= n; ++j) {
            dp[i][j] = inf;
            if (can[i - 2][j] == j) {
                dp[i][j] = dp[i - 2][j];
                can[i][j] = j;
            }
            else {
                if (can[i - 1][j - can[i - 2][j]] + can[i - 2][j] == j) {
                    dp[i][j] = dp[i - 1][j - can[i - 2][j]] + sz(s[i - 2]); 
                    can[i][j] = j;
                }
                else {
                    dp[i][j] = sz(s[i]);
                    can[i][j] = can[i - 1][j - can[i - 2][j]] + can[i - 2][j];
                }
            }
        }
    }
    reverse(t.begin() + 1, t.end());
    for (int j = 1; j <= n; ++j) {
        if (s[0][0] == t[j]) {
            nac[0][j] = 1;
            pd[0][j] = 1;
        }
        if (s[1][0] == t[j]) {
            nac[1][j] = 1;
            pd[1][j] = 1;
        }
    }
    for (int i = 2; i <= K; ++i) {
        for (int j = 1; j <= n; ++j) {
            pd[i][j] = inf;
            if (nac[i - 1][j] == j) {
                pd[i][j] = pd[i - 1][j];
                nac[i][j] = j;
            }
            else {
                if (nac[i - 2][j - nac[i - 1][j]] + nac[i - 1][j] == j) {
                    pd[i][j] = pd[i - 2][j - nac[i - 1][j]] + sz(s[i - 1]);
                    nac[i][j] = j;
                }
                else {
                    pd[i][j] = sz(s[i]);
                    nac[i][j] = nac[i - 2][j - can[i - 1][j]] + can[i - 1][j];
                }
            }
        }
    }
    int ans = inf;
    for (int i = 1; i <= K; ++i) {
        if (can[i][n] == n)
            ans = min(ans, dp[i][n]);
        for (int j = 1; j < n; ++j) {
            if (can[i][j] + nac[i - 1][n - j] == n) {
                ans = min(ans, dp[i][j] + pd[i - 1][n - j]);
            }
        }
    }
    cout << ans << '\n';
}

詳細信息

Test #1:

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

input:

aabbaab

output:

8

result:

ok 1 number(s): "8"

Test #2:

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

input:

a

output:

1

result:

ok 1 number(s): "1"

Test #3:

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

input:

b

output:

1

result:

ok 1 number(s): "1"

Test #4:

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

input:

aa

output:

2

result:

ok 1 number(s): "2"

Test #5:

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

input:

bb

output:

3

result:

ok 1 number(s): "3"

Test #6:

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

input:

ab

output:

2

result:

ok 1 number(s): "2"

Test #7:

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

input:

ba

output:

2

result:

ok 1 number(s): "2"

Test #8:

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

input:

bbba

output:

7

result:

ok 1 number(s): "7"

Test #9:

score: -100
Wrong Answer
time: 4ms
memory: 118580kb

input:

abbbbbbbab

output:

19

result:

wrong answer 1st numbers differ - expected: '20', found: '19'