Submission #751130

#TimeUsernameProblemLanguageResultExecution timeMemory
751130StickfishTable Tennis (info1cup20_tabletennis)C++17
61 / 100
365 ms29256 KiB
#include <iostream> #include <algorithm> #include <map> #include <cassert> #include <vector> using namespace std; const int MAXN = 157000; int get_bestval(vector<int> a, int k) { int n = a.size(); map<int, int> mp; for (int i = 0; i < n; ++i) { int ctr = n - i - 1; for (int t = -k; t <= k; ++t) { if (ctr + t <= i || ctr + t >= n) continue; int val = a[i] + a[ctr + t]; ++mp[val]; } } int mxval = 0; int mxcnt = 0; for (auto [val, cnt] : mp) { if (mxcnt < cnt) { mxval = val; mxcnt = cnt; } } return mxval; } vector<int> get_withsum(vector<int> a, int sm) { int n = a.size(); int j = n - 1; vector<int> ans; for (int i = 0; i < n; ++i) { while (j > i && a[i] + a[j] > sm) --j; if (a[i] + a[j] == sm) { ans.push_back(a[i]); ans.push_back(a[j]); } } return ans; } signed main() { int n, k; cin >> n >> k; vector<int> a(n + k); for (int i = 0; i < n + k; ++i) { cin >> a[i]; } vector<int> na; for (int i = 0; i < k * 2 + 10 && i < n + k; ++i) { na.push_back(a[i]); na.push_back(a[n + k - i - 1]); } sort(na.begin(), na.end()); na.resize(unique(na.begin(), na.end()) - na.begin()); int mxval = get_bestval(na, k); vector<int> ans = get_withsum(a, mxval); while (ans.size() > n) ans.pop_back(); sort(ans.begin(), ans.end()); for (int i = 0; i < n; ++i) { cout << ans[i] << ' '; } cout << '\n'; }

Compilation message (stderr)

tabletennis.cpp: In function 'int main()':
tabletennis.cpp:64:23: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   64 |     while (ans.size() > n)
      |            ~~~~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...