/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Time Exceeded ≥1100ms ≥788.0 KiB

Code

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define bug(a) cout<< #a << " : " << a <<endl;
#define bug2(a, b) cout<< #a << " : " << a  << " " << #b << " : " << b << endl;
string s;
const int N = 105;
string dp[N][N];

string f(int i, int k){
    if(k == 0)return "";
    if(i == s.size())return "$";
    if(dp[i][k] != "$")return dp[i][k];

    string tm = s[i] + f(i+1, k);
    if(tm.back() == '$')tm = "";
    tm = max(tm,f(i+1,k-1));
    return dp[i][k] = tm;
}
void solve(int cs){
    int n,k; cin >> n >> k;
    cin >> s;
    if(k == n){
        cout << 0 << '\n';
        return;
    }
    if(k == 0){
        cout << s << '\n';
        return;
    }
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++)dp[i][j] = "$";
    }
    cout << f(0,k) << '\n';
    
}


int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    cout.tie(0);

    int tc = 1;
    cin >> tc;

    for(int cs = 1; cs <= tc; cs++){
        solve(cs);
    }
}

Information

Submit By
Type
Submission
Problem
P1006 Remove K Digits
Contest
Sylhet ICPC 2024 Collaborative Challenge: Episode 2
Language
C++17 (G++ 13.2.0)
Submit At
2024-10-30 09:26:43
Judged At
2024-10-30 09:26:43
Judged By
Score
0
Total Time
≥1100ms
Peak Memory
≥788.0 KiB