#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <vector>
using namespace std;
using ll = long long;
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;
}
void solve_slow(vector<int> a, int n, int k) {
int mxval = get_bestval(a, 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';
}
const ll MOD = 1000000007;
ll pw(ll a, ll m) {
if (!m)
return 1;
a %= MOD;
if (m % 2)
return a * pw(a, m - 1) % MOD;
return pw(a * a, m / 2);
}
void solve_smallk(vector<int> a, int n, int k) {
int m = n + k;
vector<int> na;
for (int i = 0; i < 2 * k; ++i)
na.push_back(a[i]);
for (int i = m - 2 * k; i < m; ++i)
na.push_back(a[i]);
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';
return;
vector<int> dif(m - 1);
for (int i = 0; i + 1 < n + k; ++i) {
dif[i] = a[i + 1] - a[i];
}
vector<ll> phash_(m);
vector<ll> rhash_(m);
vector<ll>::iterator phash = phash_.begin() + 1;
vector<ll>::iterator rhash = rhash_.begin() + 1;
for (int i = 0; i + 1 < m; ++i) {
phash[i] = (phash[i - 1] + pw(101, i) * dif[i]) % MOD;
rhash[i] = (rhash[i - 1] + pw(101, i) * dif[m - 2 - i]) % MOD;
}
int lb = 1, ub = n / 2 + 1;
while (ub - lb > 1) {
int mb = (lb + ub) / 2;
set<ll> hashes;
for (int i = 0; i + mb < m - 1; ++i) {
ll hsh = (phash[i + mb] - phash[i - 1]) / pw(101, MOD - 1 - i);
hashes.insert(hsh);
//hashes.push_back(
}
}
}
signed main() {
int n, k;
cin >> n >> k;
vector<int> a(n + k);
for (int i = 0; i < n + k; ++i) {
cin >> a[i];
}
if (n * k <= 1000000) {
solve_slow(a, n, k);
return 0;
} else {
}
}
Compilation message
tabletennis.cpp: In function 'void solve_slow(std::vector<int>, int, int)':
tabletennis.cpp:53:23: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
53 | while (ans.size() > n)
| ~~~~~~~~~~~^~~
tabletennis.cpp: In function 'void solve_smallk(std::vector<int>, int, int)':
tabletennis.cpp:82:23: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
82 | while (ans.size() > n)
| ~~~~~~~~~~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
312 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
1132 KB |
Output is correct |
2 |
Correct |
96 ms |
5428 KB |
Output is correct |
3 |
Correct |
98 ms |
5700 KB |
Output is correct |
4 |
Correct |
99 ms |
5716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
85 ms |
5076 KB |
Output is correct |
2 |
Correct |
94 ms |
6548 KB |
Output is correct |
3 |
Correct |
92 ms |
5080 KB |
Output is correct |
4 |
Correct |
83 ms |
6556 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
684 KB |
Output is correct |
2 |
Correct |
3 ms |
852 KB |
Output is correct |
3 |
Correct |
3 ms |
852 KB |
Output is correct |
4 |
Correct |
2 ms |
684 KB |
Output is correct |
5 |
Correct |
3 ms |
852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
308 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
3 ms |
324 KB |
Output is correct |
3 |
Correct |
12 ms |
1936 KB |
Output is correct |
4 |
Correct |
3 ms |
436 KB |
Output is correct |
5 |
Correct |
3 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
59 ms |
2268 KB |
Unexpected end of file - int32 expected |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
4556 KB |
Output is correct |
2 |
Incorrect |
58 ms |
2252 KB |
Unexpected end of file - int32 expected |
3 |
Halted |
0 ms |
0 KB |
- |