Task: | Pallo |
Sender: | Mahtimursu |
Submission time: | 2022-01-22 14:25:48 +0200 |
Language: | C++ (C++17) |
Status: | READY |
Result: | 100 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 10 |
#2 | ACCEPTED | 35 |
#3 | ACCEPTED | 55 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
#2 | ACCEPTED | 0.01 s | 2, 3 | details |
#3 | ACCEPTED | 0.01 s | 3 | details |
Code
#include <bits/stdc++.h> typedef long long ll; #define M 1000000007 #define N (1 << 18) using namespace std; ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll cor(ll n, ll m, ll k) { pair<ll, ll> pos = {1, 1}; pair<int, int> dir = {1, 1}; ll ans = 0; for (ll t = 0; t < k;) { //pos = {pos.first + dir.first, pos.second + dir.second}; int rightdst = m - pos.first; int leftdst = pos.first - 1; int updst = pos.second - 1; int downdst = n - pos.second; int xdst = dir.first == 1 ? rightdst : leftdst; int ydst = dir.second == 1 ? downdst : updst; int travel = min(xdst, ydst); t += travel; if (t > k) break; pos = {pos.first + travel * dir.first, pos.second + travel * dir.second}; bool hit = 0; if (pos.first == m || pos.first == 1) { hit = 1; dir.first *= -1; } if (pos.second == n || pos.second == 1) { hit = 1; dir.second *= -1; } ans += hit; if (pos.first == 1 && pos.second == 1) { ll runs = k / t; ans *= runs; k -= (runs - 1) * t; } } return ans; } ll fast(ll n, ll m, ll k) { n--; m--; ll vert = k / n; ll hor = k / m; ll corner = k / (n * m / gcd(n, m)); return vert + hor - corner; } void test_case() { ll n, m, k; cin >> n >> m >> k; ll ans = fast(n, m, k); cout << ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int t = 1; cin >> t; for (int i = 0; i < t; ++i) { test_case(); cout << "\n"; } /*while (true) { ll n = rand() % 5 + 2; ll m = rand() % 5 + 2; ll k = rand() % 5 + 1; ll ans = cor(n, m, k); ll out = fast(n, m, k); if (ans != out) { cout << "FAIL" << endl; cout << "GOT " << out << " WAS " << ans << endl; cout << n << ", " << m << ", " << k << endl; break; } }*/ return 0; } /*for (ll t = 0; t < k;) { int rightdst = m - pos.first; int leftdst = pos.first - 1; int updst = pos.second - 1; int downdst = n - pos.second; int xdst = dir.first == 1 ? rightdst : leftdst; int ydst = dir.second == 1 ? downdst : updst; int travel = min(xdst, ydst); t += travel; if (t > k) break; pos = {pos.first + travel * dir.first, pos.second + travel * dir.second}; bool hit = 0; if (pos.first == m || pos.first == 1) { hit = 1; dir.first *= -1; } if (pos.second == n || pos.second == 1) { hit = 1; dir.second *= -1; } ans += hit; if (pos.first == 1 && pos.second == 1) { ll runs = k / t; ans *= runs; k -= (runs - 1) * t; } }*/
Test details
Test 1
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
100 10 5 76 9 8 78 8 6 49 3 3 94 ... |
correct output |
---|
25 19 15 47 8 ... |
user output |
---|
25 19 15 47 8 ... Truncated |
Test 2
Group: 2, 3
Verdict: ACCEPTED
input |
---|
1000 7 5 99033171167123849 6 8 472883555390027162 9 10 258937093512465880 10 6 691774305483997493 ... |
correct output |
---|
33011057055707949 148620545979722822 57541576336103529 199845910473154830 52151060432923288 ... |
user output |
---|
33011057055707949 148620545979722822 57541576336103529 199845910473154830 5215106043292328 ... Truncated |
Test 3
Group: 3
Verdict: ACCEPTED
input |
---|
1000 816332614 86098803 33572721929... |
correct output |
---|
4310587870 45982113074 1550250683 717639357 3282221941 ... |
user output |
---|
4310587870 45982113074 1550250683 717639357 3282221941 ... Truncated |