Advertisement
Korotkodul

N2 70 from 100

Nov 3rd, 2022
604
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.13 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <queue>
  5. #include <algorithm>
  6. #include <string>
  7. #include <stack>
  8. #include <set>
  9. #include <map>
  10. #define pii pair <int, int>
  11. #define pb(x) push_back(x)
  12. using namespace std;
  13. using ll = long long;
  14. using ld = long double;
  15. using db = double;
  16. void cv(vector <int> &v) {
  17.     for (auto x : v) cout << x << ' ';
  18.     cout << "\n";
  19. }
  20.  
  21. void cvl(vector <ll> &v) {
  22.     for (auto x : v) cout << x << ' ';
  23.     cout << "\n";
  24. }
  25.  
  26.  
  27. void cvv(vector <vector <int> > &v) {
  28.     for (auto x : v) cv(x);
  29.     cout << "\n";
  30. }
  31.  
  32. void cvb(vector <bool> v) {
  33.     for (bool x : v) cout << x << ' ';
  34.     cout << "\n";
  35. }
  36.  
  37. void cvs(vector <string>  v) {
  38.     for (auto a : v) {
  39.         cout << a << "\n";
  40.     }
  41. }
  42.  
  43. void cvp(vector <pii> a) {
  44.     for (auto p : a) {
  45.         cout << p.first << ' ' << p.second << "\n";
  46.     }
  47.     cout << "\n";
  48. }
  49.  
  50. bool sh = 0;
  51. #include <ctime>
  52. vector <ll> ans = {-1, -1, -1};
  53. ll A, B, C, n;
  54.  
  55. bool ok(ll x) {
  56.     ll y, z, a, b, c;
  57.     a = A + x;
  58.     if (a % 2 == 1) {
  59.         return 0;
  60.     }
  61.     b = a / 2;
  62.     y = b - B;
  63.     c = b;
  64.     z = c - C;
  65.     bool r = x + y + z <= n && y >= 0 && z >= 0;
  66.     if (r) {
  67.         ans[0] = x;
  68.         ans[1] = y;
  69.         ans[2] = z;
  70.     }
  71.     return r;
  72. }
  73.  
  74.  
  75.  
  76.  
  77. vector <ll> my() {
  78.     ll l = 0 + A % 2, r = n + n % 2 + A % 2 + 10, m;
  79.     if (sh) {
  80.         cout << "l r = " << l << ' ' << r << "\n";
  81.     }
  82.     while (l + 1 < r) {
  83.         m = (l + r) / 2;
  84.         ll k = m * 2 + A % 2;
  85.         if (sh) {
  86.             cout << "m = " << m << "\n";
  87.         }
  88.         if (ok(k)) {
  89.             l = m;
  90.         } else {
  91.             r = m;
  92.         }
  93.     }
  94.     /*if (ans[0] == -1) {
  95.         cout << 0;
  96.         exit(0);
  97.     }*/
  98.     /*for (int i: ans) {
  99.         cout << i << "\n";
  100.     }*/
  101.     return ans;
  102. }
  103.  
  104. bool cmp(vector <int> a, vector <int> b) {
  105.     return a[0] > b[0];
  106. }
  107.  
  108. vector <int> his() {
  109.     vector <vector <int> > ans;
  110.     for (int x= 0; x <= n; ++x) {
  111.         for (int y = 0; y <= n - x; ++y) {
  112.             for (int z = 0; z <= n - x - y; ++z) {
  113.                 if (x + y + z > n) continue;
  114.                 int a = A + x, b = B + y, c = C + z;
  115.                 if (a == 2 * b && a == 2 * c) {
  116.                     ans.push_back({x + y + z, x, y, z});
  117.                 }
  118.             }
  119.         }
  120.     }
  121.     vector <int> res = {-1, -1, -1};
  122.     if (ans.empty()) {
  123.         return res;
  124.     }
  125.     sort(ans.begin(), ans.end(), cmp);
  126.     for (int i = 1; i <= 3; ++i) {
  127.         res[i - 1] = ans[0][i];
  128.     }
  129.     return res;
  130. }
  131.  
  132.  
  133. /*
  134. 38 15 14 76
  135. WA
  136. */
  137.  
  138. int main() {
  139.     sh = 0;
  140.     srand(time(0));
  141.     cin >> A >> B >> C >> n;
  142.  
  143.  
  144.     if (sh) {
  145.         cout << A << ' ' << B << ' ' << C << ' ' << n << "\n";
  146.     }
  147.     auto me = my();
  148.     //auto he = his();
  149.     /*if (me == he) {
  150.         cv(me);
  151.         cout << "OK\n";
  152.     }
  153.     else {
  154.         cout << "WA\n";
  155.         cout << "me\n";
  156.         cv(me) ;
  157.         cout << "he\n";
  158.         cv(he);
  159.     }*/
  160.     if (me[0] == -1) {
  161.         cout << 0;
  162.         exit(0);
  163.     }
  164.     for (ll i: me) {
  165.         cout << i << "\n";
  166.     }
  167. }
  168.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement