QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#187832 | #7111. Press the Button | UrgantTeam# | AC ✓ | 42ms | 50132kb | C++23 | 4.4kb | 2023-09-25 01:19:43 | 2023-09-25 01:19:43 |
Judging History
answer
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <array>
#include <vector>
#include <tuple>
#include <algorithm>
#include <cstdint>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using ll = long long;
using pll = pair<ll, ll>;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using vpll = vector<pll>;
using vpii = vector<pii>;
using vpil = vector<pil>;
int sum(int a, int b, int m) {
if ((a += b) >= m) a -= m;
return a;
}
int dif(int a, int b, int m) {
if ((a -= b) < 0) a += m;
return a;
}
struct Solver {
const int N;
vector<pair<int, pil>> a, c;
Solver(const int N = 1e6) : N(N) {}
void init() {
a.assign(N, {});
c.assign(N, {});
}
pair<int, pil>& get_element(const int ac, const int cc) {
if (ac == 0)
return a[cc];
else
return c[ac];
}
} solver;
ll find_positive_ans(int a, int b, int c, int d, ll v, ll t) {
return (t + a) / a * b + (t + c) / c * d;
}
int gcd(int a, int b) {
while (b) {
a %= b;
swap(a, b);
}
return a;
}
// const int C = 3e6;
ll find_negative_ans(int a, int c, ll v, ll T, int i) {
++v;
//solver.init();
int ares = v % a, cres = v % c, ac = 0, cc = 0;
// ll cycle_length = (ll)a * (c / gcd(a, c));
ll p = 0;
bool found_cycle = false;
//i *= C;
for (ll t = 0; t <= T; t += v, ac = sum(ac, ares, a), cc = sum(cc, cres, c)) {
int addend = min(dif(0, ac, a), dif(0, cc, c));
if ((t += addend) > T)
break;
ac = sum(ac, addend, a);
cc = sum(cc, addend, c);
if (t == 0)
++p;
else {
int removal = min((ac ? ac : a), (cc ? cc : c));
if (removal >= v)
++p;
}
if (found_cycle)
continue;
pair<int, pil>& last_time = solver.get_element(ac, cc);
if (last_time.first <= i) {
last_time.first = i + 1;
last_time.second.first = p;
last_time.second.second = t;
continue;
}
found_cycle = true;
ll cycle_len = t - last_time.second.second;
ll cycle_load = p - last_time.second.first;
ll cycles = (T - t) / cycle_len;
p += cycles * cycle_load;
t += cycles * cycle_len;
}
ac = 0; cc = 0;
/*
for (ll t = 0; t <= T; t += v, ac = sum(ac, ares, a), cc = sum(cc, cres, c)) {
int addend = min(dif(0, ac, a), dif(0, cc, c));
if ((t += addend) > T)
break;
ac = sum(ac, addend, a);
cc = sum(cc, addend, c);
pil& last_time = solver.get_element(ac, cc);
if (last_time.first == 0)
break;
last_time.first = 0;
last_time.second = 0;
}
*/
return p;
}
ll find_ans(int a, int b, int c, int d, ll v, ll t, int i) {
ll positive_ans = find_positive_ans(a, b, c, d, v, t);
ll negative_ans = find_negative_ans(a, c, v, t, i);
ll ans = positive_ans - negative_ans;
return ans;
}
bool solve_test(int i) {
int a, b, c, d;
ll v, t;
if (!(cin >> a >> b >> c >> d >> v >> t))
return false;
cout << find_ans(a, b, c, d, v, t, i) << '\n';
return true;
}
void solve_tests() {
solver.init();
int t;
cin >> t;
for (int i = 0; i < t; ++i) {
solve_test(i);
#ifdef ONPC
//cerr << "Test " << i + 1 << " solved\n";
#endif
}
}
#include <random>
tuple<int, int, int, int, ll, ll> get_rng_test() {
static mt19937 rng;
uniform_int_distribution<int> seg(1, 30);
return { seg(rng), seg(rng), seg(rng), seg(rng), seg(rng), seg(rng) };
}
ll find_jury_negative_ans(int a, int c, ll v, ll T) {
ll timer = 0;
ll ans = 0;
for (ll t = 0; t <= T; ++t, timer = max(0ll, timer - 1)) {
if (t % a == 0 || t % c == 0) {
if (timer == 0)
++ans;
timer = v + 1;
}
}
return ans;
}
void stress() {
int i = 0;
solver.init();
while (true) {
if (i >= 150) {
i = 0;
solver.init();
}
auto [a, b, c, d, v, t] = get_rng_test();
ll correct_ans = find_jury_negative_ans(a, c, v, t);
ll my_ans = find_negative_ans(a, c, v, t, i);
cerr << '.';
if (correct_ans != my_ans) {
cerr << "!!!\n";
cerr << a << ' ' << c << ' ' << v << ' ' << t << '\n';
cerr << correct_ans << ' ' << my_ans << '\n';
return;
}
++i;
}
}
#include <chrono>
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef ONPC
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
auto start = chrono::high_resolution_clock::now();
solve_tests();
auto finish = chrono::high_resolution_clock::now();
#ifdef ONPC
cerr << "Taken " << (finish - start) / 1.ms << " ms\n";
//stress();
#endif
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 50132kb
input:
2 8 2 5 1 2 18 10 2 5 1 2 10
output:
6 4
result:
ok 2 number(s): "6 4"
Test #2:
score: 0
Accepted
time: 4ms
memory: 49932kb
input:
1000 8 6 2 6 3 17 1 6 1 1 1 30 5 4 8 8 1 31 7 6 10 3 6 12 9 1 4 4 3 38 3 3 5 8 1 8 9 1 5 2 3 18 6 10 10 8 2 40 9 6 9 10 3 9 2 5 1 10 10 39 7 7 1 2 4 19 8 10 8 6 7 36 2 9 1 1 7 17 1 2 3 5 6 14 8 8 8 7 1 46 6 9 3 9 4 6 10 8 1 7 10 18 7 1 7 10 3 50 1 10 2 1 5 1 5 8 4 9 7 44 9 2 5 4 7 42 9 1 2 1 1 20 5 ...
output:
71 216 52 16 38 22 7 102 30 499 60 75 98 54 84 44 148 80 20 179 45 4 463 139 56 30 45 127 204 121 42 69 38 98 63 121 25 142 17 75 24 175 114 40 32 11 29 85 35 7 66 49 492 49 49 14 17 53 431 161 94 27 21 135 71 92 33 290 57 300 18 89 155 55 10 219 203 390 28 50 67 213 26 18 27 19 128 101 118 62 46 15...
result:
ok 1000 numbers
Test #3:
score: 0
Accepted
time: 42ms
memory: 49996kb
input:
100 9 9 3 1 1 2 5 5 7 7 7 50 2 1 8 10 10 45 3 4 5 7 7 38 1 6 9 5 2 13 5 6 7 9 1 29 10 1 4 3 3 19 6 10 10 8 7 3 9 3 10 3 3 14 9 7 1 7 8 38 3 78 5 43 5 958 4 98 3 42 10 7 3 16 9 71 7 52 1 70 3 86 3 410 10 44 1 56 3 628 9 15 9 94 10 15 9 95 9 61 2 525 2 23 8 37 10 108 5 92 3 65 10 331 6 54 6 44 3 537 2...
output:
9 110 82 107 93 73 13 17 10 307 33215 321 713 40551 37995 217 9145 1782 13378 8730 270 2433 143 17 30 136 10 82 33 97 733 126 2917 623 364 1448 1212 872 268 1031 1601 3889 122 523 819 83 17513 277 2973 4651 202187 42602 17225 7881 32574 7087 4453 34029 20529 17520 58488 189327 14380 67133 90956 4328...
result:
ok 100 numbers
Extra Test:
score: 0
Extra Test Passed