이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/// R
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define in insert
#define mpr make_pair
#define vl vector<ll>
#define endl '\n'
using namespace std;
const int sz = 2e5+5;
const ll inf = 1000000000000000;
//tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> rbt;a
/*struct DSU{
vector<ll> e;
void init(ll n){
e.assign(n+1, -1);
}
ll base(ll x){
if(e[x] < 0){
return x;
}
return e[x] = base(e[x]);
}
bool unite(ll a, ll b){
a = base(a);
b = base(b);
if(a == b){return false;}
if(e[a] > e[b]){
swap(a, b);
}
e[a] += e[b];
e[b] = a;
return true;
}
};*/
ll n, k, m;
void print(vl v){
for(int i = 0;i<n;i++){
cout << v[i] << ' ';
}
cout << endl;
}
void solve(){
ll i, j, bg, ed, pt, w1, w2, cnt, l, r, cc;
cin>>n>>k;
m = n + k;
vl d, v(m), res;
for(i=0;i<m;i++){
cin>>v[i];
}
for(i=1;i<m;i++){
d.pb(v[i] - v[i-1]);
}
for(i=0;i<=k;i++){
for(j=0;j<=k-i;j++){
bg = i;
ed = m - 2 - j;
cc = i + j;
bool as = 0, tmr = 1;
w1 = 0, w2 = 0;
if(bg > ed){
continue;
}
vl bad;
w1 = d[bg];
w2 = d[ed];
cnt = 1;
while(bg < ed){
if(w1 == w2){
cnt++;
bg++;ed--;
w1 = d[bg];
w2 = d[ed];
tmr = 1;
continue;
}
else if(w1 > w2){
bad.pb(ed);
ed--;
cc++;
w2 += d[ed];
}
else{
bg++;
cc++;
bad.pb(bg);
w1 += d[bg];
}
tmr = 0;
}
if(cc > k){continue;}
if(tmr && cnt == (n/2)){
l = i;
r = m - j - 1;
ll p = 0;
for(pt = l; pt <= r; pt++){
if(p < bad.size() && pt == bad[p]){p++;continue;}
res.pb(v[pt]);
}
print(res);
return ;
}
}
}
assert(0);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll t=1;
//cin>>t;
while(t--){
solve();
}
}
/*
6 3
1 2 3 6 7 9 10 12 14
1 3 6 7 10 12
*/
컴파일 시 표준 에러 (stderr) 메시지
tabletennis.cpp: In function 'void solve()':
tabletennis.cpp:100:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
100 | if(p < bad.size() && pt == bad[p]){p++;continue;}
| ~~^~~~~~~~~~~~
tabletennis.cpp:62:18: warning: unused variable 'as' [-Wunused-variable]
62 | bool as = 0, tmr = 1;
| ^~
# | 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... |