이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
#pragma GCC optimize("unroll-loops")
*/
#include <bits/stdc++.h>
#define taskname "bai3"
#define all(x) x.begin(), x.end()
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
using namespace std;
const int mxN = 2e5 + 5;
const int base = 1e9 + 1;
const int mod = 1e9 + 7;
const ll oo = 1e18;
int n, k, a[mxN];
map<int, int> s;
bool test(int l, int r) {
vector<int> bruh, bruh1;
int cnt = n + k - r + l - 1;
int sum = a[l] + a[r];
if(s.find(sum) != s.end()) return false;
else s[sum]++;
int actual_count = 0;
while(l < r) {
int tmp = a[l] + a[r];
if(tmp == sum) {
bruh.pb(a[l]);
bruh1.pb(a[r]);
++l; --r;
actual_count += 2;
}
else {
++cnt;
if(tmp > sum) --r;
else ++l;
}
if(cnt > k) return false;
if(actual_count == n) {
for(int i = 0; i * 2 < actual_count; ++i) cout << bruh[i] << " ";
for(int i = (actual_count >> 1) - 1; i >= 0; --i) cout << bruh1[i] << " ";
cout << endl;
return true;
}
}
for(int i = 0; i * 2 < actual_count; ++i) cout << bruh[i] << " ";
for(int i = (actual_count >> 1) - 1; i >= 0; --i) cout << bruh1[i] << " ";
cout << endl;
return true;
}
bool check(int sum) {
vector<int> bruh, bruh1;
int cnt = 0, l = 1, r = n + k;
int actual_count = 0;
while(l < r) {
int tmp = a[l] + a[r];
if(tmp == sum) {
bruh.pb(a[l]);
bruh1.pb(a[r]);
++l; --r;
actual_count += 2;
}
else {
++cnt;
if(tmp > sum) --r;
else ++l;
}
if(cnt > k) return false;
if(actual_count == n) {
for(int i = 0; i * 2 < actual_count; ++i) cout << bruh[i] << " ";
for(int i = (actual_count >> 1) - 1; i >= 0; --i) cout << bruh1[i] << " ";
cout << endl;
return true;
}
}
for(int i = 0; i * 2 < actual_count; ++i) cout << bruh[i] << " ";
for(int i = (actual_count >> 1) - 1; i >= 0; --i) cout << bruh1[i] << " ";
cout << endl;
return true;
}
void solve() {
cin >> n >> k;
for(int i = 1; i <= n + k; ++i) cin >> a[i];
if(n + k <= 4 * k) {
for(int i = 1; i <= k + 1; ++i) {
for(int j = n + k; j >= n + i - 1; --j) {
if(test(i, j)) return;
}
}
}
int min_sum = a[1] + a[n - k + 1];
for(int i = 1; i <= 2 * k; ++i) {
for(int j = n + k; j > n - k; --j) {
s[a[i] + a[j]]++;
}
}
for(auto [u, v] : s) {
if(v >= k && u >= min_sum) {
if(check(u)) return;
}
}
}
signed main() {
#ifdef CDuongg
freopen("bai3.inp", "r", stdin);
freopen("bai3.out", "w", stdout);
auto start = chrono::high_resolution_clock::now();
#endif
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1; //cin >> t;
while(t--) solve();
#ifdef CDuongg
auto end = chrono::high_resolution_clock::now();
cout << "\n"; for(int i = 1; i <= 100; ++i) cout << '=';
cout << "\nExecution time: " << chrono::duration_cast<chrono::milliseconds> (end - start).count() << "[ms]" << endl;
#endif
}
컴파일 시 표준 에러 (stderr) 메시지
tabletennis.cpp: In function 'void solve()':
tabletennis.cpp:109:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
109 | for(auto [u, v] : s) {
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |