Advertisement
Korotkodul

N2 debug

Nov 3rd, 2022
511
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.06 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.  
  51. #include <ctime>
  52. vector <int> ans = {-1, -1, -1};
  53. int A, B, C, n;
  54.  
  55. bool ok(int x) {
  56.     int 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 <int> my() {
  78.     ios::sync_with_stdio(0);
  79.     cin.tie(0);
  80.     cout.tie(0);
  81.     int l = 0 + A % 2, r = n + n % 2 + A % 2 + 10, m;
  82.     while (l + 1 < r) {
  83.         m = (l + r) / 2;
  84.         if (ok(m)) {
  85.             l = m;
  86.         } else {
  87.             r = m;
  88.         }
  89.     }
  90.     /*if (ans[0] == -1) {
  91.         cout << 0;
  92.         exit(0);
  93.     }*/
  94.     /*for (int i: ans) {
  95.         cout << i << "\n";
  96.     }*/
  97.     return ans;
  98. }
  99.  
  100. bool cmp(vector <int> a, vector <int> b) {
  101.     return a[0] > b[0];
  102. }
  103.  
  104. vector <int> his() {
  105.     vector <vector <int> > ans;
  106.     for (int x= 0; x <= n; ++x) {
  107.         for (int y = 0; y <= n - x; ++y) {
  108.             for (int z = 0; z <= n - x - y; ++z) {
  109.                 if (x + y + z > n) continue;
  110.                 int a = A + x, b = B + y, c = C + z;
  111.                 if (a == 2 * b && a == 2 * c) {
  112.                     ans.push_back({x + y + z, x, y, z});
  113.                 }
  114.             }
  115.         }
  116.     }
  117.     vector <int> res = {-1, -1, -1};
  118.     if (ans.empty()) {
  119.         return res;
  120.     }
  121.     sort(ans.begin(), ans.end(), cmp);
  122.     for (int i = 1; i <= 3; ++i) {
  123.         res[i - 1] = ans[0][i];
  124.     }
  125.     return res;
  126. }
  127.  
  128. bool sh = 1;
  129. bool random = 0;
  130.  
  131. /*
  132. 38 15 14 76
  133. WA
  134. */
  135.  
  136. int main() {
  137.  
  138.     srand(time(0));
  139.     if (random) {
  140.        A = rand() % 100;
  141.         B = rand() % 100;
  142.         C = rand() % 100;
  143.         n = rand() % 100;
  144.     }
  145.     else {
  146.        cin >> A >> B >> C >> n;
  147.     }
  148.  
  149.     if (sh) {
  150.         cout << A << ' ' << B << ' ' << C << ' ' << n << "\n";
  151.     }
  152.     auto me = my();
  153.     auto he = his();
  154.     if (me == he) {
  155.         cv(me);
  156.         cout << "OK\n";
  157.     }
  158.     else {
  159.         cout << "WA\n";
  160.         cout << "me\n";
  161.         cv(me) ;
  162.         cout << "he\n";
  163.         cv(he);
  164.     }
  165. }
  166.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement