Submission #910973

# Submission time Handle Problem Language Result Execution time Memory
910973 2024-01-18T10:28:34 Z vjudge1 Table Tennis (info1cup20_tabletennis) C++17
0 / 100
1 ms 348 KB
#include <algorithm>
#include <iostream>
#include <fstream>
#include <queue>
#include <cmath>

#define fi first
#define se second

#define sz(a) int((a).size())
#define all(a) (a).begin(), (a).end()

using namespace std;

using pii = pair<int, int>;

const int NMAX = 15e4+5;

int n, k;
int a[NMAX];
vector<int> ans;

void read() {
   cin >> n >> k;
   for (int i = 1; i <= n + k; i++) {
      cin >> a[i];
   }
}

bool check(vector<int> a) {
   if (sz(a) == 2) return a[0] == a[1];
   sort(all(a));
   for (int i = 0; i < sz(a) / 2; i++)
      a[i] += a[sz(a) - i - 1];

   if (sz(a) % 2 == 0) a.resize(sz(a) / 2);
   else a.resize(sz(a) / 2 + 2);

   return check(a);
}

void solve() {
   if (k == 1) {
      vector<int> v;
      for (int i = 1; i <= n; i++)
         v.push_back(a[i]);
      for (int i = 0; i < n; i++) {
         if (i != n - 1)
            swap(v[i], v[n - 1]);
         if (check(v)) {
            ans = v;
            break;
         }
         if (i != n - 1)
            swap(v[i], v[n - 1]);
      }
   } else {
      for (int mask = 1; mask < 1 << (n + k); mask++) {
         if (__builtin_popcount(mask) != n) continue;
         vector<int> v;
         for (int i = 0; i < n + k; i++) {
            if (mask & (1 << i))
               v.push_back(a[i + 1]);
         }
         if (check(v)) {
            ans = v;
            break;
         }
      }
   }
   sort(all(ans));
   for (auto &it : ans) {
      cout << it << ' ';
   }
}

signed main() {
#ifdef LOCAL
   freopen("input.txt", "r", stdin);
#else
   freopen("trapped.in", "r", stdin);
   freopen("trapped.out", "w", stdout);
#endif

   read();
   solve();
   
   return 0;
}

Compilation message

tabletennis.cpp: In function 'int main()':
tabletennis.cpp:81:11: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   81 |    freopen("trapped.in", "r", stdin);
      |    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
tabletennis.cpp:82:11: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |    freopen("trapped.out", "w", stdout);
      |    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -