QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#88611 | #4107. 墙上的句子 | Jekyll_Y | 0 | 385ms | 15620kb | C++14 | 4.3kb | 2023-03-16 19:06:16 | 2023-03-16 19:06:19 |
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, int type)
{
if(!mp.count(s))push(s);
if(!(f ^ type))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))ans += !vis[str], vis[str] = 1;
else
{
if(r[i] != 0)
insert(str, check2(str), (r[i] == 1));
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))ans += !vis[str], vis[str] = 1;
else
{
if(c[j] != 0)
insert(str, check2(str), (c[j] == 1));
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: 2ms
memory: 15532kb
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:
2 3 3 3 2000000007 2 -294967291 2000000005 3 -294967293 -294967293 3 2000000003 2 5 3 4 1705032707 2000000005 3 -1179869181 3 -589934589 3 -294967293 1115098115 3 3 3 2 3 -884901885 3 3 3 2000000005 -294967294 -589934585 2000000003 3 3 3 -294967293 2000000005 -294967293 2 -884901881 3 3 -294967293 2...
result:
wrong answer 5th lines differ - expected: '7', found: '2000000007'
Test #2:
score: 0
Wrong Answer
time: 2ms
memory: 15516kb
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 -294967291 2000000005 -294967293 3 4 4 2000000007 3 -294967288 6 -294967292 2000000005 -294967293 2000000005 3 1705032707 2000000008 -589934587 2000000004 4 -294967288 3 6 4 -294967292 -294967294 3 4 3 4 4 2000000005 3 -294967290 4 2000000008 4 3 4 2000000006 4 2000000004 4 -589934586 -29...
result:
wrong answer 1st lines differ - expected: '6', found: '2000000004'
Test #3:
score: 0
Wrong Answer
time: 5ms
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:
1410065425 -589934569 2000000012 -359738354 -64771061 -294967287 22 2000000013 2000000017 1705032735 6 1410065424 11 7 -589934571 1640261652 -294967287 1115098126 525163528 7 7 1705032723 -1179869173 1410065431 -949672949 1410065421 -294967281 17 1345294351 2000000021 1705032729 230196243 -294967285...
result:
wrong answer 1st lines differ - expected: '19', found: '1410065425'
Test #4:
score: 0
Wrong Answer
time: 3ms
memory: 15544kb
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:
18 13 -589934568 11 15 -1474836461 2000000012 1410065416 8 -949672939 -589934582 15 1115098130 -1179869173 -654705637 525163547 1115098129 8 -589934570 1410065435 1410065431 -1769803748 -1769803745 -589934577 21 5 -589934569 -294967276 820130843 6 7 5 -589934583 -64771044 2000000025 2000000024 -3597...
result:
wrong answer 1st lines differ - expected: '16', found: '18'
Test #5:
score: 0
Wrong Answer
time: 1ms
memory: 15488kb
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:
7 3 -424509422 690588686 820130834 -589934587 4 2000000010 3 1705032725 1410065420 -589934580 1640261642 -1834574843 -719476731 1115098128 -64771056 -589934576 3 -1179869177 -64771063 -294967288 1705032720 525163532 1705032714 8 1705032722 4 1115098130 -294967282 -359738354 -589934586 525163536 -654...
result:
wrong answer 3rd lines differ - expected: '32', found: '-424509422'
Test #6:
score: 0
Wrong Answer
time: 14ms
memory: 15548kb
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:
1640261645 525163538 1705032712 1115098126 1115098123 1050327061 -1474836456 -589934571 3 525163535 1705032720 2000000016 4 2000000016 -424509413 -294967286 1705032715 -589934571 -589934576 5 -1179869166 230196242 1345294342 525163536 -884901864 1935228948 13 10 -1179869163 1410065428 1410065430 -58...
result:
wrong answer 1st lines differ - expected: '31', found: '1640261645'
Test #7:
score: 0
Wrong Answer
time: 385ms
memory: 15584kb
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:
35883262 -21892856 1754905704 -424509296 2071766157 1971112103 165425370 -1669149528 1050327104 431504658 -949672692 1251635347 927780032 -554051452 1215752344 1021439090 -913789790 -28887922 -1604378550 -1633266536 820130861 -323855219 -2086664014 -2129542054 -316860231 -259084151 1150981348 -42450...
result:
wrong answer 1st lines differ - expected: '182', found: '35883262'
Test #8:
score: 0
Wrong Answer
time: 285ms
memory: 15620kb
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:
2100654093 -2093659105 2100654119 330850325 460392477 366733325 -611827687 -1798691805 2078760993 1381177373 856013841 -575944655 1251635235 -654705649 1754905649 1841569827 -913789937 35883023 1215752249 -647710697 -1726925797 -712481755 -849018839 798237719 762354719 -1438953463 1352289321 -150372...
result:
wrong answer 1st lines differ - expected: '47', found: '2100654093'
Test #9:
score: 0
Wrong Answer
time: 277ms
memory: 15528kb
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:
-1172874206 -388626356 -518168512 -1331304410 791242802 395621398 71766090 -1136991192 1625363534 791242790 1186864168 1517714456 -1374182345 431504412 -287972302 1611373614 1719022646 -1669149672 1906340932 1280523316 1186864184 2100654124 827125796 -849018852 -1863462862 1611373616 496275484 79124...
result:
wrong answer 1st lines differ - expected: '88', found: '-1172874206'
Test #10:
score: 0
Wrong Answer
time: 146ms
memory: 15616kb
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:
-913789943 898891783 -1136991223 1215752215 -1604378613 827125777 -1403070451 -1208757231 -489280505 -1079215083 1971111957 -489280499 -28888047 -2057776111 -1338299377 -1604378609 -1467841519 -784247791 920784907 -1899345909 1381177351 -287972343 791242773 1445948429 1445948439 -129542127 165425163...
result:
wrong answer 1st lines differ - expected: '25', found: '-913789943'