답안 #365828

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
365828 2021-02-12T12:33:45 Z Ahmad_Hasan Table Tennis (info1cup20_tabletennis) C++17
35 / 100
3000 ms 1048580 KB
#include <bits/stdc++.h>
#define int long long
/**
     ||||||||||       |||||     |||||    ||||||||||
    |||||||||||||     |||||     |||||  |||||
   ||||     ||||||    |||||     |||||  |||||
  |||||||||||||||||   |||||||||||||||    ||||||||||
 |||||||||||||||||||  |||||||||||||||           |||||
 |||||         |||||  |||||     |||||           |||||
 |||||         |||||  |||||     |||||    ||||||||||
AHMED;HASSAN;SAEED;
*/

using namespace std;
map<int,int>mp;
vector<int>v;
vector<vector<pair<int,pair<int,int> > > >dp;
int n,k;
int slv(int l,int r){
    ///cout<<l<<' '<<r<<'\n';
    if(dp[l][r].first!=-1)
        return dp[l][r].first;
    int ret=0;
    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;
    dp=vector<vector<pair<int,pair<int,int>> > >(n+5,vector<pair<int,pair<int,int>> >(n+5,{-1,{-1,-1}}));
    for(int i=0;i<n;i++){
        for(int j=i;j<n;j++){
            int ret=slv(i,j);
            if(ret>ans){
                ans=ret;
                l=i,r=j;
            }


        }

    }
    vector<int>v2(n-k);
    int cnt=0;

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


    return 0;
}

Compilation message

tabletennis.cpp: In function 'int32_t main()':
tabletennis.cpp:72:35: warning: 'r' may be used uninitialized in this function [-Wmaybe-uninitialized]
   72 |         v2[cnt]=v[l],v2[cnt+1]=v[r];
      |                                   ^
tabletennis.cpp:72:20: warning: 'l' may be used uninitialized in this function [-Wmaybe-uninitialized]
   72 |         v2[cnt]=v[l],v2[cnt+1]=v[r];
      |                    ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1288 ms 101684 KB Output is correct
2 Correct 1273 ms 95852 KB Output is correct
3 Correct 1275 ms 102624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 661 ms 1048580 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 631 ms 1048580 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 229 ms 23276 KB Output is correct
2 Correct 283 ms 22636 KB Output is correct
3 Correct 526 ms 34924 KB Output is correct
4 Correct 350 ms 33388 KB Output is correct
5 Correct 533 ms 34896 KB Output is correct
# 결과 실행 시간 메모리 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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 620 KB Output is correct
2 Execution timed out 3055 ms 109728 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 620 KB Output is correct
2 Runtime error 622 ms 1048580 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3063 ms 167672 KB Time limit exceeded
2 Halted 0 ms 0 KB -