답안 #576429

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
576429 2022-06-13T05:55:55 Z amunduzbaev L-triominoes (CEOI21_ltriominoes) C++17
0 / 100
316 ms 524288 KB
#include "bits/stdc++.h"
using namespace std;
 
#define ar array
#define int long long

const int N = 14;
const int M = 1005;
int dp[M][N][1 << N];
int is[N][M];

signed main(){
	ios::sync_with_stdio(0); cin.tie(0);
	
	int n, m, k; cin>>n>>m>>k;
	vector<int> x(k), y(k), p;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			is[i][j] = 1;
		}
	} 
	for(int i=0;i<k;i++){
		cin>>x[i]>>y[i]; x[i]--, y[i]--;
		is[x[i]][y[i]] = 0;
	}
	
	int ch[4][2] = {
		{0, 0},
		{-1, 0},
		{-1, 1},
		{0, 1}
	};
	int P[4] = {1, 0, -1, 0}, mas[4] = {14, 13, 11, 7};
	int mask = (!is[0][1]);
	for(int i=0;i<n;i++){
		if(!is[i][0]) mask |= (1 << (i + 1));
	}
	//~ cout<<mask<<"\n";
	dp[0][1][mask] = 1;
	for(int i=0;i<m;i++){
		for(int j=1;j<n;j++){
			for(int mask=0;mask < (1 << (n + 1));mask++){
				if(!dp[i][j][mask]) continue;
				//~ cout<<i<<" "<<j<<" "<<mask<<"\n";
				int us = 0;
				for(int t=0;t<4;t++){
					us |= (is[j + ch[t][0]][i + ch[t][1]] & (t < 3 ? !(mask >> (j + P[t]) & 1) : 1)) << t;
				}
				//~ for(int l=0;l<4;l++) cout<<(us >> l & 1);
				//~ cout<<"\n";
				for(int t=0;t<4;t++){
					if((us & mas[t]) != mas[t]) continue;
					int m2 = mask;
					for(int l=0;l<4;l++){
						if(mas[t] >> l & 1){
							m2 |= (1 << (j + P[l]));
						}
					}
					if(t == 1 && !(mask >> j & 1)) continue;
					if(t == 3){
						m2 ^= (1 << j);
						m2 |= (!is[j][i + 1]) << j;
					}
					//~ cout<<m2<<"\n";
					if(j + 1 < n){
						dp[i][j + 1][m2] = 1;
					} else if(m2 >> n & 1) {
						//~ cout<<m2<<" ";
						m2 ^= (1 << n);
						m2 = m2 << 1 | (!is[0][i + 2]);
						//~ cout<<m2<<"\n";
						dp[i + 1][1][m2] = 1;
					}
				}
				if((mask >> (j - 1) & 1) && (mask >> j & 1)){
					int m2 = mask;
					if(j + 1 < n){
						m2 ^= (1 << j);
						m2 |= (!is[j][i+1]) << j;
						dp[i][j + 1][m2] = 1;
					} else if(m2 >> n & 1) {
						m2 ^= (1 << j);
						m2 |= (!is[j][i+1]) << j;
						m2 ^= (1 << n);
						m2 = m2 << 1 | (!is[0][i + 2]);
						dp[i + 1][1][m2] = 1;
					}
				}
			}
		}
	}
	
	if(dp[m][1][(1 << (n + 1)) - 1]) cout<<"YES\n";
	else cout<<"NO\n";
}

# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 3796 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 213 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 236 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 316 ms 375504 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 209 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 3796 KB Output isn't correct
2 Halted 0 ms 0 KB -