Submission #366156

# Submission time Handle Problem Language Result Execution time Memory
366156 2021-02-13T11:32:17 Z Ahmad_Hasan Table Tennis (info1cup20_tabletennis) C++17
72 / 100
3000 ms 249696 KB
#include <bits/stdc++.h>
#define int long long
/**
     ||||||||||       |||||     |||||    ||||||||||
    |||||||||||||     |||||     |||||  |||||
   ||||     ||||||    |||||     |||||  |||||
  |||||||||||||||||   |||||||||||||||    ||||||||||
 |||||||||||||||||||  |||||||||||||||           |||||
 |||||         |||||  |||||     |||||           |||||
 |||||         |||||  |||||     |||||    ||||||||||
AHMED;HASSAN;SAEED;
*/

using namespace std;
unordered_map<int,int>mp;
vector<int>v;
map<pair<int,int>,pair<int,pair<int,int> > >dp;
int n,k;
int slv(int l,int r){
    if(dp[{l,r}].first)
        return dp[{l,r}].first;
    int ret=1;
    for(int i=l+1;i<r&&(i-l)<=k+5;i++){
        if(mp[v[r]-(v[i]-v[l])]>i+1){
            int ret2=1+slv(i,mp[v[r]-(v[i]-v[l])]-1);
            ///cout<<'#'<<i<<' '<<mp[v[r]-(v[i]-v[l])]-1<<'\n';
            if(ret2>ret){
                ret=ret2;
                dp[{l,r}].second={i,mp[v[r]-(v[i]-v[l])]-1};
            }

        }

    }

    return dp[{l,r}].first=ret;

}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);      cout.tie(0);
    cin>>n>>k;
    n+=k;
    v=vector<int>(n);
    for(int i=0;i<n;i++){
        cin>>v[i];
        mp[v[i]]=i+1;
    }

    int ans=0;
    int l,r;
    for(int i=0;i<=k;i++){
        for(int j=n-1;j>=n-k-1&&(i+n-1-j)<=k;j--){
            int ret=slv(i,j);
            if(ret>ans){
                ans=ret;
                l=i,r=j;
            }


        }

    }
    vector<int>v2(n-k);
    int cnt=0;
    int tol=0,tor=n-k-1;
    while(cnt<n-k){
        v2[tol]=v[l],v2[tor]=v[r];
        int nl=dp[{l,r}].second.first,nr=dp[{l,r}].second.second;
        l=nl,r=nr;
        cnt+=2;
        tol++; tor--;
    }
    for(int i=0;i<n-k;i++)
        cout<<v2[i]<<' ';


    return 0;
}

Compilation message

tabletennis.cpp: In function 'int32_t main()':
tabletennis.cpp:70:33: warning: 'r' may be used uninitialized in this function [-Wmaybe-uninitialized]
   70 |         v2[tol]=v[l],v2[tor]=v[r];
      |                                 ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 748 KB Output is correct
2 Correct 3 ms 748 KB Output is correct
3 Correct 2 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 5612 KB Output is correct
2 Correct 240 ms 30004 KB Output is correct
3 Correct 261 ms 29876 KB Output is correct
4 Correct 232 ms 30004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 242 ms 29620 KB Output is correct
2 Correct 259 ms 30004 KB Output is correct
3 Correct 242 ms 30132 KB Output is correct
4 Correct 270 ms 30004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 125 ms 14900 KB Output is correct
2 Correct 85 ms 14900 KB Output is correct
3 Correct 71 ms 9396 KB Output is correct
4 Correct 116 ms 15196 KB Output is correct
5 Correct 76 ms 9440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 6 ms 876 KB Output is correct
3 Correct 15 ms 1004 KB Output is correct
4 Correct 4 ms 876 KB Output is correct
5 Correct 4 ms 748 KB Output is correct
6 Correct 93 ms 3052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 501 ms 30196 KB Output is correct
3 Correct 469 ms 30132 KB Output is correct
4 Correct 840 ms 36788 KB Output is correct
5 Correct 438 ms 30132 KB Output is correct
6 Execution timed out 3067 ms 74256 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3074 ms 249696 KB Time limit exceeded
2 Halted 0 ms 0 KB -