제출 #523037

#제출 시각아이디문제언어결과실행 시간메모리
523037Farhan_HYTable Tennis (info1cup20_tabletennis)C++14
43 / 100
72 ms2956 KiB
#include <bits/stdc++.h> #define int long long #define float double #define pb push_back #define F first #define S second #define T int t; cin >> t; while(t--) #define IOS ios::sync_with_stdio(); cin.tie(0); cout.tie(0); using namespace std; const int inf = 8e18; const int N = 1e6 + 6; const int M = 1e3 + 3; const int mod = 1e9 + 7; const float pi = atan(1) * 4; int a[N]; int n, m; set<int> st; set<int> ans; main() { cin >> n >> m; n += m; for(int i = 0; i < n; i++) cin >> a[i]; if (n > 2 && n <= 18) { int l = 0, r = n - 1; st.insert(a[l] + a[r]); st.insert(a[l + 1] + a[r]); st.insert(a[l] + a[r - 1]); if (m > 1) { st.insert(a[l] + a[r - 2]); st.insert(a[l + 2] + a[r]); } for(auto x: st) { l = 0, r = n - 1; bool ok = true; int cnt = 2; ans.clear(); while(l < r) { if (a[l] + a[r] == x) { l++; r--; continue; } if (l != n - 1 && a[l + 1] + a[r] == x && l + 1 != r) { cnt++; ans.insert(l); l += 2; r--; continue; } if (r != 0 && a[l] + a[r - 1] == x && l != r - 1) { cnt++; ans.insert(r); r -= 2; l++; continue; } ok = false; l++, r--; } if (ok && cnt <= m) break; } int cnt = 0; for(int i = 0; i < n; i++) { if (cnt == n - m) break; if (st.find(i) == st.end()) cout << a[i] << ' ', cnt++; } return 0; } int l = 0, r = n - 1; if (m == 1) { st.insert(a[l] + a[r]); st.insert(a[l + 1] + a[r]); st.insert(a[l] + a[r - 1]); } else { st.insert(a[l] + a[r]); st.insert(a[l + 1] + a[r]); st.insert(a[l] + a[r - 1]); st.insert(a[l] + a[r - 2]); st.insert(a[l + 1] + a[r - 1]); st.insert(a[l + 2] + a[r]); } for(auto x: st) { ans.clear(); l = 0, r = n - 1; bool ok = true; int cnt = 0; while(l < r) { if (a[l] + a[r] == x) { l++; r--; continue; } if (l != n - 1 && a[l + 1] + a[r] == x && l + 1 != r) { cnt++; ans.insert(l); l += 2; r--; continue; } if (r != 0 && a[l] + a[r - 1] == x && l != r - 1) { cnt++; ans.insert(r); r -= 2; l++; continue; } if (m > 1 && r != 1 && a[l] + a[r - 2] == x && l != r - 2) { cnt += 2; ans.insert(r); ans.insert(r - 1); r -= 3; l++; continue; } if (m > 1 && l != n - 2 && a[l + 2] + a[r] == x && l != r + 2) { cnt += 2; ans.insert(l); ans.insert(l + 1); r--; l += 3; continue; } if (m > 1 && a[l + 1] + a[r - 1] == x && r - l != 1) { cnt += 2; ans.insert(l); ans.insert(r); r -= 2; l += 2; continue; } ok = false; l++, r--; } if (ok && cnt == m) break; } int cnt = 0; for(int i = 0; i < n; i++) { if (cnt == n - m) break; if (ans.find(i) == ans.end()) cout << a[i] << ' ', cnt++; } }

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

tabletennis.cpp:22:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   22 | main()
      | ^~~~
#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...