QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#351166#6366. MessageJWRuixiRE 42ms89952kbC++172.5kb2024-03-11 17:39:532024-03-11 17:39:53

Judging History

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

  • [2024-03-11 17:39:53]
  • 评测
  • 测评结果:RE
  • 用时:42ms
  • 内存:89952kb
  • [2024-03-11 17:39:53]
  • 提交

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][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: 88500kb

input:

ababccb
abc
7 2 2 4 3 2 1

output:

7

result:

ok single line: '7'

Test #2:

score: 0
Accepted
time: 6ms
memory: 88048kb

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

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: 42ms
memory: 89952kb

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: