#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int, int>
const int W = (1<<6);
int w;
struct Mat{
vector<vector<bool>> v;
Mat(){
v.resize(W, vector<bool>(W));
for(int i = 0; i<W; i++){
v[i][i] = true;
}
}
};
Mat prod(Mat a, Mat b){
Mat res;
for(int i = 0;i<W; i++){
res.v[i][i] =false;
}
for(int i =0;i<W; i++){
for(int j = 0; j<W; j++){
for(int h = 0; h<W; h++){
res.v[i][j] = res.v[i][j] || (a.v[i][h] && b.v[h][j]);
}
}
}
return res;
}
Mat from_set(int ks){
Mat res;
for(int i = 0; i<W; i++){
res.v[i][i] =false;
}
for(int i =0; i<W; i++){
if((i &ks) == 0){
res.v[i][i|ks] =true;
//cout<<bitset<W>(i)<<" "<<bitset<W>(i|ks)<<endl;
}
}
/*for(int i =0; i<W; i++){
for(int j =0; j<W; j++){
cout<<res.v[i][j]<<" ";
}
cout<<endl;
}*/
return res;
}
Mat pows[31];
void precalc_pows(){
for(int i = 1; i<31; i++){
pows[i] = prod(pows[i-1], pows[i-1]);
}
}
Mat mpow(int v){
Mat res;
for(int i = 0; i<31; i++){
if(v & (1LL<<i)){
res = prod(res, pows[i]);
}
}
return res;
}
vector<Mat> Matrices;
map<int, bitset<W>> obstacles;
vector<bitset<W>> aviable;
vector<bool> found;
bitset<W> all_aviable(bitset<W> lh, bitset<W> rh){
int id = lh.to_ullong() + rh.to_ullong() * W;
if(found[id]){
return aviable[id];
}
found[id] = true;
//cout<<lh<<" "<<rh<<endl;
for(int i = 0; i<w-1; i++){
if((!lh[i]) && (!rh[i+1])){
//cout<<"possible "<<i<<endl;
lh.set(i);
rh.set(i+1);
if(!rh[i]){
rh.set(i);
aviable[id] |= all_aviable(lh, rh);
rh.reset(i);
}
if(!lh[i+1]){
lh.set(i+1);
aviable[id]|= all_aviable(lh, rh);
lh.reset(i+1);
}
lh.reset(i);
rh.reset(i+1);
}
if((!lh[i+1]) && (!rh[i])){
rh.set(i);
lh.set(i+1);
if(!lh[i]){
lh.set(i);
aviable[id] |= all_aviable(lh, rh);
lh.reset(i);
}
if(!rh[i+1]){
rh.set(i+1);
aviable[id]|= all_aviable(lh, rh);
rh.reset(i+1);
}
rh.reset(i);
lh.reset(i+1);
}
}
return aviable[id];
}
vector<bitset<W>> interest;
signed main(){
cin.tie(NULL);
ios_base::sync_with_stdio(false);
int h, k;
cin>>w>>h>>k;
aviable.resize(W*W);
found.resize(W*W);
bitset<W> lh;
for(int i = 0; i<w; i++){
lh.set(i);
}
for(int rh = 0; rh<W; rh++){
int id = lh.to_ullong() + rh*W;
aviable[id].set(rh);
found[id] =true;
}
Mat transition;
for(int lhi = 0; lhi<W; lhi++){
interest.push_back(all_aviable(bitset<W>(lhi), bitset<W>(0)));
for(int rh = 0; rh<W; rh++){
transition.v[lhi][rh] = interest[lhi][rh];
}
}
pows[0] = transition;
precalc_pows();
for(int i = 0; i<k; i++){
int a, b;
cin>>a>>b;
a--;
b--;
obstacles[b].set(a);
}
if(obstacles.find(h-1) == obstacles.end()){
obstacles[h-1] = bitset<W>(0);
}
Mat res;
int cur_id = 0;
for(auto e: obstacles){
res = prod(res, mpow(e.first-cur_id));
cur_id = e.first;
res = prod(res, from_set(e.second.to_ullong()));
}
if(res.v[0][(1<<w)-1]){
cout<<"YES"<<endl;
}
else{
cout<<"NO"<<endl;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
604 KB |
Output is correct |
2 |
Correct |
18 ms |
604 KB |
Output is correct |
3 |
Correct |
14 ms |
652 KB |
Output is correct |
4 |
Correct |
168 ms |
640 KB |
Output is correct |
5 |
Correct |
152 ms |
604 KB |
Output is correct |
6 |
Correct |
200 ms |
604 KB |
Output is correct |
7 |
Runtime error |
1 ms |
856 KB |
Execution killed with signal 11 |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
860 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
600 KB |
Output is correct |
2 |
Correct |
14 ms |
604 KB |
Output is correct |
3 |
Correct |
14 ms |
604 KB |
Output is correct |
4 |
Correct |
25 ms |
648 KB |
Output is correct |
5 |
Correct |
20 ms |
600 KB |
Output is correct |
6 |
Correct |
18 ms |
604 KB |
Output is correct |
7 |
Correct |
14 ms |
604 KB |
Output is correct |
8 |
Correct |
22 ms |
604 KB |
Output is correct |
9 |
Correct |
56 ms |
652 KB |
Output is correct |
10 |
Correct |
23 ms |
604 KB |
Output is correct |
11 |
Correct |
211 ms |
628 KB |
Output is correct |
12 |
Correct |
26 ms |
604 KB |
Output is correct |
13 |
Correct |
24 ms |
868 KB |
Output is correct |
14 |
Correct |
90 ms |
600 KB |
Output is correct |
15 |
Correct |
44 ms |
604 KB |
Output is correct |
16 |
Correct |
86 ms |
604 KB |
Output is correct |
17 |
Correct |
660 ms |
648 KB |
Output is correct |
18 |
Correct |
39 ms |
604 KB |
Output is correct |
19 |
Correct |
13 ms |
604 KB |
Output is correct |
20 |
Correct |
702 ms |
648 KB |
Output is correct |
21 |
Correct |
13 ms |
604 KB |
Output is correct |
22 |
Correct |
19 ms |
604 KB |
Output is correct |
23 |
Correct |
26 ms |
604 KB |
Output is correct |
24 |
Correct |
14 ms |
656 KB |
Output is correct |
25 |
Correct |
65 ms |
600 KB |
Output is correct |
26 |
Correct |
385 ms |
604 KB |
Output is correct |
27 |
Correct |
25 ms |
648 KB |
Output is correct |
28 |
Correct |
14 ms |
604 KB |
Output is correct |
29 |
Correct |
21 ms |
648 KB |
Output is correct |
30 |
Correct |
859 ms |
660 KB |
Output is correct |
31 |
Correct |
796 ms |
648 KB |
Output is correct |
32 |
Correct |
36 ms |
604 KB |
Output is correct |
33 |
Correct |
770 ms |
644 KB |
Output is correct |
34 |
Correct |
859 ms |
856 KB |
Output is correct |
35 |
Correct |
837 ms |
848 KB |
Output is correct |
36 |
Correct |
276 ms |
884 KB |
Output is correct |
37 |
Correct |
831 ms |
648 KB |
Output is correct |
38 |
Correct |
602 ms |
600 KB |
Output is correct |
39 |
Correct |
551 ms |
644 KB |
Output is correct |
40 |
Correct |
628 ms |
760 KB |
Output is correct |
41 |
Correct |
512 ms |
604 KB |
Output is correct |
42 |
Correct |
279 ms |
852 KB |
Output is correct |
43 |
Correct |
335 ms |
644 KB |
Output is correct |
44 |
Correct |
237 ms |
848 KB |
Output is correct |
45 |
Correct |
341 ms |
648 KB |
Output is correct |
46 |
Correct |
215 ms |
600 KB |
Output is correct |
47 |
Correct |
273 ms |
600 KB |
Output is correct |
48 |
Correct |
206 ms |
604 KB |
Output is correct |
49 |
Correct |
226 ms |
848 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
139 ms |
600 KB |
Output is correct |
2 |
Correct |
156 ms |
604 KB |
Output is correct |
3 |
Correct |
775 ms |
652 KB |
Output is correct |
4 |
Correct |
15 ms |
600 KB |
Output is correct |
5 |
Correct |
14 ms |
660 KB |
Output is correct |
6 |
Correct |
19 ms |
596 KB |
Output is correct |
7 |
Correct |
15 ms |
604 KB |
Output is correct |
8 |
Correct |
16 ms |
604 KB |
Output is correct |
9 |
Correct |
25 ms |
644 KB |
Output is correct |
10 |
Correct |
885 ms |
852 KB |
Output is correct |
11 |
Correct |
933 ms |
848 KB |
Output is correct |
12 |
Correct |
1121 ms |
656 KB |
Output is correct |
13 |
Correct |
877 ms |
652 KB |
Output is correct |
14 |
Correct |
791 ms |
848 KB |
Output is correct |
15 |
Correct |
838 ms |
652 KB |
Output is correct |
16 |
Correct |
775 ms |
672 KB |
Output is correct |
17 |
Correct |
827 ms |
652 KB |
Output is correct |
18 |
Correct |
821 ms |
852 KB |
Output is correct |
19 |
Correct |
620 ms |
648 KB |
Output is correct |
20 |
Correct |
359 ms |
600 KB |
Output is correct |
21 |
Correct |
271 ms |
648 KB |
Output is correct |
22 |
Correct |
301 ms |
600 KB |
Output is correct |
23 |
Correct |
544 ms |
652 KB |
Output is correct |
24 |
Correct |
746 ms |
652 KB |
Output is correct |
25 |
Correct |
769 ms |
600 KB |
Output is correct |
26 |
Correct |
722 ms |
652 KB |
Output is correct |
27 |
Correct |
636 ms |
648 KB |
Output is correct |
28 |
Correct |
246 ms |
848 KB |
Output is correct |
29 |
Correct |
605 ms |
652 KB |
Output is correct |
30 |
Correct |
297 ms |
848 KB |
Output is correct |
31 |
Correct |
786 ms |
656 KB |
Output is correct |
32 |
Correct |
765 ms |
852 KB |
Output is correct |
33 |
Correct |
745 ms |
652 KB |
Output is correct |
34 |
Correct |
184 ms |
652 KB |
Output is correct |
35 |
Correct |
223 ms |
644 KB |
Output is correct |
36 |
Correct |
291 ms |
852 KB |
Output is correct |
37 |
Correct |
265 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
860 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
604 KB |
Output is correct |
2 |
Correct |
18 ms |
604 KB |
Output is correct |
3 |
Correct |
14 ms |
652 KB |
Output is correct |
4 |
Correct |
168 ms |
640 KB |
Output is correct |
5 |
Correct |
152 ms |
604 KB |
Output is correct |
6 |
Correct |
200 ms |
604 KB |
Output is correct |
7 |
Runtime error |
1 ms |
856 KB |
Execution killed with signal 11 |
8 |
Halted |
0 ms |
0 KB |
- |