QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#526206 | #7277. Bring Down the | skittles1412# | 10 | 84ms | 3664kb | C++17 | 4.3kb | 2024-08-21 12:15:53 | 2024-08-21 12:15:53 |
Judging History
answer
// cf bits/extc++.h nonsense
#ifdef ONLINE_JUDGE
#define _EXT_CODECVT_SPECIALIZATIONS_H 1
#define _EXT_ENC_FILEBUF_H 1
#endif
#include "bits/extc++.h"
using namespace std;
template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
cerr << t;
((cerr << " | " << u), ...);
cerr << endl;
}
#ifdef DEBUG
#define dbg(...) \
cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]: "; \
dbgh(__VA_ARGS__)
#else
#define dbg(...)
#define cerr \
if (false) \
cerr
#endif
using ll = long long;
#define endl "\n"
#define long int64_t
#define sz(x) int(std::size(x))
inline void init_io() {
cin.tie(nullptr);
cin.exceptions(ios::failbit);
ios_base::sync_with_stdio(false);
}
template <typename T>
vector<T> iota(int n, const T& x) {
vector<T> arr(n);
iota(begin(arr), end(arr), x);
return arr;
}
template <typename T>
ostream& operator<<(ostream& out, const vector<T>& arr) {
out << "[";
for (int i = 0; i < sz(arr); i++) {
if (i) {
out << ", ";
}
out << arr[i];
}
return out << "]";
}
template <typename T>
int c_lb(const vector<T>& arr, const T& x) {
return int(lower_bound(begin(arr), end(arr), x) - begin(arr));
}
template <typename T>
int c_ub(const vector<T>& arr, const T& x) {
return int(upper_bound(begin(arr), end(arr), x) - begin(arr));
}
template <typename T>
T reversed(T arr) {
reverse(begin(arr), end(arr));
return arr;
}
template <typename T>
T sorted(T arr) {
sort(begin(arr), end(arr));
return arr;
}
template <typename T>
bool on(T mask, int bit) {
return (mask >> bit) & 1;
}
template <typename A, typename B>
ostream& operator<<(ostream& out, const pair<A, B>& p) {
return out << "(" << p.first << ", " << p.second << ")";
}
long kv;
map<array<long, 3>, bool> dp0_memo;
map<array<long, 4>, bool> dp_memo;
bool dp0(long x1, long x2, long f2) {
dbg(x1, x2, f2);
if (x1 < 0) {
assert(x2 >= 0);
return false;
}
if (x2 <= 0) {
return true;
}
long a1 = max(long(0), x1 - kv * f2), a2 = x2;
if (x1 - kv * f2 < 0) {
long t = clamp((kv * f2 - x1) / (kv - a2), long(1), f2);
return dp0(x1 - t * x2, x2, f2 - t);
}
assert(a1 < kv && a2 < kv);
if (x1 - kv * f2 + f2 * (kv - a2) >= x2) {
return true;
} else if (!f2) {
assert(x1 < x2);
return false;
}
auto [it, inserted] = dp_memo.insert({{x1, x2, f2}, false});
bool& ans = it->second;
if (!inserted) {
return ans;
}
ans = ans || dp0(x1 - x2, x2, f2 - 1);
if (a1) {
ans = ans || dp0(x1 - (x2 - a1), x2 - a1, f2);
}
return ans;
}
bool dp(long x1, long f1, long x2, long f2) {
assert(x1 > 0);
if (x2 <= 0) {
return true;
}
long a1 = max(long(0), x1 - kv * f2), a2 = max(long(0), x2 - kv * f1);
dbg(x1, f1, x2, f2, a1, a2);
if (a1 >= a2 && a1 >= kv) {
// because I just always attack
return true;
} else if (a2 >= kv || !f2) {
// a2 >= kv forces me to attack cuz otherwise I just lose for no good
// reason !f2 just forces me to
return !dp(x2 - a1, f2, x1, f1);
}
assert(a1 < kv && a2 < kv);
if (!f1) {
return dp0(x1, x2, f2);
}
if (!a1) {
return !dp(x2, f2 - 1, x1, f1);
}
if (a1 >= a2 && a1 > 0) {
// I jump then insta win
return true;
}
if (f2 >= 1 && x1 >= kv * f2 && dp(x1 + f2 * (kv - a2), f1, x2, 0)) {
// short circuiting max jumping
return true;
}
assert(0 < a1 && a1 < kv && 0 < a2 && a2 < kv);
f1 = min(f1, kv);
f2 = min(f2, kv);
auto [it, inserted] = dp_memo.insert({{x1, f1, x2, f2}, false});
bool& ans = it->second;
if (!inserted) {
return ans;
}
ans = ans || !dp(x2, f2 - 1, x1, f1);
ans = ans || !dp(x2 - a1, f2, x1, f1);
return ans;
}
void solve() {
long x1, f1, x2, f2;
cin >> x1 >> f1 >> x2 >> f2;
long rf2 = x1 / kv, rf1 = x2 / kv, sub = min(f2 - rf2, f1 - rf1);
if (sub > 0) {
f1 -= sub;
f2 -= sub;
}
dbg(x1, f1, x2, f2);
if (dp(x1, f1, x2, f2)) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
int main() {
init_io();
int q;
cin >> kv >> q;
while (q--) {
solve();
}
}
详细
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 5
Accepted
time: 0ms
memory: 3580kb
input:
17 2 42 1 33 1 42 1 33 7
output:
YES NO
result:
ok 2 token(s): yes count is 1, no count is 1
Test #2:
score: 0
Runtime Error
input:
2 250000 75 16 56 55 50 9 49 60 18 67 62 5 30 54 61 39 22 39 42 31 26 30 55 1 23 30 53 16 55 13 6 44 69 8 58 72 53 7 60 12 29 14 26 34 37 64 24 71 19 3 40 1 64 13 33 65 67 24 68 3 64 17 50 66 71 6 62 13 15 29 26 24 51 30 34 45 46 5 40 72 54 52 60 49 35 21 18 30 39 31 35 34 30 74 72 5 74 12 6 15 11 4...
output:
NO NO YES YES NO YES NO NO NO YES NO NO NO NO YES NO YES NO NO NO YES NO NO YES YES NO YES YES NO YES YES NO NO YES NO NO YES YES YES NO NO NO NO YES YES YES YES NO YES NO YES NO YES YES YES YES YES NO NO NO YES NO NO NO YES YES NO YES NO YES NO YES YES YES YES NO YES YES YES NO YES NO NO NO NO YES ...
result:
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 10
Accepted
Test #28:
score: 10
Accepted
time: 77ms
memory: 3592kb
input:
1 250000 554333015044 833858497873 833858497874 554333015044 655160857180 306396306924 306396306917 655160857187 374728598365 176680698490 176680698490 374728598365 764650258714 835600427315 835600427309 764650258720 521594231110 318048536486 318048536482 521594231115 273627794040 449769302710 10899...
output:
NO YES YES YES NO NO NO NO NO NO YES YES YES YES YES NO NO NO YES YES YES YES YES NO YES NO NO YES YES YES NO NO YES YES YES YES NO NO YES YES YES NO NO YES NO YES YES YES NO YES NO NO NO YES NO NO NO YES NO NO NO YES YES YES YES YES NO YES NO YES YES NO NO NO YES NO YES NO NO NO YES YES NO NO YES N...
result:
ok 250000 token(s): yes count is 126293, no count is 123707
Test #29:
score: 10
Accepted
time: 74ms
memory: 3636kb
input:
1 250000 129596328651 633211431893 1 762807760544 1 983509496641 151077576062 229908055916 36498040145 186033440917 1 995620003790 247250323075 720548396611 720548396605 247250323082 464252981836 491098062545 12027035640 943324008741 719683599156 92798217394 1 812481816550 317330065824 621406415744 ...
output:
NO YES NO NO YES NO YES NO NO NO NO NO NO YES YES NO NO YES YES YES NO YES YES NO NO YES YES NO NO YES YES NO YES NO YES NO NO YES YES YES NO YES YES NO YES NO YES YES YES YES NO NO YES YES YES NO NO YES YES NO YES YES NO YES NO YES YES YES NO NO YES NO YES NO NO YES YES YES NO NO NO NO YES YES NO N...
result:
ok 250000 token(s): yes count is 143356, no count is 106644
Test #30:
score: 10
Accepted
time: 73ms
memory: 3596kb
input:
1 250000 807680045522 377273608557 256372130241 928581523838 536035116725 716237980103 379308294473 872964802356 1 882064014033 529720193901 352343820133 80961796479 258174541326 183165451143 155970886662 739448494904 100650373373 75082626963 765016241315 166426307909 865864146065 703399919607 32889...
output:
YES NO YES YES NO NO NO NO YES YES NO YES YES NO NO NO NO YES YES NO YES NO YES NO NO YES NO YES NO NO YES NO NO NO NO NO NO NO YES NO YES YES YES NO NO NO NO NO YES YES YES YES NO YES NO YES YES NO NO YES NO YES NO NO YES NO YES YES YES NO NO NO YES NO NO YES YES YES NO NO YES YES YES YES NO NO NO ...
result:
ok 250000 token(s): yes count is 132783, no count is 117217
Test #31:
score: 10
Accepted
time: 0ms
memory: 3556kb
input:
1 1 999999999999 999999999999 999999999999 999999999999
output:
YES
result:
ok YES
Subtask #4:
score: 0
Skipped
Dependency #2:
0%
Subtask #5:
score: 0
Runtime Error
Dependency #3:
100%
Accepted
Test #60:
score: 20
Accepted
time: 84ms
memory: 3664kb
input:
1 250000 554333015044 833858497873 833858497874 554333015044 655160857180 306396306924 306396306917 655160857187 374728598365 176680698490 176680698490 374728598365 764650258714 835600427315 835600427309 764650258720 521594231110 318048536486 318048536482 521594231115 273627794040 449769302710 10899...
output:
NO YES YES YES NO NO NO NO NO NO YES YES YES YES YES NO NO NO YES YES YES YES YES NO YES NO NO YES YES YES NO NO YES YES YES YES NO NO YES YES YES NO NO YES NO YES YES YES NO YES NO NO NO YES NO NO NO YES NO NO NO YES YES YES YES YES NO YES NO YES YES NO NO NO YES NO YES NO NO NO YES YES NO NO YES N...
result:
ok 250000 token(s): yes count is 126293, no count is 123707
Test #61:
score: 0
Runtime Error
input:
33 250000 42 63 17 64 48 31 9 35 46 64 75 15 42 14 16 17 3 37 49 15 70 39 16 43 52 2 8 8 12 12 57 9 36 42 75 1 9 60 30 58 47 71 75 69 75 7 3 30 45 51 24 52 14 15 2 25 55 35 2 53 68 32 31 34 69 43 56 45 44 68 75 57 29 36 2 55 56 61 5 71 36 55 75 21 38 73 75 69 61 72 75 24 67 10 74 10 48 28 28 30 47 6...
output:
result:
Subtask #6:
score: 0
Skipped
Dependency #1:
0%
Subtask #7:
score: 0
Skipped
Dependency #1:
0%