QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#88585 | #4107. 墙上的句子 | Jekyll_Y | 0 | 68ms | 15708kb | C++14 | 4.2kb | 2023-03-16 16:51:36 | 2023-03-16 16:51:42 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
const int INF = 1e9;
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);
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;
}
详细
Test #1:
score: 0
Wrong Answer
time: 4ms
memory: 15528kb
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:
-294967294 2000000003 -1294967293 2000000003 -294967293 2 2000000003 5 3 1000000003 2000000003 3 3 2000000002 2000000003 2000000003 2 410065411 2000000003 1000000003 3 3 5 1000000003 705032707 1000000003 1000000003 3 3 2 3 705032707 1000000003 1000000003 1000000003 3 2 -1294967293 2000000003 1000000...
result:
wrong answer 1st lines differ - expected: '2', found: '-294967294'
Test #2:
score: 0
Wrong Answer
time: 3ms
memory: 15612kb
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:
2000000004 1000000003 3 3 2000000003 2000000004 4 3 1000000003 1000000004 4 1000000004 3 3 1000000003 3 1000000003 1000000004 2000000003 4 4 1000000004 -294967293 1000000004 4 4 2000000002 3 4 3 -1294967292 2000000004 1000000003 3 4 4 4 1000000004 3 4 1000000004 4 2 1000000004 4 2000000004 3 4 3 100...
result:
wrong answer 1st lines differ - expected: '6', found: '2000000004'
Test #3:
score: 0
Wrong Answer
time: 10ms
memory: 15696kb
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:
-1294967289 -1294967289 2000000006 -294967282 2000000007 1000000007 6 -294967289 1000000007 1000000007 6 -589934584 705032711 7 -1294967289 -294967286 -1294967289 1000000006 -294967290 1000000007 2000000007 1705032711 2000000015 2000000005 -1294967291 2000000007 -294967289 1000000007 -1589934585 -29...
result:
wrong answer 1st lines differ - expected: '19', found: '-1294967289'
Test #4:
score: 0
Wrong Answer
time: 5ms
memory: 15708kb
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:
1000000008 7 1000000006 2000000007 1705032711 2000000007 6 1000000006 8 -294967289 2000000006 -294967289 8 2000000007 2000000007 7 -294967289 2000000008 705032710 2000000007 1000000005 -1294967288 7 7 -1294967289 2000000005 1000000007 1000000008 705032711 1000000006 7 5 1705032711 1705032714 2000000...
result:
wrong answer 1st lines differ - expected: '16', found: '1000000008'
Test #5:
score: 0
Wrong Answer
time: 1ms
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:
1000000003 3 4 2000000004 4 -1294967293 4 2000000004 3 -1294967293 2000000004 2000000004 1000000004 -294967293 1000000013 1000000004 705032708 1000000002 3 2000000003 1000000003 -1294967292 1000000004 -1294967292 4 1000000004 4 -1294967292 1000000004 4 -1294967292 4 1000000004 -1294967285 1705032707...
result:
wrong answer 1st lines differ - expected: '7', found: '1000000003'
Test #6:
score: 0
Wrong Answer
time: 1ms
memory: 15552kb
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 2000000004 1000000002 4 -1294967291 1000000009 1000000004 3 3 3 4 4 1000000004 4 1000000003 4 5 3 1000000004 5 4 4 2 4 2 4 1 1000000004 1000000003 2000000004 2000000004 3 1000000003 11 2000000005 3 1000000004 3 2 3 4 2000000005 -1294967292 3 4 3 1 2000000004 2000000003 2000000005 2000000005 4 3 3 ...
result:
wrong answer 1st lines differ - expected: '31', found: '5'
Test #7:
score: 0
Wrong Answer
time: 68ms
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:
115098132 -1769803756 -1064771050 410065430 410065429 1410065429 1705032726 -1179869162 820130838 -1884901866 -884901866 -1884901867 1525163542 115098134 705032726 -1179869162 2115098134 115098134 705032726 1820130838 -294967275 1410065429 -64771050 1705032726 -179869163 -1589934571 115098134 820130...
result:
wrong answer 1st lines differ - expected: '182', found: '115098132'
Test #8:
score: 0
Wrong Answer
time: 46ms
memory: 15552kb
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:
2000000005 2115098117 -884901883 -1884901883 5 410065413 -1474836475 410065413 525163525 -179869179 1820130821 -64771067 -179869179 1410065413 935228933 1705032709 115098117 705032709 1410065413 -359738363 -1474836475 525163525 2000000005 115098117 1115098117 -1589934587 230196229 -1884901883 211509...
result:
wrong answer 1st lines differ - expected: '47', found: '2000000005'
Test #9:
score: 0
Wrong Answer
time: 41ms
memory: 15624kb
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:
1000000006 -1179869178 -1884901882 2115098118 2000000006 705032710 1705032710 -1179869178 -1179869178 1000000006 -589934586 2115098118 -294967291 1115098118 -1884901882 410065414 2115098118 -294967290 -294967290 705032710 -294967290 -1589934586 -1589934586 -1294967290 1410065414 -1294967290 -1294967...
result:
wrong answer 1st lines differ - expected: '88', found: '1000000006'
Test #10:
score: 0
Wrong Answer
time: 41ms
memory: 15484kb
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:
1115098115 -244640253 935228931 -884901885 115098115 115098115 -474836477 115098115 -1884901885 705032707 1115098115 -1884901885 115098115 -1474836477 935228931 -1179869181 -1359738365 -1179869181 -1884901885 -1589934589 -1884901885 820130819 525163523 1115098115 1115098115 -1179869181 1705032707 -4...
result:
wrong answer 1st lines differ - expected: '25', found: '1115098115'