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 <bits/stdc++.h>
using namespace std;
//------------------------------DEFINE------------------------------
//******************************************************************
#define IOS ios_base::sync_with_stdio(false); cin.tie(0),cout.tie(0)
#define ll long long
#define pb push_back
#define F first
#define S second
#define INF 1e18
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define OK cout<<"Ok"<<endl;
#define MOD (ll)(1e9+7)
#define endl "\n"
//******************************************************************
//----------------------------FUNCTION------------------------------
//******************************************************************
ll gcd(ll a,ll b){
if(a>b) swap(a,b);
if(a==0) return a+b;
return gcd(b%a,a);
}
ll lcm(ll a,ll b){
return a/gcd(a,b)*b;
}
bool is_prime(ll n){
ll k=sqrt(n);
if(n==2) return true;
if(n<2||n%2==0||k*k==n) return false;
for(int i=3;i<=k;i+=2){
if(n%i==0){
return false;
}
}
return true;
}
//*****************************************************************
//--------------------------MAIN-CODE------------------------------
const int mxn=2e5+5;
int t=1,n,k,arr[mxn],dp[107][107];
bool funk(int k,vector<int>vt,int ind,int say,int sum){
if(ind!=-1){
vt[ind]-=say;
sum-=say;
}
if(sum%2==1) return 1;
for(int i=0;i<vt.size();i++){
for(int j=1;j<=min(k,vt[i]);j++){
if(!funk(j,vt,i,j,sum)) return true;
}
}
return false;
}
bool funk2(int n,int k){
if(dp[n][k]!=-1) return dp[n][k];
if(n%2==1) dp[n][k]=1;
if(!n) return 0;
for(int i=1;i<=min(n,k);i++){
if(funk2(n-i,i)==0){
return dp[n][k]=1;
}
}
return dp[n][k]=0;
}
void solve(){
cin>>n>>k;
ll sum=0;
vector<int>vt;
for(int i=1;i<=n;i++){
cin>>arr[i];
sum+=arr[i];
vt.pb(arr[i]);
}
if(n==1){
ll q=1;
while(arr[1]%(q*2)==0){
q*=2;
}
if(k<q){
cout<<0;
}
else{
cout<<1;
}
return;
}
if(sum%2==1){
cout<<1;
return;
}
else if(k==1){
cout<<0;
return;
}
if(funk(k,vt,-1,0,sum)){
cout<<1;
}
else{
cout<<0;
}
}
int main(){
IOS;
cin>>t;
while(t--){
solve();
}
return 0;
}
Compilation message (stderr)
football.cpp: In function 'bool funk(int, std::vector<int>, int, int, int)':
football.cpp:51:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | for(int i=0;i<vt.size();i++){
| ~^~~~~~~~~~
football.cpp: In function 'bool funk2(int, int)':
football.cpp:64:28: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
64 | return dp[n][k]=1;
| ~~~~~~~~^~
football.cpp:67:20: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
67 | return dp[n][k]=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... |