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;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define ff first
#define ss second
ll ttt;
const ll INF=1e18;
const ll MOD=1e9+7;
const ll N=5007;
ll n,m,k;
int d[76][76][76][76][2]; // 1 if the current one loses, and 2 if wins
int cnt=0;
bool recurs(int ch, int fh, int cg, int fg, bool hert){
if(d[ch][fh][cg][fg][hert])return d[ch][fh][cg][fg][hert]==2;
cnt++;
if(hert){ // hackeri hertna
if(cg-max(ch-fg*k,0ll)<=0){
d[ch][fh][cg][fg][hert]=2;
return true;
}
if(ch>fg*k){
if(d[ch][fh][cg-ch+fg*k][fg][!hert]==1){
d[ch][fh][cg][fg][hert]=2;
return true;
}
// bool res=recurs(ch,fh,cg-ch+fg*k,fg,!hert);
// if(!res){
// d[ch][fh][cg][fg][hert]=2;
// return true;
// }
}
if(fg!=0){
if(d[ch][fh][cg][fg-1][!hert]==1){
d[ch][fh][cg][fg][hert]=2;
return true;
}
// bool res=recurs(ch,fh,cg,fg-1,!hert);
// if(!res){
// d[ch][fh][cg][fg][hert]=2;
// return true;
// }
}
if(ch>fg*k){
bool res=recurs(ch,fh,cg-ch+fg*k,fg,!hert);
if(!res){
d[ch][fh][cg][fg][hert]=2;
return true;
}
}
if(fg!=0){
bool res=recurs(ch,fh,cg,fg-1,!hert);
if(!res){
d[ch][fh][cg][fg][hert]=2;
return true;
}
}
d[ch][fh][cg][fg][hert]=1;
return false;
}
else{
if(ch-max(cg-fh*k,0ll)<=0){
d[ch][fh][cg][fg][hert]=2;
return true;
}
if(cg>fh*k){
if(d[ch-cg+fh*k][fh][cg][fg][!hert]==1){
d[ch][fh][cg][fg][hert]=2;
return true;
}
// bool res=recurs(ch-cg+fh*k,fh,cg,fg,!hert);
// if(!res){
// d[ch][fh][cg][fg][hert]=2;
// return true;
// }
}
if(fh!=0){
if(d[ch][fh-1][cg][fg][!hert]==1){
d[ch][fh][cg][fg][hert]=2;
return true;
}
// bool res=recurs(ch,fh-1,cg,fg,!hert);
// if(!res){
// d[ch][fh][cg][fg][hert]=2;
// return true;
// }
}
if(cg>fh*k){
bool res=recurs(ch-cg+fh*k,fh,cg,fg,!hert);
if(!res){
d[ch][fh][cg][fg][hert]=2;
return true;
}
}
if(fh!=0){
bool res=recurs(ch,fh-1,cg,fg,!hert);
if(!res){
d[ch][fh][cg][fg][hert]=2;
return true;
}
}
d[ch][fh][cg][fg][hert]=1;
return false;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
cin>>k>>m;
for(int i=0;i<m;i++){
int ch,fh,cg,fg;
cin>>ch>>fh>>cg>>fg;
if(recurs(ch,fh,cg,fg,true))cout<<"YES\n";
else cout<<"NO\n";
assert(cnt<=1e7);
}
}
# | 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... |