Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "bits/stdc++.h"
- using namespace std;
- #define ar array
- typedef long long ll;
- #define int ll
- signed main() {
- ios::sync_with_stdio(0);
- cin.tie(0);
- int n, a, b;
- cin >> a >> b >> n;
- vector<int> y(n);
- for (int i = 1; i <= n; i++) {
- y[i - 1] = (2ll * i * i + b) % 3 + i % 2;
- }
- int ans = 1e9;
- auto sq = [&](int x) { return x * 1ll * x; };
- auto dis = [&](int i, int j) {
- return ceil(sqrt(sq((i - j) * a) + sq(y[i] - y[j])));
- };
- for (int j = 0; j < 4; j++) {
- int last = -1, f = -1, res = 0;
- for (int i = 0; i < n; i++) {
- if (y[i] <= j) {
- if (~last)
- res += dis(last, i);
- if (f == -1)
- f = i;
- last = i;
- }
- }
- for (int i = n - 1; ~i; i--) {
- if (y[i] > j) {
- if (~last)
- res += dis(last, i);
- if (f == -1)
- f = i;
- last = i;
- }
- }
- res += dis(f, last);
- ans = min(ans, res);
- }
- cout << ans + n << "\n";
- }
- /*
- 3 3 4
- */
Advertisement
Comments
-
- (~x) means (x != -1), cause ~(-1) = 0, ~(-2) = 1, ~(1) = -2 and ~(100) = -101. as I understood, ~x is ((x * (-1)) - 1)
Add Comment
Please, Sign In to add comment
Advertisement