QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#101815 | #6380. LaLa and Divination Magic | zhouhuanyi | TL | 799ms | 17048kb | C++11 | 2.6kb | 2023-05-01 10:57:16 | 2023-05-01 10:57:19 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<bitset>
#include<vector>
#define N 2000
#define M 4000
#define K 8000000
using namespace std;
int read()
{
char c=0;
int sum=0;
while (c<'0'||c>'9') c=getchar();
while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
return sum;
}
struct reads
{
int op,x,y;
};
reads tong[K+1];
int n,m,length,ans;
char c[N+1][N+1];
bool used[M+1],F[N+1][N+1][2][2];
bitset<N+1>B[M+1];
bitset<N+1>S1;
bitset<N+1>S2;
bitset<N+1>S3;
bitset<N+1>S4;
bitset<N+1>B1[M+1];
bitset<N+1>B2[M+1];
vector<int>E[M+1];
void add(int x,int y)
{
E[x].push_back(y);
return;
}
void dfs(int rt,int x)
{
if (x<=m) B1[rt][x]=1;
else B2[rt][x-m]=1;
used[x]=1;
for (int i=0;i<E[x].size();++i)
if (!used[E[x][i]])
dfs(rt,E[x][i]);
return;
}
void dfs2(int x,bitset<N+1>st1,bitset<N+1>st2)
{
if (x==m+1)
{
ans++;
return;
}
if (!((st1|B1[x])&(st2|B2[x])).count()) dfs2(x+1,st1|B1[x],st2|B2[x]);
if (!((st1|B1[x+m])&(st2|B2[x+m])).count()) dfs2(x+1,st1|B1[x+m],st2|B2[x+m]);
if (ans>n) return;
return;
}
int main()
{
n=read(),m=read();
for (int i=1;i<=n;++i)
for (int j=1;j<=m;++j)
{
cin>>c[i][j];
if (c[i][j]=='1') B[i][j]=1;
}
for (int i=1;i<=m;++i)
{
S1.reset(),S2.reset();
for (int j=1;j<=n;++j)
{
if (c[j][i]=='1') S1|=B[j];
else S2|=B[j];
}
for (int j=1;j<=i;++j)
{
if (S1[j]) F[j][i][1][1]=1;
if (S2[j]) F[j][i][1][0]=1;
}
S1.set(),S2.set();
for (int j=1;j<=n;++j)
{
if (c[j][i]=='1') S1&=B[j];
else S2&=B[j];
}
for (int j=1;j<=i;++j)
{
if (!S1[j]) F[j][i][0][1]=1;
if (!S2[j]) F[j][i][0][0]=1;
}
}
for (int i=1;i<=m;++i)
for (int j=i;j<=m;++j)
{
if (!F[i][j][1][1]) add(i+m,j),add(j+m,i);
if (!F[i][j][0][1]) add(i,j),add(j+m,i+m);
if (!F[i][j][1][0]) add(i+m,j+m),add(j,i);
if (!F[i][j][0][0]) add(i,j+m),add(j,i+m);
}
for (int i=1;i<=(m<<1);++i)
{
for (int j=1;j<=(m<<1);++j) used[j]=0;
dfs(i,i);
}
dfs2(1,S3,S4);
if (ans>n)
{
puts("-1");
return 0;
}
for (int i=1;i<=m;++i)
for (int j=i;j<=m;++j)
{
if (!F[i][j][1][1]) tong[++length]=(reads){1,i,j};
if (i<j&&!F[i][j][0][1]) tong[++length]=(reads){2,i,j};
if (i<j&&!F[i][j][1][0]) tong[++length]=(reads){3,i,j};
if (!F[i][j][0][0]) tong[++length]=(reads){4,i,j};
}
printf("%d\n",length);
for (int i=1;i<=length;++i) printf("%d %d %d\n",tong[i].x-1,tong[i].y-1,tong[i].op);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 7844kb
input:
2 1 1 0
output:
0
result:
ok Kout = 0, Kans = 0
Test #2:
score: 0
Accepted
time: 3ms
memory: 7856kb
input:
3 3 101 011 111
output:
6 0 1 4 0 2 3 0 2 4 1 2 3 1 2 4 2 2 4
result:
ok Kout = 6, Kans = 6
Test #3:
score: 0
Accepted
time: 2ms
memory: 7772kb
input:
2 1 0 1
output:
0
result:
ok Kout = 0, Kans = 0
Test #4:
score: 0
Accepted
time: 3ms
memory: 9816kb
input:
2 1 0 1
output:
0
result:
ok Kout = 0, Kans = 0
Test #5:
score: 0
Accepted
time: 3ms
memory: 11964kb
input:
2 1 1 0
output:
0
result:
ok Kout = 0, Kans = 0
Test #6:
score: 0
Accepted
time: 3ms
memory: 9780kb
input:
2 1 0 1
output:
0
result:
ok Kout = 0, Kans = 0
Test #7:
score: 0
Accepted
time: 0ms
memory: 9908kb
input:
2 1 0 1
output:
0
result:
ok Kout = 0, Kans = 0
Test #8:
score: 0
Accepted
time: 3ms
memory: 9860kb
input:
2 1 1 0
output:
0
result:
ok Kout = 0, Kans = 0
Test #9:
score: 0
Accepted
time: 3ms
memory: 9876kb
input:
1 1 1
output:
1 0 0 4
result:
ok Kout = 1, Kans = 1
Test #10:
score: 0
Accepted
time: 3ms
memory: 7804kb
input:
1 1 0
output:
1 0 0 1
result:
ok Kout = 1, Kans = 1
Test #11:
score: 0
Accepted
time: 0ms
memory: 7836kb
input:
2 1 1 0
output:
0
result:
ok Kout = 0, Kans = 0
Test #12:
score: 0
Accepted
time: 0ms
memory: 7776kb
input:
2 1 1 0
output:
0
result:
ok Kout = 0, Kans = 0
Test #13:
score: 0
Accepted
time: 1ms
memory: 7808kb
input:
2 4 0111 0010
output:
15 0 0 1 0 1 1 0 1 3 0 2 1 0 2 3 0 2 4 0 3 1 0 3 3 1 2 3 1 2 4 1 3 2 1 3 3 2 2 4 2 3 2 2 3 4
result:
ok Kout = 15, Kans = 15
Test #14:
score: 0
Accepted
time: 1ms
memory: 7868kb
input:
2 1 1 0
output:
0
result:
ok Kout = 0, Kans = 0
Test #15:
score: 0
Accepted
time: 2ms
memory: 7856kb
input:
4 2 10 11 01 00
output:
0
result:
ok Kout = 0, Kans = 0
Test #16:
score: 0
Accepted
time: 2ms
memory: 5748kb
input:
2 1 1 0
output:
0
result:
ok Kout = 0, Kans = 0
Test #17:
score: 0
Accepted
time: 0ms
memory: 5672kb
input:
2 4 0010 1000
output:
15 0 1 1 0 1 2 0 2 1 0 2 4 0 3 1 0 3 2 1 1 1 1 2 1 1 2 3 1 3 1 1 3 2 1 3 3 2 3 1 2 3 2 3 3 1
result:
ok Kout = 15, Kans = 15
Test #18:
score: 0
Accepted
time: 2ms
memory: 5768kb
input:
2 5 11101 00000
output:
21 0 1 2 0 1 3 0 2 2 0 2 3 0 3 1 0 3 2 0 4 2 0 4 3 1 2 2 1 2 3 1 3 1 1 3 2 1 4 2 1 4 3 2 3 1 2 3 2 2 4 2 2 4 3 3 3 1 3 4 1 3 4 3
result:
ok Kout = 21, Kans = 21
Test #19:
score: 0
Accepted
time: 2ms
memory: 7616kb
input:
5 4 0010 1001 0011 0101 1011
output:
-1
result:
ok Kout = -1, Kans = -1
Test #20:
score: 0
Accepted
time: 0ms
memory: 5736kb
input:
3 2 01 00 10
output:
1 0 1 1
result:
ok Kout = 1, Kans = 1
Test #21:
score: 0
Accepted
time: 3ms
memory: 7776kb
input:
3 2 10 11 00
output:
1 0 1 2
result:
ok Kout = 1, Kans = 1
Test #22:
score: 0
Accepted
time: 2ms
memory: 5808kb
input:
2 1 0 1
output:
0
result:
ok Kout = 0, Kans = 0
Test #23:
score: 0
Accepted
time: 0ms
memory: 7872kb
input:
3 27 111010110011101010011110110 010001110100000110100101101 000011111000000010011111001
output:
-1
result:
ok Kout = -1, Kans = -1
Test #24:
score: 0
Accepted
time: 1ms
memory: 7896kb
input:
3 7 1000100 0001100 0101111
output:
39 0 1 1 0 2 1 0 2 2 0 3 1 0 3 4 0 4 3 0 4 4 0 5 1 0 6 1 1 2 1 1 2 2 1 3 3 1 4 3 1 4 4 1 5 2 1 5 3 1 6 2 1 6 3 2 2 1 2 3 1 2 3 3 2 4 1 2 4 3 2 4 4 2 5 1 2 5 3 2 6 1 2 6 3 3 4 3 3 4 4 3 5 2 3 6 2 4 4 4 4 5 2 4 5 4 4 6 2 4 6 4 5 6 2 5 6 3
result:
ok Kout = 39, Kans = 39
Test #25:
score: 0
Accepted
time: 3ms
memory: 7900kb
input:
1 19 1010110011001101000
output:
532 0 0 4 0 1 1 0 1 2 0 1 4 0 2 2 0 2 3 0 2 4 0 3 1 0 3 2 0 3 4 0 4 2 0 4 3 0 4 4 0 5 2 0 5 3 0 5 4 0 6 1 0 6 2 0 6 4 0 7 1 0 7 2 0 7 4 0 8 2 0 8 3 0 8 4 0 9 2 0 9 3 0 9 4 0 10 1 0 10 2 0 10 4 0 11 1 0 11 2 0 11 4 0 12 2 0 12 3 0 12 4 0 13 2 0 13 3 0 13 4 0 14 1 0 14 2 0 14 4 0 15 2 0 15 3 0 15 4 0 ...
result:
ok Kout = 532, Kans = 532
Test #26:
score: 0
Accepted
time: 3ms
memory: 7880kb
input:
5 32 10101101001001001101111100100110 00110110010111010101011000011010 01010101110100000110001000010100 11010011000110101101110001011111 00111001110011110000000010000111
output:
-1
result:
ok Kout = -1, Kans = -1
Test #27:
score: 0
Accepted
time: 1ms
memory: 7868kb
input:
3 12 110010101000 110001011000 110101011001
output:
145 0 0 4 0 1 2 0 1 3 0 1 4 0 2 1 0 2 2 0 2 4 0 3 2 0 3 4 0 4 2 0 4 4 0 5 2 0 5 4 0 6 2 0 6 4 0 7 2 0 7 4 0 8 2 0 8 3 0 8 4 0 9 1 0 9 2 0 9 4 0 10 1 0 10 2 0 10 4 0 11 2 0 11 4 1 1 4 1 2 1 1 2 2 1 2 4 1 3 2 1 3 4 1 4 2 1 4 4 1 5 2 1 5 4 1 6 2 1 6 4 1 7 2 1 7 4 1 8 2 1 8 3 1 8 4 1 9 1 1 9 2 1 9 4 1 1...
result:
ok Kout = 145, Kans = 145
Test #28:
score: 0
Accepted
time: 1ms
memory: 7792kb
input:
3 25 1110100100011100101100111 0100000001011101101010101 0111110111111001001110111
output:
-1
result:
ok Kout = -1, Kans = -1
Test #29:
score: 0
Accepted
time: 1ms
memory: 5820kb
input:
1 5 10110
output:
35 0 0 4 0 1 1 0 1 2 0 1 4 0 2 2 0 2 3 0 2 4 0 3 2 0 3 3 0 3 4 0 4 1 0 4 2 0 4 4 1 1 1 1 2 1 1 2 3 1 2 4 1 3 1 1 3 3 1 3 4 1 4 1 1 4 2 1 4 3 2 2 4 2 3 2 2 3 3 2 3 4 2 4 1 2 4 2 2 4 4 3 3 4 3 4 1 3 4 2 3 4 4 4 4 1
result:
ok Kout = 35, Kans = 35
Test #30:
score: 0
Accepted
time: 0ms
memory: 7768kb
input:
5 17 01011100010100110 01001101111011001 00100111001101010 10101000001010110 00101011010010001
output:
-1
result:
ok Kout = -1, Kans = -1
Test #31:
score: 0
Accepted
time: 1ms
memory: 7844kb
input:
3 30 010100010011100011010001010100 011111100101001100010101010010 011000010111111111000101101110
output:
-1
result:
ok Kout = -1, Kans = -1
Test #32:
score: 0
Accepted
time: 4ms
memory: 7808kb
input:
5 30 110010101001001100010110010000 011011111000011001101000100000 110101010111000000100100111000 001111011110101101101001101011 101100001101011110101010110000
output:
-1
result:
ok Kout = -1, Kans = -1
Test #33:
score: 0
Accepted
time: 3ms
memory: 7732kb
input:
10 10 0110101111 1100100000 1000101100 1000010101 1001011101 1011101101 1011111011 0101010000 0111011010 1111010110
output:
-1
result:
ok Kout = -1, Kans = -1
Test #34:
score: 0
Accepted
time: 0ms
memory: 7720kb
input:
9 10 1000001101 0110010110 1011101111 1010001110 1110001000 1001110110 1101010010 0001011111 1000010100
output:
-1
result:
ok Kout = -1, Kans = -1
Test #35:
score: 0
Accepted
time: 3ms
memory: 7812kb
input:
3 5 11111 01000 01100
output:
18 0 1 3 0 1 4 0 2 3 0 3 2 0 3 3 0 4 2 0 4 3 1 1 4 1 2 2 1 2 4 1 3 2 1 3 4 1 4 2 1 4 4 2 3 2 2 4 2 3 4 2 3 4 3
result:
ok Kout = 18, Kans = 18
Test #36:
score: 0
Accepted
time: 2ms
memory: 5668kb
input:
7 9 000010100 101001100 110010111 000000110 100010101 101000100 101101100
output:
-1
result:
ok Kout = -1, Kans = -1
Test #37:
score: 0
Accepted
time: 3ms
memory: 7808kb
input:
1 4 0000
output:
22 0 0 1 0 1 1 0 1 2 0 1 3 0 2 1 0 2 2 0 2 3 0 3 1 0 3 2 0 3 3 1 1 1 1 2 1 1 2 2 1 2 3 1 3 1 1 3 2 1 3 3 2 2 1 2 3 1 2 3 2 2 3 3 3 3 1
result:
ok Kout = 22, Kans = 22
Test #38:
score: 0
Accepted
time: 3ms
memory: 7660kb
input:
9 8 10011110 10111101 11001010 01000101 10110011 00101001 00101100 11010110 01000000
output:
-1
result:
ok Kout = -1, Kans = -1
Test #39:
score: 0
Accepted
time: 2ms
memory: 7648kb
input:
3 10 0000000111 1011011111 0101111010
output:
-1
result:
ok Kout = -1, Kans = -1
Test #40:
score: 0
Accepted
time: 2ms
memory: 5780kb
input:
2 1 1 0
output:
0
result:
ok Kout = 0, Kans = 0
Test #41:
score: 0
Accepted
time: 1ms
memory: 7872kb
input:
1 5 00110
output:
35 0 0 1 0 1 1 0 1 2 0 1 3 0 2 1 0 2 3 0 2 4 0 3 1 0 3 3 0 3 4 0 4 1 0 4 2 0 4 3 1 1 1 1 2 1 1 2 3 1 2 4 1 3 1 1 3 3 1 3 4 1 4 1 1 4 2 1 4 3 2 2 4 2 3 2 2 3 3 2 3 4 2 4 1 2 4 2 2 4 4 3 3 4 3 4 1 3 4 2 3 4 4 4 4 1
result:
ok Kout = 35, Kans = 35
Test #42:
score: 0
Accepted
time: 1ms
memory: 7660kb
input:
6 9 100101111 100001110 100101010 001101000 101100010 010101110
output:
-1
result:
ok Kout = -1, Kans = -1
Test #43:
score: 0
Accepted
time: 799ms
memory: 17048kb
input:
6 836 001111110001001001101010101010011100010100100100111110110100101000100100000000011101110001011100111111111001101111111101101110010011000100100111111101011010101101011101010000100011100011000011111011011110000001010101001101110100001111111001000110111000010110001100110010010000101011001010101100...
output:
-1
result:
ok Kout = -1, Kans = -1
Test #44:
score: -100
Time Limit Exceeded
input:
1 1680 00110010011001010101000101001110100010100110000110011101101101011011011011011011000000100100001111110111011001000010100101111110011000011110001000000001001010010110001011101000000110011010000001101010010000101111000010110001001010000010001010110000110111011011001011010011100111110000100110110...