QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#393541#6366. MessageJohnsonloyWA 80ms28152kbC++173.8kb2024-04-18 19:22:152024-04-18 19:22:16

Judging History

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

  • [2024-04-18 19:22:16]
  • 评测
  • 测评结果:WA
  • 用时:80ms
  • 内存:28152kb
  • [2024-04-18 19:22:15]
  • 提交

answer

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

#define int long long
#define pii pair<int, int>
#define mp make_pair
#define db double
const int maxn = 1e6 + 10;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f3f3f3f3f;

namespace IO {
void openfile() {
#ifndef ONLINE_JUDGE
    freopen("in.in", "r", stdin);
    freopen("out.out", "w", stdout);
#endif
}
void Min(int& x, int y) {
    x = (x < y) ? x : y;
}
void Max(int& x, int y) {
    x = (x > y) ? x : y;
}
int add(int x, int y) {
    return (x + y) >= mod ? (x + y - mod) : (x + y);
}
int sub(int x, int y) {
    return (x < y) ? (x + mod - y) : (x - y);
}
void Add(int& x, int y) {
    x = (x + y) >= mod ? (x + y - mod) : (x + y);
}
void Sub(int& x, int y) {
    x = (x < y) ? (x - y + mod) : (x - y);
}
int mul(int x, int y) {
    return 1ll * x * y % mod;
}
void Mul(int& x, int y) {
    x = 1ll * x * y % mod;
}
int qpow(int x, int y = mod - 2) {
    int ans = 1;
    while (y) {
        if (y & 1)
            ans = 1ll * x * ans % mod;
        x = 1ll * x * x % mod, y >>= 1;
    }
    return ans;
}
inline int read() {
    int x = 0, f = 0;
    char w = getchar();
    while (!isdigit(w))
        f |= w == '-', w = getchar();
    while (isdigit(w))
        x = x * 10 + w - '0', w = getchar();
    if (f)
        x = -x;
    return x;
}
}  // namespace IO
using namespace IO;

char a[maxn], b[maxn], s[maxn];
int n, m, pcnt, scnt, sp[maxn], nex[maxn];
int w[maxn], sum[maxn], f[maxn], tmp[maxn], flag[maxn];
pii p[maxn];

signed main() {
    openfile();
    ios::sync_with_stdio(false), cin.tie(0);
    cin >> a + 1 >> b + 1;
    n = strlen(a + 1), m = strlen(b + 1);
    for (int i = 1; i <= n; i++)
        cin >> w[i];
    for (int j = 0; j < 26; j++) {
        int l = n + 1, r = -1;
        for (int i = 1; i <= m; i++)
            if (b[i] == (j + 'a'))
                Min(l, i), r = i + 1;
        if (~r)
            p[++pcnt] = mp(l, j + 1), p[++pcnt] = mp(r, -j - 1);
    }
    sort(p + 1, p + 1 + pcnt);
    for (int k = 1; k < pcnt; k++) {
        if (p[k].second > 0)
            flag[p[k].second - 1] = 1;
        else
            flag[-p[k].second - 1] = 0;
        for (int i = 0; i <= n; i++)
            tmp[i] = -inf;
        scnt = 0;
        for (int i = 1; i <= n; i++)
            if (flag[a[i] - 'a'])
                s[++scnt] = a[i], sp[scnt] = i, sum[scnt] = sum[scnt - 1] + w[i];
        sp[scnt + 1] = n + 1;
        if (p[k].first == p[k + 1].first) {
            for (int i = 0; i <= scnt; i++)
                for (int j = sp[i] + 2; i < sp[i + 1]; i++)
                    Max(f[j], f[j - 1]);
            continue;
        }
        int L = p[k].first, R = p[k + 1].first - 1, K = R - L + 1;
        nex[L] = L - 1;
        for (int i = L + 1, j = L - 1; i <= R; i++) {
            while (j >= L && b[j + 1] != b[i])
                j = nex[j];
            if (b[j + 1] == b[i])
                j++;
            nex[i] = j;
        }
        for (int i = 1, j = L - 1; i <= scnt; i++) {
            while (j >= L && s[i] != b[j + 1])
                j = nex[j];
            if (b[j + 1] == s[i])
                j++;
            if (j == R) {
                j = nex[j];
                int res = -inf;
                for (int x = sp[i - K]; x < sp[i - K + 1]; x++)
                    Max(res, f[x]);
                for (int x = sp[i]; x < sp[i + 1]; x++)
                    Max(tmp[x], res + sum[i] - sum[i - K]);
            }
        }
        for (int i = 0; i <= n; i++)
            f[i] = tmp[i];
    }
    int ans = -inf, sum = 0;
    for (int i = 1; i <= n; i++)
        Max(ans, f[i]), sum += w[i];
    if (ans < -1e17)
        cout << "You better start from scratch man...\n";
    else
        cout << sum - ans;
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 15964kb

input:

ababccb
abc
7 2 2 4 3 2 1

output:

7

result:

ok single line: '7'

Test #2:

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

input:

babab
baab
2 1 3 2 4

output:

You better start from scratch man...

result:

ok single line: 'You better start from scratch man...'

Test #3:

score: 0
Accepted
time: 19ms
memory: 27436kb

input:

bbaaaabbbbbabaababbaaabbbabaaaababaababaabababbbbabbbbababaabaaabbabaaaabbbabbaababababbabbbabbaababaaaaaabbabbbababbaabbbabbbabbbabaababaaaaaabaaababbbbbbaabaabaaaaaaabbbaaabaabbbababbbbbabbababaababaabbababbaababbbbbbbbbbbaabbbbbabaaabaabaaabaaaaabaaaabbbbbbbaaaabaabbbababbaaaabbabababbbabbbbabbab...

output:

You better start from scratch man...

result:

ok single line: 'You better start from scratch man...'

Test #4:

score: 0
Accepted
time: 40ms
memory: 28152kb

input:

bdabcfbdfcffebebcabbadacbbaeeaffbdedeedfabefdfdbddcecdaaddafdfbbdceccedebcecdfbcfbaafcefeecffdabfaacbeeecfeffaaafaefdcdaaeaeecfafcdadbfbccbdecacfeabdbfcacafebdcfbfbebacbffaecbfbcedccabbdecabaebbbdbcfbaeadfcadfadfaebaddbebfcbefdabdcefbbdaaaabcefedabcabcafedcfadedfdcbbccbffdcfdfcfcdfcfbbdabdbbeecafecc...

output:

You better start from scratch man...

result:

ok single line: 'You better start from scratch man...'

Test #5:

score: 0
Accepted
time: 80ms
memory: 26304kb

input:

soibsuydrizsuvymezuyrewmgwpnzxgyggpzjkdzooisgzbkfqjzkfcklluotqpwganvksoqtzixkfkrtqobdnregwgkxjwzsruvhztscxjyqlhfytomzhxiglxemdhkjnskrsqngojffogrkbygmdgzfwrlhwhhngqpjpepqgynsdybhpuaqhgjroijqofiwnxgxdmhofwsjnmwitruiesefzmabcfsyzrrruidewjowfkwwwqhztsmmtdnejlqhkmbpmknlxijnmzbtqviburbqwufipqsrqplcelovsxz...

output:

You better start from scratch man...

result:

ok single line: 'You better start from scratch man...'

Test #6:

score: 0
Accepted
time: 19ms
memory: 26996kb

input:

bbaaaabbbbbabaababbaaabbbabaaaababaababaabababbbbabbbbababaabaaabbabaaaabbbabbaababababbabbbabbaababaaaaaabbabbbababbaabbbabbbabbbabaababaaaaaabaaababbbbbbaabaabaaaaaaabbbaaabaabbbababbbbbabbababaababaabbababbaababbbbbbbbbbbaabbbbbabaaabaabaaabaaaaabaaaabbbbbbbaaaabaabbbababbaaaabbabababbbabbbbabbab...

output:

0

result:

ok single line: '0'

Test #7:

score: 0
Accepted
time: 43ms
memory: 26292kb

input:

hdhlkjabgckjkagfgkigfebfjmdabahajicgkfmblafmfgkiimkjlciiaegbkbkicgklhbhfmclghkleghmckbjliiicmmecldieghfdeghgechcjahdfebkhdigbkklcclieccijaemchbmfcggcjmgbdjhcbacleajjjledkfdjebgdmgahkjigjjighlbedbellabffeeckfbghcblmmgjijdehmcameeledejfijfmfcfkjdjklfldhmkabblcbgebhibkmihelehjccgggjhhbjehfidfmmjdgmmjbf...

output:

0

result:

ok single line: '0'

Test #8:

score: 0
Accepted
time: 80ms
memory: 27972kb

input:

soibsuydrizsuvymezuyrewmgwpnzxgyggpzjkdzooisgzbkfqjzkfcklluotqpwganvksoqtzixkfkrtqobdnregwgkxjwzsruvhztscxjyqlhfytomzhxiglxemdhkjnskrsqngojffogrkbygmdgzfwrlhwhhngqpjpepqgynsdybhpuaqhgjroijqofiwnxgxdmhofwsjnmwitruiesefzmabcfsyzrrruidewjowfkwwwqhztsmmtdnejlqhkmbpmknlxijnmzbtqviburbqwufipqsrqplcelovsxz...

output:

0

result:

ok single line: '0'

Test #9:

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

input:

aaaaaaaaaa
a
670064684 12247274 885150692 755303894 373857482 772871474 451986656 733926307 275101324 732261937

output:

4777621032

result:

ok single line: '4777621032'

Test #10:

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

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaa
807194254 763061330 636628022 447638039 310117480 873320507 134259988 666480259 747042520 231541618 643931761 30317274 158530414 253502390 229547045 438239031 709645547 367432988 755781758 67144518 360508870 862615691 635226301 863755466 104979114 4...

output:

5115514604

result:

ok single line: '5115514604'

Test #11:

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

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaa
768295104 305748099 281563038 518303412 678146171 512832379 509999474 360793781 979858190 884904151 886121576 776530718 147119220 985829130 553994391 500082956 167860347 562080893 520228135 790526162 270707017 179265550 913606870 245853815 83...

output:

21140461276

result:

ok single line: '21140461276'

Test #12:

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

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
684483834 637018127 270602950 736485564 883414052 758886073 266638494 906099301 851227039 479339928 603217972 474167559 537788182 324629484 719852776 8079...

output:

27302362948

result:

ok single line: '27302362948'

Test #13:

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

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

131859070652

result:

ok single line: '131859070652'

Test #14:

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

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

781196173176

result:

ok single line: '781196173176'

Test #15:

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

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

4343956108320

result:

ok single line: '4343956108320'

Test #16:

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

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

18494567762260

result:

ok single line: '18494567762260'

Test #17:

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

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

32209183658799

result:

ok single line: '32209183658799'

Test #18:

score: 0
Accepted
time: 7ms
memory: 23888kb

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

54681136007004

result:

ok single line: '54681136007004'

Test #19:

score: 0
Accepted
time: 17ms
memory: 27480kb

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

29370598770431

result:

ok single line: '29370598770431'

Test #20:

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

input:

aaaabababb
bb
476848657 19478030 860633182 479517749 926931997 990353030 811177212 276072809 44418816 639422667

output:

3786744940

result:

ok single line: '3786744940'

Test #21:

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

input:

baabbbaabbbbbbaaabbabababbbabb
aabbbbbbbbbbbb
596942736 513321407 582182914 466363879 661702687 696876564 738552457 374802663 475543850 315580035 306727219 980454952 485808481 677883937 518967937 895712736 991586358 554417767 795851770 921017576 109301858 423859119 202619045 804565823 583428190 4070...

output:

9486081373

result:

ok single line: '9486081373'

Test #22:

score: -100
Wrong Answer
time: 2ms
memory: 18072kb

input:

bbaaaaababbaabbbabaaaaaaaaaaaaaaabaabaabbabbbbaaaa
bba
517088091 307183015 994179974 164146474 156595248 11692792 656694126 683962150 307132163 246359231 966105863 281059597 304728259 612665622 916423647 405320553 230841790 746930714 950416681 343242506 418374186 670629995 146835514 191417218 469803...

output:

21936514047

result:

wrong answer 1st lines differ - expected: '21735754192', found: '21936514047'