QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#446151#8521. Pattern Search IIucup-team1069WA 0ms116556kbC++202.5kb2024-06-16 22:41:532024-06-16 22:41:54

Judging History

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

  • [2024-06-16 22:41:54]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:116556kb
  • [2024-06-16 22:41:53]
  • 提交

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) {
        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: 116556kb

input:

aabbaab

output:

8

result:

ok 1 number(s): "8"

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 112492kb

input:

a

output:

1000000000

result:

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