Submission #10405612
Source Code Expand
#include <bits/stdc++.h> using namespace std; #define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define watch(x) cout << (#x) << " is " << (x) << endl #define f(t) for(ll i =0;i<t;i++) #define bs(a,x) binary_search(a.begin(),a.end(),x) #define ll long long int #define ul unsigned long int #define ld long double #define umpi unordered_map<int,int> #define umpl unordered_map<ll,ll> #define vi vector<int> #define vl vector<ll> #define pb push_back #define mod 1000000007 #define N 10000000 #define all(a) a.begin(),a.end() #define point pair<ll,ll> const int inf = 1000000007; const ll linf = 1ll * inf * inf; const ll MAXIMUM =1000005; inline ll mul(ll a, ll b){ return (a * 1ll * b) % mod; } inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; } inline ll add(ll a, ll b){ ll c = a + b; if(c > mod) c -= mod; return c; } inline ll max(ll a, ll b){return a>b?a:b;} inline ll min(ll a, ll b){return a<b?a:b;} struct hash_pair { template <class T1, class T2> size_t operator()(const pair<T1, T2>& p) const { auto hash1 = hash<T1>{}(p.first); auto hash2 = hash<T2>{}(p.second); return hash1 ^ hash2; } }; string to_str(char a) { string s(1,a); return s; } int main() { fio; string s,t;cin>>s>>t; pair<ll,string> dp[s.length()+1][t.length()+1]; for(int i=0;i<=s.length();i++) { for(int j=0;j<=t.length();j++) { dp[i][j].first=0; } } for(int i=1;i<=s.length();i++) { for(int j=1;j<=t.length();j++) { if(s[i-1]==t[j-1]) { if((dp[i-1][j-1].first+1)>=dp[i][j].first) { dp[i][j].first=dp[i-1][j-1].first+1; dp[i][j].second=dp[i-1][j-1].second+to_str(s[i-1]); } } if(dp[i-1][j].first>=dp[i][j].first) { dp[i][j].first=dp[i-1][j].first; dp[i][j].second=dp[i-1][j].second; } if(dp[i][j-1].first>=dp[i][j].first) { dp[i][j].first=dp[i][j-1].first; dp[i][j].second=dp[i][j-1].second; } } } ll ans=-1; string temp; for(int i=0;i<=s.length();i++) { for(int j=0;j<=t.length();j++) { if(dp[i][j].first>ans) { ans=dp[i][j].first; temp=dp[i][j].second; // cout<<dp[i][j].first<<" "<<dp[i][j].second<<" "; } // cout<<endl; } } // cout<<ans<<"\n"; cout<<temp<<"\n"; }
Submission Info
Submission Time | |
---|---|
Task | F - LCS |
User | lowercase_guy |
Language | C++14 (GCC 5.4.1) |
Score | 100 |
Code Size | 2386 Byte |
Status | AC |
Exec Time | 1917 ms |
Memory | 909184 KB |
Judge Result
Set Name | All | ||
---|---|---|---|
Score / Max Score | 100 / 100 | ||
Status |
|
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 | 1 ms | 256 KB |
0_01 | AC | 1 ms | 256 KB |
0_02 | AC | 1 ms | 256 KB |
0_03 | AC | 1 ms | 256 KB |
1_00 | AC | 1 ms | 256 KB |
1_01 | AC | 1 ms | 256 KB |
1_02 | AC | 1917 ms | 145536 KB |
1_03 | AC | 164 ms | 140928 KB |
1_04 | AC | 163 ms | 140928 KB |
1_05 | AC | 164 ms | 140928 KB |
1_06 | AC | 1854 ms | 144768 KB |
1_07 | AC | 1753 ms | 909184 KB |
1_08 | AC | 1366 ms | 808192 KB |
1_09 | AC | 1157 ms | 719360 KB |
1_10 | AC | 853 ms | 551552 KB |
1_11 | AC | 659 ms | 433280 KB |
1_12 | AC | 515 ms | 332160 KB |
1_13 | AC | 363 ms | 237056 KB |