Untitled
unknown
plain_text
7 months ago
2.2 kB
0
Indexable
Never
#include <bits/stdc++.h> #define int long long using namespace std; int M, N; string s1, s2, s3; vector<vector<int>> dp; int shortest_uncommon(string& s, string& t, int i, int j) { if(i == M) return LLONG_MAX; if(j == N) return 1; if(dp[i][j] != -1) return dp[i][j]; int foundIdx = -1; for(int k = j; k < N; k++) { if(t[k] == s[i]) { foundIdx = k; break; } } if(foundIdx == -1) { return 1; } int ans1 = shortest_uncommon(s, t, i + 1, foundIdx + 1); if(ans1 != LLONG_MAX) ans1++; int ans2 = shortest_uncommon(s, t, i + 1, j); return dp[i][j] = min(ans1, ans2); } int longest_uncommon(string& s, string& t, int i, int j) { if(i == M) return -1; if(j == N) return M - i; if(dp[i][j] != -1) return dp[i][j]; int foundIdx = -1; for(int k = j; k < N; k++) { if(t[k] == s[i]) { foundIdx = k; break; } } int ans1 = -1, ans2 = -1, ans3 = -1; if(foundIdx == -1) { ans3 = M - i; } else { ans1 = longest_uncommon(s, t, i + 1, foundIdx + 1); if(ans1 != -1) ans1++; ans2 = longest_uncommon(s, t, i + 1, j + 1); } return dp[i][j] = max(max(ans1, ans2), ans3); } void solve_p1() { vector<int> v; cout << v[100]; } void solve_p2() { vector<int> v; cout << v[100]; N = s2.length(); dp.assign(s1.length(), vector<int>(s2.length(), -1)); int ans = shortest_uncommon(s1, s2, 0, 0); if(ans == LLONG_MAX) cout << -1; else cout << ans; } void solve_p3() { N = s3.length(); dp.assign(s1.length(), vector<int>(s3.length(), -1)); int ans = longest_uncommon(s1, s3, 0, 0); cout << ans; } signed main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ cin >> s1 >> s2 >> s3; M = s1.length(); int n; cin >> n; for(int i = 0; i < n; i++) { int option; cin >> option; if(option == 0) solve_p1(); else if(option == 1) solve_p2(); else solve_p3(); cout << ' '; } return 0; }
Leave a Comment