QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#351167#6366. MessageJWRuixiRE 40ms100944kbC++172.5kb2024-03-11 17:40:422024-03-11 17:40:43

Judging History

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

  • [2024-03-11 17:40:43]
  • 评测
  • 测评结果:RE
  • 用时:40ms
  • 内存:100944kb
  • [2024-03-11 17:40:42]
  • 提交

answer

#include <bits/stdc++.h>
#define IL inline
#define LL long long
#define eb emplace_back
#define L(i, j, k) for (int i = (j); i <= (k); ++i)
#define R(i, j, k) for (int i = (j); i >= (k); --i)
using namespace std;

using vi = vector<int>;
using pi = pair<int, int>;
#define fi first
#define se second

constexpr int N = 2e5 + 9;
constexpr int M = 26;
constexpr LL INF = 0x3f3f3f3f3f3f3f3f;
int n, m, w[N], p[M], q[M];
char s[N], t[N];

int nt;
pi d[M * 2];

bool vis[M];
LL ww[N], c[N], f[M * 2 + 7][N];
int nx[N];

int main () {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> (s + 1) >> (t + 1);
  n = strlen(s + 1);
  m = strlen(t + 1);
  L (i, 1, n) {
    cin >> w[i];
  }
  memset(p, 0, M << 2);
  memset(q, 0, M << 2);
  L (i, 1, m) {
    q[t[i] - 'a'] = i;
  }
  R (i, m, 1) {
    p[t[i] - 'a'] = i;
  }
  L (i, 0, M - 1) {
    if (p[i]) {
      d[++nt] = pi(p[i] - 1, i);
      d[++nt] = pi(q[i], i);
    }
  }
  sort(d + 1, d + nt + 1);
  memset(f, 0x3f, sizeof(f));
  f[0][0] = 0;
  L (i, 1, n) {
    f[0][i] = f[0][i - 1] + w[i];
  }
  L (i, 1, nt) {
    int l = d[i - 1].fi + 1, r = d[i].fi;
    if (l > r) {
      memcpy(f[i], f[i - 1], (n + 1) << 4);
      vis[d[i].se] ^= 1;
      continue;
    }
    int k = l - 1;
    nx[l] = k;
    L (j, l + 1, r) {
      while (t[k + 1] != t[j] && k >= l) {
        k = nx[k];
      }
      k += (t[k + 1] == t[j]);
      nx[j] = k;
    }
    L (j, 1, n) {
      ww[j] = ww[j - 1];
      c[j] = c[j - 1];
      if (vis[s[j] - 'a']) {
        ++c[j];
      } else {
        ww[j] += w[j];
      }
    }
    k = l - 1;
    int kk = 0;
    LL mn = f[i - 1][kk];
    auto mv = [&] (int j) {
      while (c[j] - c[kk] > k - l + 1) {
        ++kk;
      }
      mn = INF;
      while (c[j] - c[kk] == k - l + 1) {
        mn = min(mn, f[i - 1][kk] - ww[kk]);
        ++kk;
      }
    };
    L (j, 1, n) {
      if (vis[s[j] - 'a']) {
        if (k == r) {
          k = nx[k];
        }
        while (t[k + 1] != s[j] && k >= l) {
          k = nx[k];
        }
        k += t[k + 1] == s[j];
        mv(j);
      }
      if (k == r) {
        f[i][j] = mn + ww[j];
      }
    }
    vis[d[i].se] ^= 1;
  }
  LL as = INF;
  LL k = 0;
  R (i, n, 1) {
    as = min(as, f[nt][i] + k);
    k += w[i];
  }
  if (as == INF) {
    cout << "You better start from scratch man..." << '\n';
  } else {
    cout << as << '\n';
  }
}
// I love WHQ!

详细

Test #1:

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

input:

ababccb
abc
7 2 2 4 3 2 1

output:

7

result:

ok single line: '7'

Test #2:

score: 0
Accepted
time: 4ms
memory: 96436kb

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: 100832kb

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: 100944kb

input:

bdabcfbdfcffebebcabbadacbbaeeaffbdedeedfabefdfdbddcecdaaddafdfbbdceccedebcecdfbcfbaafcefeecffdabfaacbeeecfeffaaafaefdcdaaeaeecfafcdadbfbccbdecacfeabdbfcacafebdcfbfbebacbffaecbfbcedccabbdecabaebbbdbcfbaeadfcadfadfaebaddbebfcbefdabdcefbbdaaaabcefedabcabcafedcfadedfdcbbccbffdcfdfcfcdfcfbbdabdbbeecafecc...

output:

You better start from scratch man...

result:

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

Test #5:

score: -100
Runtime Error

input:

soibsuydrizsuvymezuyrewmgwpnzxgyggpzjkdzooisgzbkfqjzkfcklluotqpwganvksoqtzixkfkrtqobdnregwgkxjwzsruvhztscxjyqlhfytomzhxiglxemdhkjnskrsqngojffogrkbygmdgzfwrlhwhhngqpjpepqgynsdybhpuaqhgjroijqofiwnxgxdmhofwsjnmwitruiesefzmabcfsyzrrruidewjowfkwwwqhztsmmtdnejlqhkmbpmknlxijnmzbtqviburbqwufipqsrqplcelovsxz...

output:


result: