Submission #10405941


Source Code Expand

//*******Abhijit Burman***********//
//Jalpaiguri Government Engineering College//

#include<bits/stdc++.h>
using namespace std;
#define ll long long int

#define pb push_back
#define mk make_pair
#define MAXX (1000000000000000000+7)
#define fio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
string temp=" ";
ll dp[3010][3010];
string s,tt,ans="";
ll ii,jj;
//vector<ll> dp(100000100,110);
ll LCS(ll i, ll j)
{

    if(i>ii || j>jj)
    {
        return 0;
    }
   else
    {
        //cout<<i<<" "<<j<<endl;
        if(dp[i][j]!=-1)
        {
            //cout<<"Hello"<<i<<" "<<j<<endl;
            return dp[i][j];
        }
        else
        {

            if(s[i]==tt[j])
            {

                dp[i][j] = 1+LCS(i+1,j+1);
                return dp[i][j];
            }
            else
            {
                dp[i][j] = max(LCS(i+1,j),LCS(i,j+1));
                return dp[i][j];
            }

        }
    }

}

int main( )
{
    fio;

	cin>>s>>tt;
	 ii=s.size()-1;
	 jj=tt.size()-1;
	 memset(dp,-1,sizeof(dp));

//	ll jj;
    //cout<<v.size()<<endl;
    LCS(0,0);
    //ll maxi = 0;
    ll i=0,j=0;
    while(i<=ii && j<=jj)
    {
        if(s[i]==tt[j])
        {
            ans+=s[i];
            i++;
            j++;
        }
        else
        {
            if(dp[i][j] == dp[i+1][j])
            {
                i++;
            }
            else
            {
                j++;
            }
        }
        //cout<<ans<<endl;
    }
    cout<<ans<<endl;
    //cout<<endl;

    return 0;
}


Submission Info

Submission Time
Task F - LCS
User chromium6012
Language C++14 (GCC 5.4.1)
Score 100
Code Size 1645 Byte
Status AC
Exec Time 154 ms
Memory 71296 KB

Judge Result

Set Name All
Score / Max Score 100 / 100
Status
AC × 18
Set Name Test Cases
All 0_00, 0_01, 0_02, 0_03, 1_00, 1_01, 1_02, 1_03, 1_04, 1_05, 1_06, 1_07, 1_08, 1_09, 1_10, 1_11, 1_12, 1_13
Case Name Status Exec Time Memory
0_00 AC 19 ms 71040 KB
0_01 AC 19 ms 71040 KB
0_02 AC 19 ms 71040 KB
0_03 AC 19 ms 71040 KB
1_00 AC 19 ms 71040 KB
1_01 AC 19 ms 71040 KB
1_02 AC 18 ms 71168 KB
1_03 AC 153 ms 71296 KB
1_04 AC 154 ms 71296 KB
1_05 AC 154 ms 71296 KB
1_06 AC 18 ms 71168 KB
1_07 AC 77 ms 71168 KB
1_08 AC 105 ms 71168 KB
1_09 AC 117 ms 71168 KB
1_10 AC 125 ms 71168 KB
1_11 AC 132 ms 71168 KB
1_12 AC 133 ms 71168 KB
1_13 AC 142 ms 71168 KB