Advertisement
senb1

krsu 3407 (not my code)

Mar 29th, 2023
607
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.19 KB | None | 0 0
  1. #include "bits/stdc++.h"
  2. using namespace std;
  3.  
  4. #define ar array
  5. typedef long long ll;
  6. #define int ll
  7.  
  8. signed main() {
  9.     ios::sync_with_stdio(0);
  10.     cin.tie(0);
  11.  
  12.     int n, a, b;
  13.     cin >> a >> b >> n;
  14.     vector<int> y(n);
  15.     for (int i = 1; i <= n; i++) {
  16.         y[i - 1] = (2ll * i * i + b) % 3 + i % 2;
  17.     }
  18.     int ans = 1e9;
  19.     auto sq = [&](int x) { return x * 1ll * x; };
  20.     auto dis = [&](int i, int j) {
  21.         return ceil(sqrt(sq((i - j) * a) + sq(y[i] - y[j])));
  22.     };
  23.  
  24.     for (int j = 0; j < 4; j++) {
  25.         int last = -1, f = -1, res = 0;
  26.         for (int i = 0; i < n; i++) {
  27.             if (y[i] <= j) {
  28.                 if (~last)
  29.                     res += dis(last, i);
  30.                 if (f == -1)
  31.                     f = i;
  32.                 last = i;
  33.             }
  34.         }
  35.  
  36.         for (int i = n - 1; ~i; i--) {
  37.             if (y[i] > j) {
  38.                 if (~last)
  39.                     res += dis(last, i);
  40.                 if (f == -1)
  41.                     f = i;
  42.                 last = i;
  43.             }
  44.         }
  45.  
  46.         res += dis(f, last);
  47.         ans = min(ans, res);
  48.     }
  49.  
  50.     cout << ans + n << "\n";
  51. }
  52.  
  53. /*
  54.  
  55. 3 3 4
  56.  
  57. */
  58.  
Advertisement
Comments
  • senb1
    1 year
    # text 0.12 KB | 0 0
    1. (~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