QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#532674 | #9111. Zayin and String | ZYLZPP | WA | 118ms | 34432kb | C++20 | 2.7kb | 2024-08-25 08:47:00 | 2024-08-25 08:47:01 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define For(i, l, r) for (int i = (l); i <= (r); ++i)
typedef long long ll;
typedef double lf;
const int N = 1e3 + 5, S = 4e3 + 5, Mo = 998244353;
const lf eps = 1e-10;
inline int ml(const int &x, const int &y) { return 1ll * x * y % Mo; }
inline void mul(int &x, const int &y) { x = ml(x, y); }
inline int qPow(int a, int b) { int r=1; for (;b;b>>=1,mul(a,a)) if (b&1) mul(r,a); return r; }
template<class C> inline bool cmax(C &x, const C &y) { return y>x? x=y, 1: 0; }
struct IO {
char c; int f;
#define gc() (getchar())
template<class C>
inline IO& operator >> (C &x) {
x = 0; f = 1;
while (!isdigit(c = gc()) && ~c) f |= -!(c ^ 45);
while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = gc();
x *= f; return *this;
}
inline bool operator ~ () { return ~c; }
} io;
int T, n, m, vis[N][S], tim;
lf f[N][S];
char t[N];
namespace ACAM {
int ch[S][26], tot = 1, fail[S], sum[S];
char s[S];
inline void add(char s[], int x) {
int n = strlen(s + 1), u = 1;
For (i, 1, n) {
int c = s[i] - 'a';
if (!ch[u][c]) ch[u][c] = ++tot;
u = ch[u][c];
}
sum[u] += x;
}
inline void build() {
For (i, 0, 25) ch[0][i] = 1;
queue<int > q; q.push(1);
fail[1] = 0;
while (!q.empty()) {
int u = q.front(); q.pop(); sum[u] += sum[fail[u]];
For (i, 0, 25) (ch[u][i]? q.push(ch[u][i]), fail[ch[u][i]]: ch[u][i]) = ch[fail[u]][i];
}
}
}
using namespace ACAM;
inline bool ok(lf x) {
f[0][1] = 0; vis[0][1] = ++tim;
For (i, 0, n - 1) For (j, 1, tot) if (vis[i][j] == tim) {
int c = t[i + 1] - 'a', k = ch[j][c];
if (vis[i + 1][j] ^ tim) vis[i + 1][j] = tim, f[i + 1][j] = f[i][j];
else cmax(f[i + 1][j], f[i][j]);
if (vis[i + 1][k] ^ tim) vis[i + 1][k] = tim, f[i + 1][k] = f[i][j] + sum[k] - x;
else cmax(f[i + 1][k], f[i][j] + sum[k] - x);
}
For (i, 1, tot) if (vis[n][i] == tim && f[n][i] > eps) return 1;
return 0;
}
inline void solve() {
For (i, 1, tot) fail[i] = sum[i] = 0, memset(ch[i], 0, sizeof ch[i]);
tot = 1;
io >> n >> m;
scanf("%s", t + 1);
int x;
For (i, 1, m) scanf("%s", s + 1), io >> x, add(s, x);
build();
lf l = 0, r = 2e8;
while (r - l > eps) {
lf mid = (l + r) / 2;
if (ok(mid)) l = mid;
else r = mid;
}
For (i, 1, n) {
ll x = round(l * i);
if (fabs(x - l * i) < n * eps) { printf("%d\n", ml(x % Mo, qPow(i, Mo - 2))); return; }
}
}
int main() {
io >> T;
while (T--) solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 108ms
memory: 31880kb
input:
80 4 7 ggeg g 92946 d 65678 gg 50828 wrj 93954 gge 53780 a 94179 geg 40837 5 6 hiiii ii 67984 foh 69185 hi 88153 pj 39431 i 32219 wfmve 96834 8 12 wvxxvwww xw 1522 rzl 16262 wx 77596 v 69622 vw 82225 nykkmkv 19236 xv 83470 o 16781 w 2405 m 98319 ww 13889 qggbvty 16331 8 14 jjjiiijh i 96670 z 74397 i...
output:
332874949 599030808 249640519 332898173 665548146 81272 61572 67112 499196918 748779217 88888 831949361 74929 665552405 499139737 665543594 332830174 60785 748771076 63646 103574 101389 432700990 332787384 249703944 89874 110460 499215461 665540622 41750 782592345 96189 111031999 94537 83443 111657 ...
result:
ok 80 lines
Test #2:
score: 0
Accepted
time: 103ms
memory: 22232kb
input:
80 6 9 ffdffd df 5764 g 80673 dfd 93960 sje 2655 f 52989 dykez 24524 fd 93464 v 5951 dd 80386 4 8 hgig hi 36540 eoy 56555 hgi 16024 da 39472 i 11615 w 28388 h 13233 b 36396 3 6 jhh jhh 78310 jck 52810 h 93391 f 84166 j 58232 tixuja 90170 6 9 wvuuwu uu 18802 cto 64653 v 17516 e 89244 vu 7176 yb 35851...
output:
499220334 30694 665604010 28868 499155869 399434929 43201 55925 53130 665596997 112603 48316 51377 665595637 332817598 92435 332790461 199775438 118514 46654 98424 99849 468077048 33082 499180262 499161147 99170 49530 249661952 665599894 19760011 31724 125134 665598061 665568382 53270 57347 74873729...
result:
ok 80 lines
Test #3:
score: -100
Wrong Answer
time: 118ms
memory: 34432kb
input:
80 6 9 fdfdfd f 62278 bd 63301 d 82508 hyx 79679 fd 77199 gat 3304 dd 38771 sz 65675 ffd 39030 3 4 ihi i 23765 vum 4334 ihi 35317 jz 58824 7 12 nmnnnmn mm 53554 z 37003 nnm 93166 os 47375 n 91295 k 23069 mn 70863 ke 53536 nmm 79577 xx 80568 nnn 9319 xpoioy 49090 3 4 stu su 64015 pm 39855 stu 12774 g...
output:
249677224 665523851 499231655 499154184 95658 499226034 748789158 80649 144255 249638234 499158453 48294 249637902 90840 499168402 499173301 499254931 599034136 249676514 332790820 798677117 102014068 332796115 44767 96925 120384 499168015 88966 99986 27092909 66644 832034701 125185 332785314 73629 ...
result:
wrong answer 6th lines differ - expected: '332794463', found: '499226034'