답안 #576762

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
576762 2022-06-13T12:03:37 Z amunduzbaev L-triominoes (CEOI21_ltriominoes) C++17
45 / 100
1430 ms 16248 KB
#include "bits/stdc++.h"
using namespace std;
 
#define ar array
#define int int64_t
const int N = 15;
const int M = 1005;
int dp[2][N][1 << N];
int is[N][M];


struct mtx{
	vector<vector<int>> t;
	int n;
	
	mtx (int sz){
		n = sz;
		t.resize(n, vector<int>(n, 0));
	}
	
	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][k] & b.t[k][j]);
				}
			}
		} return c;
	}
};
 
signed main(){
	ios::sync_with_stdio(0); cin.tie(0);
	
	int n, m, k; cin>>n>>m>>k;
	if(!k && m > 1000) {
		if(n == 3){
			if(m % 2 == 0) cout<<"YES\n";	
			else cout<<"NO\n";
			return 0;
		}
		
		if(n * m % 3 == 0) cout<<"YES\n"; 
		else cout<<"NO\n";
		return 0;
	}
	//~ if(m > 1000){
		//~ if(n < 6){
			//~ if((n * m) % 6 == 0) cout<<"YES\n";
			//~ else cout<<"NO\n";
		//~ } else {
			//~ if((n * m) % 3 == 0) cout<<"YES\n";
			//~ else cout<<"NO\n";
		//~ }
		//~ return 0;
	//~ }
	
	if(n <= 7){
		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(1 << n));
		{
			mtx dp(1 << n);
			for(int i=0;i < (1 << n);i++){
				for(int j=0;j < (1 << (n + n));j++){
					int mask = 0, mm = i;
					for(int l=0;l<n;l++){
						if(mm >> l & 1) continue;
						int v = (j >> (2 * l)) & 3;
						if(v == 0){
							if(l + 1 < n && !(mm >> (l + 1) & 1) && !(mask >> (l + 1) & 1)){
								mm |= (1 << l);
								mm |= (1 << (l + 1));
								mask |= (1 << (l + 1));
							}
						}
						if(v == 1){
							if(l + 1 < n && !(mm >> (l + 1) & 1) && !(mask >> l & 1)){
								mm |= (1 << l);
								mm |= (1 << (l + 1));
								mask |= (1 << l);
							}
						}
						if(v == 2){
							if(l && !(mask >> (l - 1) & 1) && !(mask >> l & 1)){
								mm |= (1 << l);
								mask |= (1 << l);
								mask |= (1 << (l - 1));
							}
						}
						if(v == 3){
							if(l + 1 < n && !(mask >> (l + 1) & 1) && !(mask >> l & 1)){
								mm |= (1 << l);
								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, rev = 0;
			while(j<k && a[j][1] == a[i][1]) rev |= (1 << a[j][0]), j++;
			
			int d = a[i][1] - last;
			//~ cout<<d<<endl;
			//~ for(int i=0;i<n;i++) cout<<(rev >> i & 1);
			//~ cout<<endl;
			for(int l=29;~l;l--){
				if(d >> l & 1){
					d ^= (1 << l);
					vector<int> tp(1 << n);
					for(int mask=0;mask < (1 << n);mask++){
						for(int j=0;j < (1 << n);j++){
							if(d){
								tp[j] |= (dp[mask] & pw[l].t[mask][j]);
							} else {
								if(j & rev) continue;
								//~ if(dp[mask] && pw[l].t[mask][j]){
									//~ for(int i=0;i<n;i++) cout<<(mask >> i & 1);
									//~ cout<<endl;
									//~ for(int i=0;i<n;i++) cout<<(j >> i & 1);
									//~ cout<<endl;
								//~ }
								tp[j | rev] |= (dp[mask] & pw[l].t[mask][j]);
							}
						}
					}
					swap(tp, dp);
				}
			} last = a[i][1], i = j;
		}
		
		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";
		return 0;
	}
	
	vector<int> x(k), y(k);
	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));
	}
	
	dp[0][1][mask] = 1;
	for(int i=0;i+1<m;i++){
		int c = i&1;
		memset(dp[!c], 0, sizeof dp[!c]);
		for(int j=1;j<n;j++){
			for(int mask=0;mask < (1 << (n + 1));mask++){
				if(!dp[c][j][mask]) continue;
				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 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){
							//~ assert(!(m2 >> (j + P[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;
					}
					
					if(j + 1 < n){
						dp[c][j + 1][m2] = 1;
					} else if(m2 >> n & 1) {
						m2 ^= (1 << n);
						m2 = m2 << 1 | (!is[0][i + 2]);
						dp[!c][1][m2] = 1;
					}
				}
				
				if(mask >> j & 1){
					int m2 = mask;
					if(j + 1 < n){
						m2 ^= (1 << j);
						m2 |= (!is[j][i+1]) << j;
						dp[c][j + 1][m2] = 1;
					} else if(m2 >> n & 1) {
						m2 ^= (1 << j) ^ (1 << n);
						m2 |= (!is[j][i+1]) << j;
						m2 = m2 << 1 | (!is[0][i + 2]);
						dp[!c][1][m2] = 1;
					}
				}
			}
		}
	}
	
	if(dp[(m-1)&1][1][(1 << (n + 1)) - 1]) cout<<"YES\n";
	else cout<<"NO\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 3 ms 596 KB Output is correct
7 Correct 99 ms 4572 KB Output is correct
8 Correct 90 ms 8052 KB Output is correct
9 Correct 40 ms 8020 KB Output is correct
10 Correct 41 ms 8032 KB Output is correct
11 Correct 167 ms 8048 KB Output is correct
12 Correct 50 ms 8020 KB Output is correct
13 Correct 3 ms 596 KB Output is correct
14 Correct 4 ms 596 KB Output is correct
15 Correct 19 ms 8020 KB Output is correct
16 Correct 1216 ms 8104 KB Output is correct
17 Correct 368 ms 8076 KB Output is correct
18 Correct 750 ms 8096 KB Output is correct
19 Correct 102 ms 4592 KB Output is correct
20 Correct 1270 ms 8104 KB Output is correct
21 Correct 760 ms 8100 KB Output is correct
22 Correct 2 ms 596 KB Output is correct
23 Correct 102 ms 4580 KB Output is correct
24 Correct 2 ms 596 KB Output is correct
25 Correct 1341 ms 8096 KB Output is correct
26 Correct 1430 ms 8112 KB Output is correct
27 Correct 2 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 3 ms 8020 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 328 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 328 KB Output is correct
20 Correct 1 ms 328 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 328 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 328 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 328 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 2 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 328 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 336 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 332 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 5 ms 632 KB Output is correct
4 Correct 3 ms 596 KB Output is correct
5 Correct 16 ms 1440 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 3 ms 596 KB Output is correct
8 Correct 3 ms 596 KB Output is correct
9 Correct 2 ms 628 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 6 ms 596 KB Output is correct
12 Correct 25 ms 1360 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 5 ms 596 KB Output is correct
16 Correct 20 ms 1364 KB Output is correct
17 Correct 5 ms 596 KB Output is correct
18 Correct 5 ms 596 KB Output is correct
19 Correct 20 ms 1356 KB Output is correct
20 Correct 16 ms 1436 KB Output is correct
21 Correct 3 ms 596 KB Output is correct
22 Correct 15 ms 1444 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 7 ms 588 KB Output is correct
25 Correct 21 ms 1364 KB Output is correct
26 Correct 3 ms 340 KB Output is correct
27 Correct 5 ms 596 KB Output is correct
28 Correct 5 ms 596 KB Output is correct
29 Correct 4 ms 596 KB Output is correct
30 Correct 3 ms 596 KB Output is correct
31 Correct 5 ms 596 KB Output is correct
32 Correct 21 ms 1364 KB Output is correct
33 Correct 21 ms 1412 KB Output is correct
34 Correct 16 ms 1444 KB Output is correct
35 Correct 15 ms 1352 KB Output is correct
36 Correct 3 ms 596 KB Output is correct
37 Correct 19 ms 1364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 133 ms 4576 KB Output is correct
2 Correct 101 ms 4572 KB Output is correct
3 Runtime error 12 ms 16248 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 3 ms 596 KB Output is correct
7 Correct 99 ms 4572 KB Output is correct
8 Correct 90 ms 8052 KB Output is correct
9 Correct 40 ms 8020 KB Output is correct
10 Correct 41 ms 8032 KB Output is correct
11 Correct 167 ms 8048 KB Output is correct
12 Correct 50 ms 8020 KB Output is correct
13 Correct 3 ms 596 KB Output is correct
14 Correct 4 ms 596 KB Output is correct
15 Correct 19 ms 8020 KB Output is correct
16 Correct 1216 ms 8104 KB Output is correct
17 Correct 368 ms 8076 KB Output is correct
18 Correct 750 ms 8096 KB Output is correct
19 Correct 102 ms 4592 KB Output is correct
20 Correct 1270 ms 8104 KB Output is correct
21 Correct 760 ms 8100 KB Output is correct
22 Correct 2 ms 596 KB Output is correct
23 Correct 102 ms 4580 KB Output is correct
24 Correct 2 ms 596 KB Output is correct
25 Correct 1341 ms 8096 KB Output is correct
26 Correct 1430 ms 8112 KB Output is correct
27 Correct 2 ms 596 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 0 ms 212 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 3 ms 8020 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
51 Correct 0 ms 212 KB Output is correct
52 Correct 0 ms 340 KB Output is correct
53 Correct 0 ms 212 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 1 ms 340 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 1 ms 336 KB Output is correct
59 Correct 0 ms 340 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 1 ms 340 KB Output is correct
62 Correct 1 ms 340 KB Output is correct
63 Correct 1 ms 340 KB Output is correct
64 Correct 1 ms 340 KB Output is correct
65 Correct 1 ms 332 KB Output is correct
66 Correct 1 ms 340 KB Output is correct
67 Correct 0 ms 328 KB Output is correct
68 Correct 1 ms 340 KB Output is correct
69 Correct 1 ms 340 KB Output is correct
70 Correct 1 ms 328 KB Output is correct
71 Correct 1 ms 328 KB Output is correct
72 Correct 1 ms 212 KB Output is correct
73 Correct 1 ms 328 KB Output is correct
74 Correct 1 ms 340 KB Output is correct
75 Correct 1 ms 340 KB Output is correct
76 Correct 1 ms 340 KB Output is correct
77 Correct 1 ms 328 KB Output is correct
78 Correct 0 ms 340 KB Output is correct
79 Correct 0 ms 340 KB Output is correct
80 Correct 1 ms 340 KB Output is correct
81 Correct 1 ms 328 KB Output is correct
82 Correct 1 ms 332 KB Output is correct
83 Correct 1 ms 340 KB Output is correct
84 Correct 2 ms 340 KB Output is correct
85 Correct 1 ms 340 KB Output is correct
86 Correct 1 ms 332 KB Output is correct
87 Correct 1 ms 340 KB Output is correct
88 Correct 1 ms 340 KB Output is correct
89 Correct 1 ms 340 KB Output is correct
90 Correct 1 ms 340 KB Output is correct
91 Correct 1 ms 340 KB Output is correct
92 Correct 1 ms 328 KB Output is correct
93 Correct 1 ms 340 KB Output is correct
94 Correct 1 ms 340 KB Output is correct
95 Correct 1 ms 340 KB Output is correct
96 Correct 1 ms 336 KB Output is correct
97 Correct 1 ms 340 KB Output is correct
98 Correct 1 ms 340 KB Output is correct
99 Correct 1 ms 332 KB Output is correct
100 Correct 1 ms 340 KB Output is correct
101 Correct 1 ms 340 KB Output is correct
102 Correct 1 ms 340 KB Output is correct
103 Correct 5 ms 632 KB Output is correct
104 Correct 3 ms 596 KB Output is correct
105 Correct 16 ms 1440 KB Output is correct
106 Correct 2 ms 596 KB Output is correct
107 Correct 3 ms 596 KB Output is correct
108 Correct 3 ms 596 KB Output is correct
109 Correct 2 ms 628 KB Output is correct
110 Correct 2 ms 340 KB Output is correct
111 Correct 6 ms 596 KB Output is correct
112 Correct 25 ms 1360 KB Output is correct
113 Correct 2 ms 340 KB Output is correct
114 Correct 1 ms 340 KB Output is correct
115 Correct 5 ms 596 KB Output is correct
116 Correct 20 ms 1364 KB Output is correct
117 Correct 5 ms 596 KB Output is correct
118 Correct 5 ms 596 KB Output is correct
119 Correct 20 ms 1356 KB Output is correct
120 Correct 16 ms 1436 KB Output is correct
121 Correct 3 ms 596 KB Output is correct
122 Correct 15 ms 1444 KB Output is correct
123 Correct 2 ms 340 KB Output is correct
124 Correct 7 ms 588 KB Output is correct
125 Correct 21 ms 1364 KB Output is correct
126 Correct 3 ms 340 KB Output is correct
127 Correct 5 ms 596 KB Output is correct
128 Correct 5 ms 596 KB Output is correct
129 Correct 4 ms 596 KB Output is correct
130 Correct 3 ms 596 KB Output is correct
131 Correct 5 ms 596 KB Output is correct
132 Correct 21 ms 1364 KB Output is correct
133 Correct 21 ms 1412 KB Output is correct
134 Correct 16 ms 1444 KB Output is correct
135 Correct 15 ms 1352 KB Output is correct
136 Correct 3 ms 596 KB Output is correct
137 Correct 19 ms 1364 KB Output is correct
138 Correct 133 ms 4576 KB Output is correct
139 Correct 101 ms 4572 KB Output is correct
140 Runtime error 12 ms 16248 KB Execution killed with signal 11
141 Halted 0 ms 0 KB -