#include<bits/stdc++.h>
using namespace std;
int n;
bool done;
bool possible[1000000];
void DFS(int mask){
if(possible[mask])return;
possible[mask]=true;
int arr[n];
for(int i=0;i<n;i++){
arr[i]=((mask&(1<<i))>0);
}
int prev[n];
int next[n];
prev[0]=-1;
for(int i=1;i<n;i++){
if(arr[i-1]==1)prev[i]=prev[i-1];
else prev[i]=i-1;
}
next[n-1]=n;
for(int i=n-2;i>-1;i--){
if(arr[i+1]==1)next[i]=next[i+1];
else next[i]=i+1;
}
/*for(int i=0;i<n;i++){
cout<<prev[i]<<" "<<next[i]<<endl;
}*/
for(int i=0;i<n;i++){
if(arr[i]==0 && prev[i]!=-1 && next[i]!=n){
int less=(1<<prev[i])+(1<<next[i]);
DFS(mask+less);
}
}
}
int main(){
int t;
cin>>t;
done=false;
while(t--){
cin>>n;
if(!done){
for(int i=0;i<(1<<n);i++)possible[i]=false;
DFS(0);
/*for(int mask=0;mask<(1<<n);mask++){
for(int i=0;i<n;i++)cout<<((mask&(1<<i))>0);
cout<<" "<<possible[mask]<<endl;
}*/
}
int l;
cin>>l;
int MSK=(1<<n)-1;
for(int i=0;i<l;i++){
int x;
cin>>x;
x--;
MSK-=(1<<x);
}
if(possible[MSK])cout<<0<<endl<<endl;
else cout<<-1<<endl;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
6 ms |
376 KB |
Output is partially correct |
2 |
Partially correct |
4 ms |
376 KB |
Output is partially correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
6 ms |
376 KB |
Output is partially correct |
2 |
Partially correct |
4 ms |
376 KB |
Output is partially correct |
3 |
Execution timed out |
1081 ms |
504 KB |
Time limit exceeded |
4 |
Execution timed out |
1082 ms |
508 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
4 ms |
2424 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Runtime error |
4 ms |
2424 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
6 ms |
376 KB |
Output is partially correct |
2 |
Partially correct |
4 ms |
376 KB |
Output is partially correct |
3 |
Execution timed out |
1081 ms |
504 KB |
Time limit exceeded |
4 |
Execution timed out |
1082 ms |
508 KB |
Time limit exceeded |
5 |
Runtime error |
2 ms |
632 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
6 |
Runtime error |
3 ms |
632 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
7 |
Runtime error |
4 ms |
2424 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
6 ms |
376 KB |
Output is partially correct |
2 |
Partially correct |
4 ms |
376 KB |
Output is partially correct |
3 |
Execution timed out |
1081 ms |
504 KB |
Time limit exceeded |
4 |
Execution timed out |
1082 ms |
508 KB |
Time limit exceeded |
5 |
Runtime error |
2 ms |
632 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
6 |
Runtime error |
3 ms |
632 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
7 |
Runtime error |
4 ms |
2424 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
8 |
Runtime error |
4 ms |
2428 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
9 |
Runtime error |
4 ms |
2424 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
10 |
Runtime error |
2 ms |
504 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
11 |
Runtime error |
2 ms |
632 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |