QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#190795#6380. LaLa and Divination MagicmanizareWA 1ms5580kbC++142.6kb2023-09-29 14:24:122023-09-29 14:24:12

Judging History

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

  • [2023-09-29 14:24:12]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5580kb
  • [2023-09-29 14:24:12]
  • 提交

answer

#include <bits/stdc++.h> 
 
#define pb push_back
#define F first
#define S second 
#define all(a) a.begin(),a.end()
#define pii pair <int,int>
#define Pii pair< pii , pii >
using namespace std ;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int maxn = 2000  , maxq = 1e7 + 1 ,  inf = 1e9 + 10 , mod= 998244353 ,lg = 20 ;
int n , m ;
bitset <maxn> c[maxn] , an;
bitset <2*maxn> e[maxn],mark; 
vector <int> G[maxn] ;

inline int no(int x){
	return (x < n ? x+n : x-n); 
}

void add(int a, int b){
	G[no(a)].pb(b) ; 
	G[no(b)].pb(a);
}

void dfs(int v){
	mark[v] = 1;
	for(int i = 0 ; i < G[v].size() ; i++){
		int u = G[v][i ]; 
		if(mark[u] == 0){
			dfs(u) ;
		}
		e[v] |= e[u] ;
	}
}
int cnt=  2 , ch[1000000][2];  
void bui(int x){
	int v = 1; 
	for(int i = 0 ; i < n ; i++){
		int z = c[x][i] ; 
		if(ch[v][z] == 0){
			ch[v][z] = cnt;
			cnt++;
		}
		v = ch[v][z]; 
	}
}
void dfs2(int v , int x ,bitset <2*maxn> a){
	if(x == n+1)return ;
	if(ch[v][0] == 0){
		bitset <2*maxn> b = (e[x + n] | a) ; 
		bitset <2*maxn> x = (b<<n) & (b>>n) ;
		if(x.any()){
			cout << -1 ;
			exit(0) ;
		}
	}else{
		bitset <2*maxn> b = e[x + n] | a;
		dfs2(ch[v][0] , x+1 , b) ;
	}
	if(ch[v][1] == 0){
		bitset <2*maxn> b = (e[x] | a) ; 
		bitset <2*maxn> x = (b<<n) & (b>>n) ;
		if(x.any()){
			cout << -1 ;
			exit(0) ;
		}		
	}else{
		bitset <2*maxn> b = e[x] | a;
		dfs2(ch[v][1] , x+1 , b) ;		
	}
}

signed main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin >> m >> n ;
	for(int i = 0; i < m ;i++){
		for(int j = 0; j < n ; j++){
			char a ;
			cin>> a ;
			if(a=='1')c[j][i] = 1; 
		}
	}
	for(int i = 0 ; i < m ; i++){
		an[i] = 1; 
	}
	vector <pair <int ,pii> > s ;
	for(int i = 0 ;i < n ;i++){
		for(int j = i+1 ; j< n ;j++){
			bitset <maxn> a = ~c[i] , b = ~c[j] , k ;
			k = a&b&an ;
			if(k.any()){
				add(no(i) , no(j)) ;
				s.pb({1 , {i,j}}) ;
			}
			k = c[i] & b ;
			if(k.any()){
				add(i , no(j));
				s.pb({2 , {i ,j}}); 
			}
			k = a & c[j] ;
			if(k.any()){
				add(no(i) , j) ;
				s.pb({3 , {i ,j}});
			}
			k = c[i] & c[j] ;
			if(k.any()){
				add(i , j);
				s.pb({4 , {i ,j}});
			}
		}
	}
	for(int i = 0 ; i < n ; i++){
		e[i][i]=1;
	}
	for(int i =0 ; i < n ; i++){
		if(mark[i] == 1)continue ;
		dfs(i );
	}
	for(int i = 0 ; i < m ; i++){
		bui(i) ;
	}
	bitset <2*maxn> a; 
	dfs2(1 , 1 , a ) ;
	cout << s.size() << "\n"; 
	for(int i =0 ; i < s.size() ; i++){
		cout << s[i].S.F+1 << " " << s[i].S.S+1 << " "  << s[i].F  << "\n" ;
	}
}
/*

*/

详细

Test #1:

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

input:

2 1
1
0

output:

0

result:

ok Kout = 0, Kans = 0

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 5568kb

input:

3 3
101
011
111

output:

7
1 2 2
1 2 3
1 2 4
1 3 3
1 3 4
2 3 3
2 3 4

result:

wrong answer Integer parameter [name=y] equals to 3, violates the range [0, 2]