QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#88586 | #4107. 墙上的句子 | Jekyll_Y | 0 | 75ms | 15712kb | C++14 | 4.3kb | 2023-03-16 17:05:20 | 2023-03-16 17:05:23 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
const int INF = 2e9;
int n, m;
int r[80], c[80];
char s[80][80];
int S = 0, T = 1e3;
int tot;
map <string, int> mp;
map <string, int> vis;
struct graph
{
int cnt, head[N];
struct edge
{
int to, nxt, flow;
edge(int v = 0, int x = 0, int f = 0) :
to(v), nxt(x), flow(f) {}
}e[N * N];
void add(int u, int v, int f)
{
e[++cnt] = edge(v, head[u], f); head[u] = cnt;
e[++cnt] = edge(u, head[v], 0); head[v] = cnt;
}
void init()
{
cnt = 1;
memset(head, 0, sizeof(head));
}
}G;
void init()
{
G.init(); mp.clear(); tot = 0; vis.clear();
}
bool check1(string s)
{
int len = s.size();
for(int i = 0; i <= (len - 1) / 2; i++)
if(s[i] != s[len - i - 1])return 0;
return 1;
}
bool check2(string s)
{
string a = s, b = s;
reverse(b.begin(), b.end());
return a < b;
}
void push(string s)
{
string a = s, b = s;
reverse(b.begin(), b.end());
if(a > b)swap(a, b);
mp[a] = ++tot, mp[b] = ++tot;
G.add(mp[a], mp[b], 2);
}
void insert(string s, int f)
{
if(!mp.count(s))push(s);
if(f)G.add(S, mp[s], INF);
else G.add(mp[s], T, INF);
}
void add(string s, int x)
{
string a = s, b = s;
reverse(b.begin(), b.end());
if(a > b)swap(a, b);
if(!mp.count(s))push(s);
G.add(mp[b], x, INF);
G.add(x, mp[a], INF);
}
int depth[N];
bool bfs()
{
memset(depth, 0, sizeof(depth));
depth[S] = 1; queue <int> q; q.push(S);
while(!q.empty())
{
int x = q.front(); q.pop();
for(int i = G.head[x]; i; i = G.e[i].nxt)
{
int v = G.e[i].to, f = G.e[i].flow;
if(f && !depth[v])
{
depth[v] = depth[x] + 1;
q.push(v);
}
}
}
return depth[T];
}
int dfs(int x, int in)
{
if(x == T)return in;
int out = 0;
for(int i = G.head[x]; i; i = G.e[i].nxt)
{
if(in <= 0)break;
int v = G.e[i].to, f = G.e[i].flow;
if(f && depth[v] == depth[x] + 1)
{
int res = dfs(v, min(in, f));
G.e[i].flow -= res;
G.e[i ^ 1].flow += res;
in -= res; out += res;
}
}
if(!out)depth[x] = 0;
return out;
}
int dinic()
{
int maxflow = 0;
while(bfs())maxflow += dfs(S, INF);
return maxflow;
}
int main()
{
int T; scanf("%d", &T);
while(T--)
{
init();
scanf("%d%d", &n, &m);
for(int i = 1; i <= n; i++)
scanf("%d", &r[i]);
for(int i = 1; i <= m; i++)
scanf("%d", &c[i]);
for(int i = 1; i <= n; i++)
scanf("%s", s[i] + 1);
int ans = 0; tot = n + m;
for(int i = 1; i <= n; i++)
{
string str = ""; s[i][m + 1] = '_';
for(int j = 1; j <= m + 1; j++)
{
if(s[i][j] == '_')
{
if(str == "")continue;
if(check1(str) && !vis[str])
ans++, vis[str] = 1;
else
{
if(r[i])
insert(str, check2(str));
else add(str, i);
}
str = "";
}
else str += s[i][j];
}
}
for(int j = 1; j <= m; j++)
{
string str = ""; s[n + 1][j] = '_';
for(int i = 1; i <= n + 1; i++)
{
if(s[i][j] == '_')
{
if(str == "")continue;
if(check1(str) && !vis[str])
ans++, vis[str] = 1;
else
{
if(c[j])
insert(str, check2(str));
else add(str, j + n);
}
str = "";
}
else str += s[i][j];
}
}
printf("%d\n", ans + dinic());
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 4ms
memory: 15696kb
input:
64 9 9 0 0 0 0 1 0 0 0 0 0 0 0 0 0 -1 0 1 -1 BB_AC_BC_ BC_CC_CC_ _________ AB_AB_AC_ BC_BB_BC_ _________ AC_BC_BC_ CC_BC_BC_ _________ 9 9 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 AB_AA_AB_ BB_AA_BC_ _________ AB_AB_AC_ AB_BC_BC_ _________ AA_AB_AC_ AB_BB_AC_ _________ 9 9 0 0 0 0 -1 0 0 0 0 0 -1 0 0 0 ...
output:
4 5 7 5 9 2 7 5 3 5 7 3 3 6 7 7 2 7 5 5 3 3 5 5 9 5 5 3 3 2 3 5 7 7 7 3 2 5 9 7 7 7 7 5 9 4 7 3 3 5 9 7 3 2 7 3 7 7 7 5 7 7 3 9
result:
wrong answer 1st lines differ - expected: '2', found: '4'
Test #2:
score: 0
Wrong Answer
time: 1ms
memory: 15528kb
input:
64 9 9 0 0 0 0 1 1 1 0 0 0 0 0 0 -1 0 0 0 -1 BD_AD_BC_ CD_DD_CD_ _________ AD_BD_BC_ BD_CD_BC_ _________ AD_AC_AC_ DD_AD_AC_ _________ 9 9 0 0 -1 0 -1 0 0 0 -1 1 0 0 -1 0 -1 0 0 0 BC_BC_AC_ CD_CD_BD_ _________ CD_BC_BC_ DD_BC_CD_ _________ AD_AC_BB_ DD_CD_BD_ _________ 9 9 0 0 0 1 0 0 0 0 0 0 1 0 -1...
output:
8 5 3 3 5 8 4 3 5 8 4 6 3 3 7 3 7 6 11 4 4 8 5 10 4 4 8 3 4 3 8 4 5 3 4 4 4 6 3 4 4 4 2 6 4 8 3 4 3 4 9 5 3 4 5 4 7 4 4 4 4 4 4 4
result:
wrong answer 1st lines differ - expected: '6', found: '8'
Test #3:
score: 0
Wrong Answer
time: 4ms
memory: 15548kb
input:
64 18 18 0 0 0 0 0 -1 0 0 1 0 0 0 0 0 0 0 0 0 0 -1 1 0 0 0 0 -1 0 1 0 0 0 1 0 0 0 1 AC_BD_FG_BE_AA_AG_ BE_CE_FG_CF_AD_GG_ __________________ BD_CC_BE_BE_BE_BE_ CF_CE_DE_CG_BG_CF_ __________________ BD_AE_AE_AC_CE_AF_ CG_EF_EG_CD_CF_BF_ __________________ CF_DE_BE_AB_AD_CF_ FF_DG_BG_BD_AF_EF_ _______...
output:
27 37 16 26 35 15 6 27 15 37 6 26 27 7 25 28 25 12 28 21 27 31 23 17 17 29 33 25 23 27 31 23 21 7 26 6 29 6 31 27 32 7 31 20 15 32 19 12 16 30 7 6 27 23 32 21 33 30 7 7 28 20 6 20
result:
wrong answer 1st lines differ - expected: '19', found: '27'
Test #4:
score: 0
Wrong Answer
time: 10ms
memory: 15692kb
input:
64 18 18 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 AG_EF_AF_AD_BE_BC_ BH_EF_FG_CH_CF_CE_ __________________ BE_AC_BC_EF_DD_AE_ DH_BH_BG_EH_DF_CH_ __________________ AE_AB_BB_AF_BE_EG_ DG_AE_BB_AF_EG_EH_ __________________ DE_AD_CD_BF_BG_AG_ EG_DE_CH_CG_EG_CG_ _________...
output:
16 7 16 23 29 19 6 14 8 21 26 25 8 19 23 7 31 28 20 17 17 38 7 7 21 19 33 24 33 14 7 5 25 24 35 28 36 30 29 15 8 24 16 31 6 22 38 15 27 7 26 24 7 8 30 17 19 6 29 17 23 27 6 28
result:
wrong answer 2nd lines differ - expected: '13', found: '7'
Test #5:
score: 0
Wrong Answer
time: 6ms
memory: 15704kb
input:
64 24 24 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 ABC_AAC_ABC_AAB_AAB_AAB_ ACD_ABD_ABD_ABC_ABD_ABC_ CDD_BDD_BDD_ACD_ACD_ACD_ ________________________ ABC_ABD_ABB_ABC_AAB_ACD_ BCD_ACD_ABD_ACD_ABD_BDD_ CCD_BDD_BCD_CCD_ABD_CDD_ ___________________...
output:
11 3 4 12 4 23 4 14 3 21 22 10 20 9 19 14 20 10 3 17 15 18 6 22 4 14 4 16 10 4 14 4 20 23 17 9 13 11 24 10 4 10 18 18 20 14 4 4 9 12 14 16 19 19 13 13 22 18 12 7 4 18 4 26
result:
wrong answer 1st lines differ - expected: '7', found: '11'
Test #6:
score: 0
Wrong Answer
time: 1ms
memory: 15644kb
input:
64 24 24 -1 0 0 0 0 0 1 0 1 0 -1 0 -1 0 0 0 0 -1 0 1 0 1 -1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 1 1 -1 0 0 AAC_AAB_ABB_BBC_ABC_ACD_ ACD_ABC_ABE_BBE_BBE_CDD_ BDD_BBD_BBE_BDE_BCE_CDE_ ________________________ ACD_ABC_ABD_ABC_ABD_ABB_ BDE_ACE_ACD_ABE_ADE_ABC_ CEE_CDE_CDD_BEE_CDE_BCC_ _____________...
output:
5 16 8 4 27 13 10 3 3 3 4 4 10 4 11 4 5 3 14 5 4 4 2 4 2 4 1 12 9 10 12 3 9 11 17 3 10 3 2 3 4 19 12 3 4 3 1 26 19 13 15 4 3 3 5 18 3 3 5 21 17 5 4 4
result:
wrong answer 1st lines differ - expected: '31', found: '5'
Test #7:
score: 0
Wrong Answer
time: 75ms
memory: 15664kb
input:
64 72 72 -1 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 -1 0 0 -1 0 1 0 0 0 0 0 0 0 -1 0 0 0 1 0 0 0 -1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 -1 0 0 -1 1 0 0 0 0 -1 0 0 0 0 -1 0 0 0 0 0 1 -1 0 0 0...
output:
378 396 350 286 409 369 288 336 306 396 316 383 374 364 358 380 392 374 304 388 265 371 394 276 399 375 360 290 400 298 380 410 410 392 286 410 370 373 328 390 394 390 280 396 350 379 386 341 348 412 370 390 374 376 381 408 410 399 383 324 372 315 360 364
result:
wrong answer 1st lines differ - expected: '182', found: '378'
Test #8:
score: 0
Wrong Answer
time: 33ms
memory: 15652kb
input:
64 72 72 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 -1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 -1 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 -1 0 0 ...
output:
39 61 51 59 5 61 57 57 53 49 55 51 59 57 57 59 57 57 61 55 61 57 57 57 59 57 57 61 59 55 57 61 55 59 61 45 51 55 55 59 57 59 57 57 57 57 59 57 55 59 57 53 59 57 53 57 55 61 53 55 59 61 55 57
result:
wrong answer 1st lines differ - expected: '47', found: '39'
Test #9:
score: 0
Wrong Answer
time: 37ms
memory: 15712kb
input:
64 72 72 0 0 -1 0 0 0 1 0 0 0 0 0 0 -1 0 0 0 1 -1 0 0 0 0 0 1 0 0 0 -1 0 0 -1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 -1 0 0 0 1 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 -1 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 -1 0 -1 0 0 0 0 0 1 0 0 0 -1 0 -1 0 0 0 0 0 0 0...
output:
32 88 78 84 44 92 88 82 84 50 88 74 45 72 82 80 80 82 86 84 52 90 88 40 82 68 86 38 66 42 6 78 81 84 86 66 76 76 44 72 42 84 72 80 70 39 70 84 84 76 79 84 80 44 72 42 80 78 78 66 92 80 82 84
result:
wrong answer 1st lines differ - expected: '88', found: '32'
Test #10:
score: 0
Wrong Answer
time: 24ms
memory: 15612kb
input:
64 70 70 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 -1 0 0 0 0 0 0 0 -1 0 0 0 0 -1 0 -1 -1 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 1 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 -1 0 0 0 0 0 0 0 0 1 0 0 -1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 ...
output:
27 27 27 25 23 25 25 25 25 15 23 17 25 27 25 25 27 23 27 17 21 23 27 25 23 23 15 25 27 23 23 25 15 25 23 25 25 15 25 25 23 27 27 25 27 25 25 21 23 25 23 23 27 3 17 25 23 15 25 23 23 27 25 25
result:
wrong answer 1st lines differ - expected: '25', found: '27'