제출 #499885

#제출 시각아이디문제언어결과실행 시간메모리
499885jesus_coconutTable Tennis (info1cup20_tabletennis)C++17
87 / 100
3082 ms3716 KiB
#include <bits/stdc++.h> #define pb push_back #define all(a) begin(a), end(a) using namespace std; int n, k; vector<int> v; vector<int> dif; void load() { cin >> n >> k; v.resize(n + k); for (auto &it : v) cin >> it; } vector<int> ans; map<pair<int, int>, int> mp; bool solve(int sl, int sr) { int l = sl, r = sr; if (l >= r) return false; ans.clear(); ans.pb(v[l]); ans.pb(v[r]); while (l < r) { if (mp.count({l, r})) { mp[{sl, sr}] = mp[{l, r}] + ans.size(); if (mp[{sl, sr}] < n) return false; } int cl = dif[l+1]; int cr = dif[r]; int pl = l, pr = r; while (cl != cr && l < r) { if (cl < cr) { l++; cl += dif[l+1]; } else { r--; cr += dif[r]; } } ++l; --r; if (l >= r) break; if (cl == cr) { ans.pb(v[l]); ans.pb(v[r]); } if (ans.size() == n) return true; } mp[{sl, sr}] = ans.size(); return false; } void solve() { for (int i = 0; i <= k; ++i) { for (int j = 0; j <= k - i; ++j) { if (solve(i, n + k - 1 - j)) { sort(all(ans)); for (auto &it: ans) cout << it << ' '; return; }; } } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); load(); sort(all(v)); dif.resize(size(v)); adjacent_difference(all(v), begin(dif)); solve(); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

tabletennis.cpp: In function 'bool solve(int, int)':
tabletennis.cpp:46:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   46 |   if (ans.size() == n) return true;
      |       ~~~~~~~~~~~^~~~
tabletennis.cpp:30:7: warning: unused variable 'pl' [-Wunused-variable]
   30 |   int pl = l, pr = r;
      |       ^~
tabletennis.cpp:30:15: warning: unused variable 'pr' [-Wunused-variable]
   30 |   int pl = l, pr = r;
      |               ^~
#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...