#include <bits/stdc++.h>
#define int long long
using namespace std;
const int nmax = 75;
bool dp[nmax + 5][nmax + 5][nmax + 5][nmax + 5];
bool sel[nmax + 5][nmax + 5][nmax + 5][nmax + 5];
int s, q;
bool solve(int C, int F, int c, int f)
{
if(C <= 0)
{
return false;
}
if(C <= s * f && c <= s * F)
{
int D = f - (C - 1) / s;
int d = F - (c - 1) / s;
if(D <= d)
{
return solve(C, F - D, c, f - d);
}
else
{
return !solve(c, f - d - 1, C, F - D);
}
}
/*if(C - s * f > 0 && c - s * F <= 0)
{
return true;
}*/
if(sel[C][F][c][f])
{
return dp[C][F][c][f];
}
sel[C][F][c][f] = true;
dp[C][F][c][f] = false;
if(C - f * s > 0 && !solve(c - (C - f * s), f, C, F))
{
dp[C][F][c][f] = true;
}
else if(f > 0 && !solve(c, f - 1, C, F))
{
dp[C][F][c][f] = true;
}
return dp[C][F][c][f];
}
bool solve1(int C, int F, int c, int f)
{
if(C <= 0)
{
return false;
}
if(C <= f && c <= F)
{
if(f - C <= F - c)
{
return true;
}
return false;
}
if(C <= f)
{
return false;
}
return (!solve1(c - (C - f), f, C, F));
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
#ifdef home
freopen("nr.in","r",stdin);
freopen("nr.out","w",stdout);
#endif // home
cin>>s>>q;
for(int i=1; i<=q; i++)
{
int ch, fh, cg, fg;
cin>>ch>>fh>>cg>>fg;
bool ok;
if(s == 1)
{
ok = solve1(ch, fh, cg, fg);
}
else
{
ok = solve(ch, fh, cg, fg);
}
if(ok)
{
cout<<"YES\n";
}
else
{
cout<<"NO\n";
}
}
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... |