Submission #539000

# Submission time Handle Problem Language Result Execution time Memory
539000 2022-03-18T07:41:49 Z amunduzbaev L-triominoes (CEOI21_ltriominoes) C++17
0 / 100
59 ms 4428 KB
#include "bits/stdc++.h"
using namespace std;

#define ar array
#define int long long

struct mtx{
	vector<vector<int>> t;
	int n;
	
	mtx (int sz){
		n = sz;
		t.resize(n, vector<int>(n));
	}
	
	mtx operator * (mtx& b){
		mtx c(n);
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				for(int k=0;k<n;k++){
					c.t[i][j] |= (t[i][j] | b.t[i][j]);
				}
			}
		} return c;
	}
};

signed main(){
	ios::sync_with_stdio(0); cin.tie(0);
	
	int n, m, k; cin>>n>>m>>k;
	vector<ar<int, 2>> a(k);
	for(int i=0;i<k;i++){
		cin>>a[i][0]>>a[i][1];
		a[i][0]--, a[i][1]--;
	}
	
	vector<mtx> pw(30, mtx(n));
	{
		mtx dp(1 << n);
		for(int i=0;i < (1 << n);i++){
			for(int j=0;j < (1 << n);j++){
				int mask = 0, mm = i;
				for(int l=0;l<n;l++){
					if(mm >> l & 1) continue;
					mm |= (1 << l);
					if(l + 1 < n && !(mm >> (l + 1) & 1) && !(mask >> (l + (j >> l & 1)) & 1) && 
					(j >> l & 1) == (j >> (l + 1) & 1)){
						mm |= (1 << (l + 1));
						mask |= (1 << (l + (j >> l & 1)));
					} else if((j >> l & 1) && l + 1 < n && !(mask >> (l + 1) & 1) && !(mask >> l & 1)){
						mask |= (1 << l);
						mask |= (1 << (l + 1));
					} else if(!(j >> l & 1) && l && !(mask >> (l - 1) & 1) && !(mask >> l & 1)){
						mask |= (1 << l);
						mask |= (1 << (l - 1));
					}
				}
				
				if(mm == (1 << n) - 1 && !dp.t[i][mask]){
					//~ for(int j=0;j<n;j++) cout<<(i >> j & 1);
					//~ cout<<endl;
					//~ for(int j=0;j<n;j++) cout<<(mask >> j & 1);
					//~ cout<<endl<<endl;
					dp.t[i][mask] = 1;
				}
			}
		}
		
		pw[0] = dp;
		for(int j=1;j<30;j++){
			pw[j] = pw[j-1] * pw[j-1];
		}
	}
	
	sort(a.begin(), a.end(), [&](auto& a, auto& b){
		return (a[1] < b[1]);
	});
	
	vector<int> dp(1 << n);
	dp[(1 << n) - 1] = 1;
	int last = -1;
	for(int i=0;i<k;){
		int j = i, bad = (1 << n) - 1;
		while(j<k && a[j][1] == a[i][1]) bad ^= (1 << a[j][0]), j++;
		int d = a[i][1] - last, rev = (1 << n) - 1 - bad;;
		for(int l=29;~l;l--){
			if(d >> l & 1){
				vector<int> tp(1 << n);
				for(int mask=0;mask < (1 << n);mask++){
					for(int j=0;j < (1 << n);j++){
						if((j & bad) != j) continue;
						tp[j | rev] |= dp[mask] & pw[l].t[mask][j];
					}
				}
				swap(tp, dp);
			} 
		} last = a[i][1], i = j;
	}
	
	if(!k){
		int d = m - last - 1;
		for(int l=29;~l;l--){
			if(d >> l & 1){
				vector<int> tp(1 << n);
				for(int mask=0;mask < (1 << n);mask++){
					for(int j=0;j < (1 << n);j++){
						tp[j] |= dp[mask] & pw[l].t[mask][j];
					}
				}
				
				swap(tp, dp);
			}
		}
	}
	
	if(dp[(1 << n) - 1]) cout<<"YES\n";
	else cout<<"NO\n";
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 320 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 42 ms 4428 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 56 ms 4428 KB Output is correct
2 Incorrect 59 ms 4328 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 320 KB Output isn't correct
2 Halted 0 ms 0 KB -