QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#676982 | #7697. Impartial Strings | new_game_plus_players# | WA | 14ms | 4224kb | C++14 | 2.4kb | 2024-10-26 08:10:08 | 2024-10-26 08:10:09 |
Judging History
answer
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
string Sigma;
int go[1011][26];
int tp[1011][26];
int fail[1011];
int fa[1011];
int fac[2011];
int lv[1011];
vector<int> v[1011];
int tot;
int label[1011];
void add(char s[], int coef) {
int l = strlen(s);
int x = 1;
for (int i=0; i<l; i++) {
int c = s[i]-'a';
if (!go[x][c]) {
go[x][c] = ++tot;
fa[go[x][c]] = x;
lv[go[x][c]] = lv[x]+1;
fac[go[x][c]] = c;
}
x = go[x][c];
}
label[x] += coef;
}
int dis[1011];
void build() {
for (int i=0; i<=tot; i++) v[i].clear();
for (int i=1; i<=tot; i++) {
v[lv[i]].PB(i);
}
// cerr<<"ok"<<endl;
fail[1] = 1;
for (int i=0; i<=tot; i++) {
for (auto x : v[i]) {
if (x==1 || fa[x] == 1) fail[x] = 1;
else {
int &f = fail[x];
f = fail[fa[x]];
while (f != 1 && !go[f][fac[x]]) f = fail[f];
if (go[f][fac[x]]) f = go[f][fac[x]];
}
}
}
memset(tp, 0, sizeof(tp));
// cerr<<"ok"<<endl;
for (int i=0; i<=tot; i++) {
for (auto x : v[i]) {
for (int j=0; j<26; j++) {
int &t = tp[x][j];
if (go[x][j]) t = go[x][j];
else {
t = x;
while (t!=1 && !go[t][j]) t = fail[t];
if (go[t][j]) t = go[t][j];
}
}
}
}
}
int potential[1011];
const int qmax = 1011;
int que[qmax], qb, qe;
bool inq[1011];
int cntq[1011];
bool check() {
memset(inq, 0, sizeof(inq));
memset(dis, 20, sizeof(dis));
memset(cntq, 0, sizeof(cntq));
qb = qe = 0;
que[qe++] = 1;
inq[1] = 1;
dis[1] = 0;
while (qb != qe) {
int x = que[qb];
// cerr<<"x="<<x<<" dis="<<dis[x]<<endl;
qb++; if (qb>=qmax) qb = 0;
inq[x] = 0;
for (auto c : Sigma) {
int u = tp[x][c-'a'];
// cerr<<"u="<<u<<endl;
if (dis[u] > dis[x] + label[u]) {
dis[u] = dis[x] + label[u];
if (!inq[u]) {
inq[u] = true;
que[qe++] = u;
if (qe>=qmax) qe = 0;
cntq[u]++;
if (cntq[u]>=tot) {
return false;
}
}
}
}
}
return true;
}
void solve() {
tot = 1;
memset(go, 0, sizeof(go));
memset(label, 0, sizeof(label));
cin>>Sigma;
for (int i=0; i<2; i++) {
char s[1011];
scanf("%s", s);
add(s, i?1:-1);
}
build();
int ans = check();
printf("%d\n", ans);
}
int main() {
int Tn;
scanf("%d", &Tn);
while (Tn--) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 4012kb
input:
3 ab ab ba abc ab ba cz cczz zzcc
output:
1 0 0
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 14ms
memory: 4224kb
input:
7 d d d d dd d d d dd z zzzzzzzzzzzz zzz a aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
1 0 1 0 1 1 0
result:
wrong answer 2nd lines differ - expected: '1', found: '0'