QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#101792#6380. LaLa and Divination MagicZeardoeTL 753ms201932kbC++202.9kb2023-05-01 09:19:462023-05-01 09:19:48

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-01 09:19:48]
  • 评测
  • 测评结果:TL
  • 用时:753ms
  • 内存:201932kb
  • [2023-05-01 09:19:46]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
//use ll instead of int.
#define f(i, a, b) for(int i = (a); i <= (b); i++)
#define cl(i, n) i.clear(),i.resize(n);
#define endl '\n'
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int inf = 1e9;
//#define cerr if(false)cerr
//#define freopen if(false)freopen
#define watch(x) cerr  << (#x) << ' '<<'i'<<'s'<<' ' << x << endl
void pofe(int number, int bitnum) {
    string s; f(i, 0, bitnum) {s += char(number & 1) + '0'; number >>= 1; } 
    reverse(s.begin(), s.end()); cerr << s << endl; 
    return;
}
template <typename TYP> void cmax(TYP &x, TYP y) {if(x < y) x = y;}
template <typename TYP> void cmin(TYP &x, TYP y) {if(x > y) x = y;}
//调不出来给我对拍!
//use std::array.
time_t alltime = 0;
vector<bitset<2000>> s;int ord[2020];
int n,m; struct syz {int x,y,z;};
bitset<4000000> vt[4];int trie[2020*2020][2];int cnt=1;int memo[2020];
bool dfs(int step, int cur) {
  //  cerr<<step<<" "<<cur<<endl;
  //  f(i,0,step-1)cerr<<memo[i];
  //  cerr<<endl;
    if(step==m){return cur;}
    f(i,0,1){
        bool ok=1;
        f(j,0,step-1)if(vt[(memo[j]<<1) + i][j*m+step]==0){ok=0;break;}
        if(vt[(i<<1)+i][step*m+step]==0){ok=0;}
        if(ok){
            memo[step]=i;
            if(cur==0){
                if(!dfs(step+1,0)) return 0;
            }
            else {
                if(!dfs(step+1,trie[cur][i])) return 0;
            }
        }
    }
    return 1;
}
void build(){
    f(i,0,n-1){
        int cur=1;
        f(j,0,m-1){
            if(!trie[cur][s[i][j]]) trie[cur][s[i][j]] = ++cnt;
            cur = trie[cur][s[i][j]];
        }
    }
    return;
}
signed main() {
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    //  freopen("G.in","r",stdin);
    //  freopen("G.out","w",stdout);
    //freopen();
    
    //think twice,code once.
    //think once,debug forever.
    cin>>n>>m;s.resize(n);
    f(i,0,n-1){f(j,0,m-1){char ct;cin>>ct;s[i][j]=ct-'0';}}build();
    mt19937 rng(time(0));
    shuffle(ord+1,ord+n+1,rng);vector<syz> v;
    f(k,0,n-1){
        f(i,0,m-1)f(j,0,i){
            vt[(s[k][j]<<1)+s[k][i]][j*m+i]=1;
        }
    }
    
    f(t,0,3)f(i,0,m-1)f(j,i,m-1){
        if(!vt[t][i*m+j]){if(i!=j || t==0 || t==3)v.push_back({i,j,(t==0?4:(t==3?1:t+1))});}
    }
    
    
    if(!dfs(0,1)) {
        cout << -1 << endl;
        
    //    cerr << "time used:" << alltime * 1.0 / CLOCKS_PER_SEC <<"s"<< endl;
        return 0;
    }
    // time_t finish = clock(); alltime += finish - start << endl;
    cout<<v.size()<<endl;
    for(syz it : v)cout<<it.x<<" "<<it.y<<" "<<it.z<<endl;
    //
  //  cerr << "time used:" << alltime * 1.0 / CLOCKS_PER_SEC <<"s"<< endl;
    return 0;
}
/*
2023/4/29
start thinking at 11:24


start coding at h:mm
finish debugging at h:mm
*/

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 5528kb

input:

2 1
1
0

output:

0

result:

ok Kout = 0, Kans = 0

Test #2:

score: 0
Accepted
time: 2ms
memory: 5528kb

input:

3 3
101
011
111

output:

6
0 1 4
0 2 4
1 2 4
2 2 4
0 2 3
1 2 3

result:

ok Kout = 6, Kans = 6

Test #3:

score: 0
Accepted
time: 1ms
memory: 5656kb

input:

2 1
0
1

output:

0

result:

ok Kout = 0, Kans = 0

Test #4:

score: 0
Accepted
time: 2ms
memory: 5528kb

input:

2 1
0
1

output:

0

result:

ok Kout = 0, Kans = 0

Test #5:

score: 0
Accepted
time: 2ms
memory: 5568kb

input:

2 1
1
0

output:

0

result:

ok Kout = 0, Kans = 0

Test #6:

score: 0
Accepted
time: 0ms
memory: 5532kb

input:

2 1
0
1

output:

0

result:

ok Kout = 0, Kans = 0

Test #7:

score: 0
Accepted
time: 2ms
memory: 5568kb

input:

2 1
0
1

output:

0

result:

ok Kout = 0, Kans = 0

Test #8:

score: 0
Accepted
time: 0ms
memory: 5656kb

input:

2 1
1
0

output:

0

result:

ok Kout = 0, Kans = 0

Test #9:

score: 0
Accepted
time: 2ms
memory: 3608kb

input:

1 1
1

output:

1
0 0 4

result:

ok Kout = 1, Kans = 1

Test #10:

score: 0
Accepted
time: 2ms
memory: 5644kb

input:

1 1
0

output:

1
0 0 1

result:

ok Kout = 1, Kans = 1

Test #11:

score: 0
Accepted
time: 2ms
memory: 5576kb

input:

2 1
1
0

output:

0

result:

ok Kout = 0, Kans = 0

Test #12:

score: 0
Accepted
time: 2ms
memory: 5528kb

input:

2 1
1
0

output:

0

result:

ok Kout = 0, Kans = 0

Test #13:

score: 0
Accepted
time: 0ms
memory: 5580kb

input:

2 4
0111
0010

output:

15
0 2 4
1 2 4
2 2 4
2 3 4
1 3 2
2 3 2
0 1 3
0 2 3
0 3 3
1 2 3
1 3 3
0 0 1
0 1 1
0 2 1
0 3 1

result:

ok Kout = 15, Kans = 15

Test #14:

score: 0
Accepted
time: 2ms
memory: 5580kb

input:

2 1
1
0

output:

0

result:

ok Kout = 0, Kans = 0

Test #15:

score: 0
Accepted
time: 2ms
memory: 5516kb

input:

4 2
10
11
01
00

output:

0

result:

ok Kout = 0, Kans = 0

Test #16:

score: 0
Accepted
time: 2ms
memory: 5532kb

input:

2 1
1
0

output:

0

result:

ok Kout = 0, Kans = 0

Test #17:

score: 0
Accepted
time: 0ms
memory: 5576kb

input:

2 4
0010
1000

output:

15
0 2 4
0 1 2
0 3 2
1 3 2
2 3 2
1 2 3
1 3 3
0 1 1
0 2 1
0 3 1
1 1 1
1 2 1
1 3 1
2 3 1
3 3 1

result:

ok Kout = 15, Kans = 15

Test #18:

score: 0
Accepted
time: 2ms
memory: 5516kb

input:

2 5
11101
00000

output:

21
0 1 2
0 2 2
0 3 2
0 4 2
1 2 2
1 3 2
1 4 2
2 3 2
2 4 2
0 1 3
0 2 3
0 4 3
1 2 3
1 4 3
2 4 3
3 4 3
0 3 1
1 3 1
2 3 1
3 3 1
3 4 1

result:

ok Kout = 21, Kans = 21

Test #19:

score: 0
Accepted
time: 2ms
memory: 5632kb

input:

5 4
0010
1001
0011
0101
1011

output:

-1

result:

ok Kout = -1, Kans = -1

Test #20:

score: 0
Accepted
time: 2ms
memory: 5540kb

input:

3 2
01
00
10

output:

1
0 1 1

result:

ok Kout = 1, Kans = 1

Test #21:

score: 0
Accepted
time: 2ms
memory: 5648kb

input:

3 2
10
11
00

output:

1
0 1 2

result:

ok Kout = 1, Kans = 1

Test #22:

score: 0
Accepted
time: 1ms
memory: 5584kb

input:

2 1
0
1

output:

0

result:

ok Kout = 0, Kans = 0

Test #23:

score: 0
Accepted
time: 2ms
memory: 5624kb

input:

3 27
111010110011101010011110110
010001110100000110100101101
000011111000000010011111001

output:

-1

result:

ok Kout = -1, Kans = -1

Test #24:

score: 0
Accepted
time: 2ms
memory: 5652kb

input:

3 7
1000100
0001100
0101111

output:

39
0 3 4
0 4 4
1 4 4
2 4 4
3 4 4
4 4 4
4 5 4
4 6 4
0 2 2
1 2 2
1 5 2
1 6 2
3 5 2
3 6 2
4 5 2
4 6 2
5 6 2
0 4 3
1 3 3
1 4 3
1 5 3
1 6 3
2 3 3
2 4 3
2 5 3
2 6 3
3 4 3
5 6 3
0 1 1
0 2 1
0 3 1
0 5 1
0 6 1
1 2 1
2 2 1
2 3 1
2 4 1
2 5 1
2 6 1

result:

ok Kout = 39, Kans = 39

Test #25:

score: 0
Accepted
time: 2ms
memory: 5704kb

input:

1 19
1010110011001101000

output:

532
0 0 4
0 1 4
0 2 4
0 3 4
0 4 4
0 5 4
0 6 4
0 7 4
0 8 4
0 9 4
0 10 4
0 11 4
0 12 4
0 13 4
0 14 4
0 15 4
0 16 4
0 17 4
0 18 4
1 2 4
1 4 4
1 5 4
1 8 4
1 9 4
1 12 4
1 13 4
1 15 4
2 2 4
2 3 4
2 4 4
2 5 4
2 6 4
2 7 4
2 8 4
2 9 4
2 10 4
2 11 4
2 12 4
2 13 4
2 14 4
2 15 4
2 16 4
2 17 4
2 18 4
3 4 4
3 5 4...

result:

ok Kout = 532, Kans = 532

Test #26:

score: 0
Accepted
time: 2ms
memory: 5556kb

input:

5 32
10101101001001001101111100100110
00110110010111010101011000011010
01010101110100000110001000010100
11010011000110101101110001011111
00111001110011110000000010000111

output:

-1

result:

ok Kout = -1, Kans = -1

Test #27:

score: 0
Accepted
time: 0ms
memory: 5556kb

input:

3 12
110010101000
110001011000
110101011001

output:

145
0 0 4
0 1 4
0 2 4
0 3 4
0 4 4
0 5 4
0 6 4
0 7 4
0 8 4
0 9 4
0 10 4
0 11 4
1 1 4
1 2 4
1 3 4
1 4 4
1 5 4
1 6 4
1 7 4
1 8 4
1 9 4
1 10 4
1 11 4
2 8 4
3 8 4
4 5 4
4 7 4
4 8 4
5 6 4
5 8 4
6 7 4
6 8 4
7 8 4
8 8 4
8 9 4
8 10 4
8 11 4
0 1 2
0 2 2
0 3 2
0 4 2
0 5 2
0 6 2
0 7 2
0 8 2
0 9 2
0 10 2
0 11 2
...

result:

ok Kout = 145, Kans = 145

Test #28:

score: 0
Accepted
time: 2ms
memory: 5616kb

input:

3 25
1110100100011100101100111
0100000001011101101010101
0111110111111001001110111

output:

-1

result:

ok Kout = -1, Kans = -1

Test #29:

score: 0
Accepted
time: 1ms
memory: 5520kb

input:

1 5
10110

output:

35
0 0 4
0 1 4
0 2 4
0 3 4
0 4 4
1 2 4
1 3 4
2 2 4
2 3 4
2 4 4
3 3 4
3 4 4
0 1 2
0 2 2
0 3 2
0 4 2
1 4 2
2 3 2
2 4 2
3 4 2
0 2 3
0 3 3
1 2 3
1 3 3
1 4 3
2 3 3
0 1 1
0 4 1
1 1 1
1 2 1
1 3 1
1 4 1
2 4 1
3 4 1
4 4 1

result:

ok Kout = 35, Kans = 35

Test #30:

score: 0
Accepted
time: 2ms
memory: 5584kb

input:

5 17
01011100010100110
01001101111011001
00100111001101010
10101000001010110
00101011010010001

output:

-1

result:

ok Kout = -1, Kans = -1

Test #31:

score: 0
Accepted
time: 1ms
memory: 5696kb

input:

3 30
010100010011100011010001010100
011111100101001100010101010010
011000010111111111000101101110

output:

-1

result:

ok Kout = -1, Kans = -1

Test #32:

score: 0
Accepted
time: 2ms
memory: 5548kb

input:

5 30
110010101001001100010110010000
011011111000011001101000100000
110101010111000000100100111000
001111011110101101101001101011
101100001101011110101010110000

output:

-1

result:

ok Kout = -1, Kans = -1

Test #33:

score: 0
Accepted
time: 2ms
memory: 5568kb

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: 5664kb

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: 2ms
memory: 5532kb

input:

3 5
11111
01000
01100

output:

18
0 1 4
1 1 4
1 2 4
1 3 4
1 4 4
0 3 2
0 4 2
1 2 2
1 3 2
1 4 2
2 3 2
2 4 2
3 4 2
0 1 3
0 2 3
0 3 3
0 4 3
3 4 3

result:

ok Kout = 18, Kans = 18

Test #36:

score: 0
Accepted
time: 0ms
memory: 5604kb

input:

7 9
000010100
101001100
110010111
000000110
100010101
101000100
101101100

output:

-1

result:

ok Kout = -1, Kans = -1

Test #37:

score: 0
Accepted
time: 2ms
memory: 5532kb

input:

1 4
0000

output:

22
0 1 2
0 2 2
0 3 2
1 2 2
1 3 2
2 3 2
0 1 3
0 2 3
0 3 3
1 2 3
1 3 3
2 3 3
0 0 1
0 1 1
0 2 1
0 3 1
1 1 1
1 2 1
1 3 1
2 2 1
2 3 1
3 3 1

result:

ok Kout = 22, Kans = 22

Test #38:

score: 0
Accepted
time: 2ms
memory: 5584kb

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: 5576kb

input:

3 10
0000000111
1011011111
0101111010

output:

-1

result:

ok Kout = -1, Kans = -1

Test #40:

score: 0
Accepted
time: 1ms
memory: 5632kb

input:

2 1
1
0

output:

0

result:

ok Kout = 0, Kans = 0

Test #41:

score: 0
Accepted
time: 2ms
memory: 3484kb

input:

1 5
00110

output:

35
0 2 4
0 3 4
1 2 4
1 3 4
2 2 4
2 3 4
2 4 4
3 3 4
3 4 4
0 1 2
0 4 2
1 4 2
2 3 2
2 4 2
3 4 2
0 1 3
0 2 3
0 3 3
0 4 3
1 2 3
1 3 3
1 4 3
2 3 3
0 0 1
0 1 1
0 2 1
0 3 1
0 4 1
1 1 1
1 2 1
1 3 1
1 4 1
2 4 1
3 4 1
4 4 1

result:

ok Kout = 35, Kans = 35

Test #42:

score: 0
Accepted
time: 2ms
memory: 5528kb

input:

6 9
100101111
100001110
100101010
001101000
101100010
010101110

output:

-1

result:

ok Kout = -1, Kans = -1

Test #43:

score: 0
Accepted
time: 8ms
memory: 13056kb

input:

6 836
001111110001001001101010101010011100010100100100111110110100101000100100000000011101110001011100111111111001101111111101101110010011000100100111111101011010101101011101010000100011100011000011111011011110000001010101001101110100001111111001000110111000010110001100110010010000101011001010101100...

output:

-1

result:

ok Kout = -1, Kans = -1

Test #44:

score: 0
Accepted
time: 753ms
memory: 201932kb

input:

1 1680
00110010011001010101000101001110100010100110000110011101101101011011011011011011000000100100001111110111011001000010100101111110011000011110001000000001001010010110001011101000000110011010000001101010010000101111000010110001001010000010001010110000110111011011001011010011100111110000100110110...

output:

4232760
0 2 4
0 3 4
0 6 4
0 9 4
0 10 4
0 13 4
0 15 4
0 17 4
0 19 4
0 23 4
0 25 4
0 28 4
0 29 4
0 30 4
0 32 4
0 36 4
0 38 4
0 41 4
0 42 4
0 47 4
0 48 4
0 51 4
0 52 4
0 53 4
0 55 4
0 56 4
0 58 4
0 59 4
0 61 4
0 63 4
0 64 4
0 66 4
0 67 4
0 69 4
0 70 4
0 72 4
0 73 4
0 75 4
0 76 4
0 78 4
0 79 4
0 86 4
0 ...

result:

ok Kout = 4232760, Kans = 4232760

Test #45:

score: 0
Accepted
time: 9ms
memory: 9660kb

input:

5 525
010011011010110111000101111001010011110110100011110111000110010010000011011011110001110100110101101111111001100010010011011011011101110010011011001111110100010011011001010111011001100011001000101100111000000100010100011011011110101010000011101110001001000000100101000000101011101010110101010110...

output:

-1

result:

ok Kout = -1, Kans = -1

Test #46:

score: 0
Accepted
time: 31ms
memory: 18020kb

input:

9 1369
10111110110000010001000001110000001000010000101111010111111000100001001011101000101011000111001000010110010100011001110101100010000010000010100010011100110011000011110001001001010100010100001111111000111110100100010000100100110111110101100011010100000011000011010111111101011001011001010010110...

output:

-1

result:

ok Kout = -1, Kans = -1

Test #47:

score: 0
Accepted
time: 35ms
memory: 31152kb

input:

7 1509
10100001100101000101100011100001010001111101001010100101000010000100010000100110001011000011111000111100011100000110100100011010011111011100111010101011110111011011100100101110011000110111100101101011010101100011101011110001011101001011010100000011001001110100111101101001100110101111011010011...

output:

-1

result:

ok Kout = -1, Kans = -1

Test #48:

score: 0
Accepted
time: 28ms
memory: 13020kb

input:

1 354
101000111100100010011000000111001111100100100101111010100100101010111001011110011010111111010010101111101101101010100011010000011011010101000011010000001101110011011000101101111011111001011010111100100001100000110000110011101011010011110011001100101100011101100010101001100101110011001011001011...

output:

187797
0 0 4
0 1 4
0 2 4
0 3 4
0 4 4
0 5 4
0 6 4
0 7 4
0 8 4
0 9 4
0 10 4
0 11 4
0 12 4
0 13 4
0 14 4
0 15 4
0 16 4
0 17 4
0 18 4
0 19 4
0 20 4
0 21 4
0 22 4
0 23 4
0 24 4
0 25 4
0 26 4
0 27 4
0 28 4
0 29 4
0 30 4
0 31 4
0 32 4
0 33 4
0 34 4
0 35 4
0 36 4
0 37 4
0 38 4
0 39 4
0 40 4
0 41 4
0 42 4
0 ...

result:

ok Kout = 187797, Kans = 187797

Test #49:

score: 0
Accepted
time: 17ms
memory: 18608kb

input:

5 1006
00111100011111100001101011101101000101000011011000111111110010111011001101010000100011001000000111001011010000001110010000101000010111100101100101101000110000011011101010111110101110100110000011001000010000011111000001011111101010110011100110010011010000000000100000111101000001000100101110100...

output:

-1

result:

ok Kout = -1, Kans = -1

Test #50:

score: 0
Accepted
time: 52ms
memory: 19148kb

input:

9 1851
11000110100010011010000110010000010111101010100110011010100101110011100000101101001010000010001011111110100001101000001101111011011011011110010110000111001101110011001011111001110001011101100110111111100101100101000110010001011001100101010111100000101111010110010000110111010100011010111101110...

output:

-1

result:

ok Kout = -1, Kans = -1

Test #51:

score: 0
Accepted
time: 4ms
memory: 9816kb

input:

7 695
001100011101000101000011101100000101000000010110110101110110100101010100100111101110100100110101110100111000011000000101111101010100010010101011100101111001100001101111000111000111010110101101001111110111110001010011011111110111111010101010100100111010101010100111110011001100101100110010111101...

output:

-1

result:

ok Kout = -1, Kans = -1

Test #52:

score: 0
Accepted
time: 1ms
memory: 3852kb

input:

8 231
010111111111010000001100101001011111011010100101010100111010100110111011111111101110001100001001101110001001000000001110010010010110011001011110100110110110101100101110101100101011000001101111101001110000101110110010000100111101010
00010011100001101010000101100000110001010100100010110011011111...

output:

-1

result:

ok Kout = -1, Kans = -1

Test #53:

score: -100
Time Limit Exceeded

input:

1751 1586
01101110101110010111101111101010000000001010101101111100000001001100010101101011011111100010010111010010010010111101000011101101010110011100010001111110110011001111111111010000101011010111101110010101010011100110001111101111010000001111101111101011110100011101101100000011100110100110000000...

output:


result: