Submission #366158

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

using namespace std;
unordered_map<int,int>mp;
vector<int>v;
map<int,pair<int,pair<int,int> > >dp[150000];
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:20: warning: 'l' 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 6 ms 7788 KB Output is correct
2 Correct 7 ms 7788 KB Output is correct
3 Correct 6 ms 7788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 12396 KB Output is correct
2 Correct 136 ms 33204 KB Output is correct
3 Correct 142 ms 33204 KB Output is correct
4 Correct 143 ms 33204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 133 ms 33204 KB Output is correct
2 Correct 139 ms 33204 KB Output is correct
3 Correct 146 ms 33352 KB Output is correct
4 Correct 148 ms 33272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 121 ms 21940 KB Output is correct
2 Correct 91 ms 21940 KB Output is correct
3 Correct 77 ms 16436 KB Output is correct
4 Correct 107 ms 22240 KB Output is correct
5 Correct 76 ms 16436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7424 KB Output is correct
2 Correct 5 ms 7404 KB Output is correct
3 Correct 5 ms 7404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 7532 KB Output is correct
2 Correct 8 ms 7916 KB Output is correct
3 Correct 9 ms 8044 KB Output is correct
4 Correct 8 ms 7916 KB Output is correct
5 Correct 7 ms 7788 KB Output is correct
6 Correct 43 ms 10092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 7532 KB Output is correct
2 Correct 201 ms 33332 KB Output is correct
3 Correct 192 ms 33332 KB Output is correct
4 Correct 277 ms 39988 KB Output is correct
5 Correct 198 ms 33332 KB Output is correct
6 Correct 2741 ms 197720 KB Output is correct
7 Correct 348 ms 43188 KB Output is correct
8 Correct 345 ms 45072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3098 ms 262432 KB Time limit exceeded
2 Halted 0 ms 0 KB -