QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#298508#7955. Tandem CopySolitaryDream#WA 0ms3756kbC++171.6kb2024-01-06 12:08:002024-01-06 12:08:00

Judging History

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

  • [2024-01-06 12:08:00]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3756kb
  • [2024-01-06 12:08:00]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 2e4 + 10;;
string s, t;
int n, m, ans[N], f[2][N];
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> s >> t;
    // s.resize(2e4);
    // t.resize(2e4);
    // for (int i = 1; i <= 2e4; ++i) s[i] = 'a' + (i & 1);
    // for (int i = 1; i <= 2e4; ++i) t[i] = 'a' + (i & 1);
    n = s.size(); m = t.size();
    s = ' ' + s; t = ' ' + t;
    {
        int tp = 0;
        for (int i = 1; i <= m; ++i) if (t[i] != t[i - 1]) t[++tp] = t[i];
        m = tp;
        t.resize(tp + 1);
    }
    if (m == 1) {
        for (int i = 1; i <= n; ++i) ans[i] = (s[i] == t[1] ? i : n + 1);
    } else {
        for (int i = 1; i <= m + 1; ++i) f[n & 1][i] = n + 1;
        f[n & 1][m] = (s[n] == t[m] ? n : n + 1);
        ans[n] = n + 1; 
        for (int i = n - 1; i; --i) {
            f[i & 1][m + 1] = i;
            f[i & 1][m] = (s[i] == t[m] ? i : n + 1);
            if (s[i + 1] == t[m]) f[i & 1][m] = i + 1;
            for (int j = m - 1; j; --j) {
                if (s[i] != t[j]) f[i & 1][j] = n + 1;
                else {
                    f[i & 1][j] = f[(i + 1) & 1][j + 1];
                    if (s[i + 1] == t[j + 1]) f[i & 1][j] = min(f[i & 1][j], max(i + 1, f[i & 1][j + 2]));
                }
            }
            ans[i] = min(f[i & 1][1], ans[i + 1]);
            if (s[i + 1] == t[1]) ans[i] = min(ans[i], max(i + 1, f[i & 1][2]));
        }
    }
    int rst = 0;
    for (int i = 1; i <= n; ++i) rst += n - ans[i] + 1;
    cout << rst << endl;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

ACGCG
CCG

output:

9

result:

ok single line: '9'

Test #2:

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

input:

TATCGC
TTCCG

output:

6

result:

ok single line: '6'

Test #3:

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

input:

ABCABC
ABC

output:

7

result:

ok single line: '7'

Test #4:

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

input:

ABCABC
ABCABC

output:

1

result:

ok single line: '1'

Test #5:

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

input:

FUSBX
UUUUUUUUUU

output:

4

result:

wrong answer 1st lines differ - expected: '8', found: '4'