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;
const int N = 80;
int s, q;
int dp[N][N][N][N][2];
int bt(int ch, int fh, int cg, int fg, bool turn) {
	if (turn == 0) {
		if (ch < 0) {
			return false; 
		}
		int& ret = dp[ch][fh][cg][fg][turn];
		if (ret != -1) {
			return ret; 
		}
		ret = 0; 
		if (fg) {
			ret |= bt(ch, fh, cg, fg - 1, turn ^ 1) == 0;
		}
		int damage = ch - fg * s;
		if (damage > 0) {
			ret |= bt(ch, fh, cg - damage, fg, turn ^ 1) == 0;
		} 
		return ret; 
	} else {
		if (cg < 0) {
			return false; 
		}
		int& ret = dp[ch][fh][cg][fg][turn];
		if (ret != -1) {
			return ret; 
		}
		ret = 0; 
		if (fh) {
			ret |= bt(ch, fh - 1, cg, fg, turn ^ 1) == 0;
		}
		int damage = cg - fh * s;
		if (damage > 0) {
			ret |= bt(ch - damage, fh, cg, fg, turn ^ 1) == 0;
		}
		return ret; 
	} 
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> s >> q;
	memset(dp, -1, sizeof dp);
	while (q--) {
		int ch, fh, cg, fg;
		cin >> ch >> fh >> cg >> fg;
		int ok = bt(ch, fh, cg, fg, 0);
		cout << (ok ? "YES" : "NO") << '\n';
	}
}
| # | 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... |