제출 #1145185

#제출 시각아이디문제언어결과실행 시간메모리
1145185mansurTable Tennis (info1cup20_tabletennis)C++20
87 / 100
3087 ms4360 KiB
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") //#pragma GCC optimize("Ofast,unroll-loops,fast-math,O3") #include<bits/stdc++.h> using namespace std; #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define sz(a) (int)a.size() #define s second #define f first using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); vector<pii> rid = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}}; vector<pii> dir = {{-1, -1}, {-1, 1}, {1, -1}, {1, 1}}; const int N = 1e6 + 1, mod = 998244353; const ll inf = 1e9; double eps = 1e-15; bool flg = 0; void slv() { int n, k; cin >> n >> k; int m = n + k; int a[m + 1]; for (int i = 1; i <= m; i++) cin >> a[i]; int l[m + 1], r[m + 1]; for (int i = 1; i <= m; i++) { l[i] = i; if (i <= 2) { l[i] = 1; continue; } if (a[i] - a[i - 1] == a[i - 1] - a[i - 2]) l[i] = l[i - 1]; } for (int i = m; i >= 1; i--) { r[i] = i; if (i >= m - 1) { r[i] = m; continue; } if (a[i] - a[i + 1] == a[i + 1] - a[i + 2]) r[i] = r[i + 1]; } for (int i = 1; i <= min(m, k + 1); i++) { for (int j = m; j >= max(1, m - k) && i + (m - j) - 1 <= k; j--) { int v = a[i] + a[j]; vector<int> ansl, ansr; int x = i, y = j, cnt = i + m - j - 1; while (x <= y) { if (a[x] + a[y] < v) { x++, cnt++; continue; } if (a[x] + a[y] > v) { y--, cnt++; continue; } int len = min(r[x] - x + 1, y - l[y] + 1); len = min(len, (y - x + 1) / 2); x += len, y -= len; } //cout << i << ' ' << j << ' ' << v << ' ' << cnt << endl; if (cnt > k) continue; x = i, y = j, cnt = i + m - j - 1; while (x <= y) { if (a[x] + a[y] < v) { x++, cnt++; continue; } if (a[x] + a[y] > v) { y--, cnt++; continue; } int len = min(r[x] - x + 1, y - l[y] + 1); len = min(len, (y - x + 1) / 2); while (len-- && sz(ansl) + sz(ansr) < n) { ansl.push_back(a[x++]); ansr.push_back(a[y--]); } if (sz(ansl) + sz(ansr) == n) break; } for (int x: ansl) cout << x << ' '; reverse(all(ansr)); for (int x: ansr) cout << x << ' '; return; } } } main() { //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); ios_base::sync_with_stdio(0); cin.tie(0); int tp = 1; if (flg) cin >> tp; while (tp--) { slv(); } } //wenomechainsama

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

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