QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#88468#4107. 墙上的句子Jekyll_Y0 144ms9856kbC++143.1kb2023-03-16 11:48:012023-03-16 11:48:05

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-16 11:48:05]
  • Judged
  • Verdict: 0
  • Time: 144ms
  • Memory: 9856kb
  • [2023-03-16 11:48:01]
  • Submitted

answer

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define inf 0x3f3f3f3f
const int M = 705;
int read()
{
    int x=0,flag=1;
    char c;
    while((c=getchar())<'0' || c>'9') if(c=='-') flag=-1;
    while(c>='0' && c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
    return x*flag;
}
int n,m,cnt,ans,tot,S,T,f[M],dis[M];
int r[M],c[M];
char s[M][M];
queue<int> q;
set<string> p;
map<string,int> id;
struct edge
{
    int v,c,next;
    edge(int V=0,int C=0,int N=0) : v(V) , c(C) , next(N) {}
} e[M*M];
void add_edge(int u,int v,int c)
{
    printf("%d %d\n",u,v);
    e[++tot]=edge(v,c,f[u]),f[u]=tot;
    e[++tot]=edge(u,0,f[v]),f[v]=tot;
}
int bfs()
{
    memset(dis,0,sizeof dis);
    dis[S]=1;
    q.push(S);
    while(!q.empty())
    {
        int u=q.front();
        q.pop();
        for(int i=f[u]; i; i=e[i].next)
        {
            int v=e[i].v;
            if(e[i].c>0 && !dis[v])
            {
                dis[v]=dis[u]+1;
                q.push(v);
            }
        }
    }
    if(!dis[T]) return 0;
    return 1;
}
int dfs(int u,int ept)
{
    if(u==T) return ept;
    int flow=0,tmp=0;
    for(int i=f[u]; i; i=e[i].next)
    {
        int v=e[i].v;
        if(dis[u]+1==dis[v] && e[i].c)
        {
            tmp=dfs(v,min(e[i].c,ept));
            if(!tmp) continue;
            ept-=tmp;
            e[i].c-=tmp;
            e[i^1].c+=tmp;
            flow+=tmp;
            if(!ept) break;
        }
    }
    return flow;
}
void work(string s,int tp,int u)
{
    string a,b;
    int len=s.length();
    for(int i=0,r,flag; i<len; i=r+1)
    {
        r=i;
        if(s[i]=='_') continue;
        while(r+1<len && s[r+1]!='_') r++;
        a=s.substr(i,r-i+1);
        b=a;
        reverse(b.begin(),b.end());
        if(b<a) swap(a,b),flag=-1;
        else flag=1;
        if(a==b)
        {
            p.insert(a);
            continue;
        }
        if(!id.count(a))
        {
            id[a]=++cnt;
            id[b]=++cnt;
            add_edge(id[a],id[b],2);
        }
        flag*=tp;
        if(flag==1) add_edge(S,id[a],inf);
        else if(flag==-1) add_edge(id[b],T,inf);
        else add_edge(id[b],u,inf),add_edge(u,id[a],inf);
    }
}
void solve()
{
    p.clear();
    id.clear();
    n=read();
    m=read();
    cnt=n+m;
    for(int i=1; i<=n; i++) r[i]=read();
    for(int i=1; i<=m; i++) c[i]=read();
    for(int i=1; i<=n; i++) scanf("%s",s[i]+1);
    S=0;
    T=M-1;
    string tmp;
    for(int i=1; i<=n; i++)
    {
        tmp=s[i]+1;
        work(tmp,r[i],i);
    }
    for(int i=1; i<=m; i++)
    {
        tmp="";
        for(int j=1; j<=n; j++)
            tmp+=s[j][i];
        work(tmp,c[i],i+n);
    }
    while(bfs()) ans+=dfs(S,inf);
    printf("%d\n",ans+(int)(p.size()));
}
int main()
{
    int Cases=read();
    while(Cases--)
    {
        tot=1;
        ans=0;
        memset(f,0,sizeof f);
        solve();
    }
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 9384kb

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:

19 20
20 1
1 19
21 22
22 1
1 21
22 2
2 21
23 24
24 4
4 23
24 4
4 23
20 4
4 19
0 21
0 21
20 7
7 19
22 7
7 21
22 7
7 21
22 8
8 21
22 8
8 21
24 10
10 23
20 10
10 19
22 11
11 21
22 11
11 21
20 13
13 19
24 13
13 23
22 16
16 21
24 16
16 23
2
19 20
20 1
1 19
20 1
1 19
21 22
22 2
2 21
20 4
4 19
20 4
4 19
23...

result:

wrong answer 1st lines differ - expected: '2', found: '19 20'

Test #2:

score: 0
Wrong Answer
time: 6ms
memory: 9392kb

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:

19 20
20 1
1 19
21 22
22 1
1 21
23 24
24 1
1 23
25 26
26 2
2 25
26 2
2 25
22 4
4 21
20 4
4 19
24 4
4 23
0 19
0 25
0 23
0 21
27 28
0 27
0 27
22 8
8 21
28 8
8 27
24 10
10 23
29 30
30 10
10 29
22 10
10 21
22 13
13 21
24 13
13 23
26 704
24 16
16 23
26 17
17 25
6
19 20
20 1
1 19
20 1
1 19
21 22
22 1
1 21...

result:

wrong answer 1st lines differ - expected: '6', found: '19 20'

Test #3:

score: 0
Wrong Answer
time: 4ms
memory: 9464kb

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:

37 38
38 1
1 37
39 40
40 1
1 39
41 42
42 1
1 41
43 44
44 1
1 43
45 46
46 1
1 45
44 2
2 43
47 48
48 2
2 47
42 2
2 41
49 50
50 2
2 49
51 52
52 2
2 51
40 4
4 39
44 4
4 43
44 4
4 43
44 4
4 43
44 4
4 43
50 5
5 49
48 5
5 47
53 54
54 5
5 53
55 56
56 5
5 55
57 58
58 5
5 57
50 5
5 49
40 7
7 39
59 60
60 7
7 5...

result:

wrong answer 1st lines differ - expected: '19', found: '37 38'

Test #4:

score: 0
Wrong Answer
time: 1ms
memory: 9400kb

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:

37 38
38 1
1 37
39 40
40 1
1 39
41 42
42 1
1 41
43 44
44 1
1 43
45 46
46 1
1 45
47 48
48 1
1 47
49 50
50 2
2 49
40 2
2 39
51 52
52 2
2 51
53 54
54 2
2 53
55 56
56 2
2 55
57 58
58 2
2 57
46 4
4 45
59 60
60 4
4 59
48 4
4 47
40 4
4 39
61 62
62 4
4 61
63 64
64 5
5 63
50 5
5 49
65 66
66 5
5 65
67 68
68 5...

result:

wrong answer 1st lines differ - expected: '16', found: '37 38'

Test #5:

score: 0
Wrong Answer
time: 1ms
memory: 9820kb

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:

49 50
50 1
1 49
51 52
52 1
1 51
50 1
1 49
53 54
54 1
1 53
54 1
1 53
54 1
1 53
55 56
56 2
2 55
57 58
58 2
2 57
58 2
2 57
50 2
2 49
58 2
2 57
50 2
2 49
59 60
60 3
3 59
61 62
62 3
3 61
62 3
3 61
56 3
3 55
56 3
3 55
56 3
3 55
50 5
5 49
58 5
5 57
63 64
64 5
5 63
50 5
5 49
54 5
5 53
56 5
5 55
65 66
66 6
6...

result:

wrong answer 1st lines differ - expected: '7', found: '49 50'

Test #6:

score: 0
Wrong Answer
time: 11ms
memory: 9468kb

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:

49 50
50 704
51 52
52 704
53 54
54 704
55 56
56 704
57 58
58 704
59 60
60 704
60 2
2 59
58 2
2 57
61 62
62 2
2 61
63 64
64 2
2 63
64 2
2 63
65 66
66 2
2 65
67 68
68 3
3 67
69 70
70 3
3 69
64 3
3 63
71 72
72 3
3 71
73 74
74 3
3 73
75 76
76 3
3 75
60 5
5 59
58 5
5 57
77 78
78 5
5 77
58 5
5 57
78 5
5 7...

result:

wrong answer 1st lines differ - expected: '31', found: '49 50'

Test #7:

score: 0
Wrong Answer
time: 144ms
memory: 9604kb

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:

145 146
146 704
147 148
148 704
149 150
150 704
151 152
152 704
153 154
154 704
155 156
156 704
157 158
158 704
159 160
160 704
161 162
162 704
163 164
164 704
165 166
166 704
167 168
168 704
169 170
170 704
171 172
172 704
173 174
174 704
175 176
176 704
177 178
178 704
179 180
180 704
181 182
182 ...

result:

wrong answer 1st lines differ - expected: '182', found: '145 146'

Test #8:

score: 0
Wrong Answer
time: 76ms
memory: 9428kb

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:

145 146
146 1
1 145
146 1
1 145
147 148
148 1
1 147
146 1
1 145
149 150
150 1
1 149
151 152
152 1
1 151
153 154
154 1
1 153
152 1
1 151
155 156
156 1
1 155
148 1
1 147
156 1
1 155
146 1
1 145
157 158
158 1
1 157
146 1
1 145
148 1
1 147
148 1
1 147
158 1
1 157
158 1
1 157
150 2
2 149
159 160
160 2
2 ...

result:

wrong answer 1st lines differ - expected: '47', found: '145 146'

Test #9:

score: 0
Wrong Answer
time: 87ms
memory: 9856kb

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:

145 146
146 1
1 145
147 148
148 1
1 147
149 150
150 1
1 149
151 152
152 1
1 151
146 1
1 145
153 154
154 1
1 153
155 156
156 1
1 155
157 158
158 1
1 157
156 1
1 155
154 1
1 153
148 1
1 147
159 160
160 1
1 159
161 162
162 1
1 161
154 1
1 153
148 1
1 147
163 164
164 1
1 163
165 166
166 1
1 165
167 168
...

result:

wrong answer 1st lines differ - expected: '88', found: '145 146'

Test #10:

score: 0
Wrong Answer
time: 48ms
memory: 9768kb

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:

141 142
142 1
1 141
143 144
144 1
1 143
144 1
1 143
145 146
146 1
1 145
144 1
1 143
142 1
1 141
147 148
148 1
1 147
146 1
1 145
146 1
1 145
144 1
1 143
146 1
1 145
144 1
1 143
142 1
1 141
148 1
1 147
149 150
150 2
2 149
146 2
2 145
142 2
2 141
142 2
2 141
142 2
2 141
150 2
2 149
151 152
152 2
2 151
...

result:

wrong answer 1st lines differ - expected: '25', found: '141 142'