Submission #888306

#TimeUsernameProblemLanguageResultExecution timeMemory
888306raul2008487Table Tennis (info1cup20_tabletennis)C++17
49 / 100
27 ms6252 KiB
/// 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; vl d, v(sz); void print(ll bg, ll ed, ll pos){ ll l = bg, r = ed, s1 = d[bg], s2 = d[ed]; vl bad, res; while(l < r && pos <= k){ if(s1 == s2){ l++; r--; } else if(s1 < s2){ l++; bad.pb(l); s1 += d[l]; } else{ bad.pb(r); r--; s2 += d[r]; } } ll ptr = 0; for(int g = bg; g <= ed+1; g++){ if(ptr < bad.size() && bad[ptr] == g){ptr++;continue;} res.pb(v[g]); } for(auto x: res){ cout << x << ' '; } cout << endl; } bool check(ll bg, ll ed, ll pos){ ll l = bg, r = ed, s1 = d[bg], s2 = d[ed]; ll cnt = 1; if( l > r){return false;} bool tmr = 1; while(l < r && pos <= k){ if(s1 == s2){ l++; r--; cnt++; tmr = 1; continue; } else if(s1 < s2){ l++; pos++; s1 += d[l]; } else{ r--; pos++; s2 += d[r]; } tmr = 0; } return (cnt == (n/2) && pos == k && (tmr)); } void solve(){ ll i, j, bg, ed, pt, w1, w2, cnt, l, r, cc; cin>>n>>k; m = n + k; 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++){ if(check(i, m - 2 - j, i + j)){ print(i, m - 2 - j, i + j); 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 */

Compilation message (stderr)

tabletennis.cpp: In function 'void print(long long int, long long int, long long int)':
tabletennis.cpp:62:16: 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]
   62 |         if(ptr < bad.size() && bad[ptr] == g){ptr++;continue;}
      |            ~~~~^~~~~~~~~~~~
tabletennis.cpp: In function 'void solve()':
tabletennis.cpp:98:14: warning: unused variable 'bg' [-Wunused-variable]
   98 |     ll i, j, bg, ed, pt, w1, w2, cnt, l, r, cc;
      |              ^~
tabletennis.cpp:98:18: warning: unused variable 'ed' [-Wunused-variable]
   98 |     ll i, j, bg, ed, pt, w1, w2, cnt, l, r, cc;
      |                  ^~
tabletennis.cpp:98:22: warning: unused variable 'pt' [-Wunused-variable]
   98 |     ll i, j, bg, ed, pt, w1, w2, cnt, l, r, cc;
      |                      ^~
tabletennis.cpp:98:26: warning: unused variable 'w1' [-Wunused-variable]
   98 |     ll i, j, bg, ed, pt, w1, w2, cnt, l, r, cc;
      |                          ^~
tabletennis.cpp:98:30: warning: unused variable 'w2' [-Wunused-variable]
   98 |     ll i, j, bg, ed, pt, w1, w2, cnt, l, r, cc;
      |                              ^~
tabletennis.cpp:98:34: warning: unused variable 'cnt' [-Wunused-variable]
   98 |     ll i, j, bg, ed, pt, w1, w2, cnt, l, r, cc;
      |                                  ^~~
tabletennis.cpp:98:39: warning: unused variable 'l' [-Wunused-variable]
   98 |     ll i, j, bg, ed, pt, w1, w2, cnt, l, r, cc;
      |                                       ^
tabletennis.cpp:98:42: warning: unused variable 'r' [-Wunused-variable]
   98 |     ll i, j, bg, ed, pt, w1, w2, cnt, l, r, cc;
      |                                          ^
tabletennis.cpp:98:45: warning: unused variable 'cc' [-Wunused-variable]
   98 |     ll i, j, bg, ed, pt, w1, w2, cnt, l, r, cc;
      |                                             ^~
#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...