#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);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Runtime error |
3 ms |
528 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
284 ms |
260160 KB |
Output is correct |
3 |
Correct |
272 ms |
260692 KB |
Output is correct |
4 |
Correct |
264 ms |
261680 KB |
Output is correct |
5 |
Runtime error |
428 ms |
525904 KB |
Execution killed with signal 6 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
284 ms |
260160 KB |
Output is correct |
3 |
Correct |
272 ms |
260692 KB |
Output is correct |
4 |
Correct |
264 ms |
261680 KB |
Output is correct |
5 |
Runtime error |
428 ms |
525904 KB |
Execution killed with signal 6 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
600 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
284 ms |
260160 KB |
Output is correct |
3 |
Correct |
272 ms |
260692 KB |
Output is correct |
4 |
Correct |
264 ms |
261680 KB |
Output is correct |
5 |
Runtime error |
428 ms |
525904 KB |
Execution killed with signal 6 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
284 ms |
260160 KB |
Output is correct |
3 |
Correct |
272 ms |
260692 KB |
Output is correct |
4 |
Correct |
264 ms |
261680 KB |
Output is correct |
5 |
Runtime error |
428 ms |
525904 KB |
Execution killed with signal 6 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
284 ms |
260160 KB |
Output is correct |
3 |
Correct |
272 ms |
260692 KB |
Output is correct |
4 |
Correct |
264 ms |
261680 KB |
Output is correct |
5 |
Runtime error |
428 ms |
525904 KB |
Execution killed with signal 6 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
284 ms |
260160 KB |
Output is correct |
3 |
Correct |
272 ms |
260692 KB |
Output is correct |
4 |
Correct |
264 ms |
261680 KB |
Output is correct |
5 |
Runtime error |
428 ms |
525904 KB |
Execution killed with signal 6 |
6 |
Halted |
0 ms |
0 KB |
- |