This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <algorithm>
#include <cstring>
#define int long long
#define MAX 1000002
using namespace std;
int t,n,k,a[MAX],nrp,tmp,s,c[MAX],lst;
bool gasit;
pair<int, int> st[MAX];
void backtrack(int pas){
if(tmp == s){
if((pas-1)%2 == 1){
gasit = true;
}
}else{
for(int i = 1; i <= n && !gasit; i++){
int clst = lst;
for(int j = 1; j <= clst && !gasit; j++){
if(j > c[i]){
break;
}
c[i] -= j;
tmp += j;
st[pas] = {i, j};
backtrack(pas+1);
lst = j;
c[i] += j;
tmp -= j;
}
lst = clst;
}
}
}
void solve(){
cin >> n >> k;
nrp = 0;
s = 0;
for(int i = 1; i <= n; i++){
cin >> a[i];
s += a[i];
}
sort(a+1, a+n+1);
memcpy(c, a, sizeof(a));
if(k == 1){
cout << (s%2);
}else{
gasit = false;
lst = k;
backtrack(1);
cout << gasit;
}
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> t;
while(t--){
solve();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |