Submission

Status:

[PPPPPPPPPPPPPP]

Subtask/Task Score:

{100/100}

Score: 100

User: kittipos

Problemset: anna

Language: cpp

Time: 0.007 second

Submitted On: 2026-03-05 19:58:10

#include <iostream>
#include <vector>
#define int int64_t

using namespace std;


vector<vector<int>> get_permutation(vector<int> vec) {
  if (vec.size() == 1) {
    return {vec};
  }

  vector<vector<int>> output;
  for (int i = 0; i < vec.size(); i++) {
    // pass new vector that exclude i to recursive
    // then get output of recursive add i in front and add to output
    vector<int> temp = vec;
    temp.erase(temp.begin() + i);

    vector<vector<int>> sub_per = get_permutation(temp);
    for (int j = 0; j < sub_per.size(); j++) {
      sub_per[j].insert(sub_per[j].begin(), vec[i]);
      output.push_back(sub_per[j]);
    }
  }

  return output;
}

bool check(int a, int b, int c, int d, int e, int x, int y) {
  if (x <= y || y <= 0) {
    return false;
  }
  return
  (a == x+y) &&
  (b == x-y) &&
  (c == x*y) &&
  (d == x%y) &&
  (e == x/y) ;
}

int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;
  cin >> n;

  for (int j = 0; j < n; j++)
  {
    vector<int> nums;
    nums.resize(5);
    for (int i = 0; i < 5; i++) {
      cin >> nums[i];
    }
    vector<vector<int>> permu = get_permutation(nums);
    
    int cx = 0;
    int cy = 0;
    for (int i = 0; i < permu.size(); i++) {
      // cout << "check point 1: " << permu[i].size() << endl;
      int a = permu[i][0];
      int b = permu[i][1];
      int c = permu[i][2];
      int d = permu[i][3];
      int e = permu[i][4];
      // cout << "check point 2: "
      // << "a: " << a
      // << ", b: " << b
      // << ", c: " << c
      // << ", d: " << d
      // << ", e: " << e
      //  << endl;

      int x = (a + b) / 2;
      int y = a - x;

      if (check(a, b, c, d, e, x, y)) {
        if (cx == 0) {
          cx = x;
          cy = y;
        } else {
          if (cx == x && cy == y) {
            continue;
          }
          cx = 0;
          cy = 0;
          goto done;
        }
      }
    }

    done:
    cout << cx << ' ' << cy << '\n';
  }

  return 0;
}