結果
問題 | No.225 文字列変更(medium) |
ユーザー | inu_hir0shi |
提出日時 | 2015-06-12 23:14:43 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,653 bytes |
コンパイル時間 | 1,043 ms |
コンパイル使用メモリ | 159,196 KB |
実行使用メモリ | 7,424 KB |
最終ジャッジ日時 | 2024-07-06 15:56:23 |
合計ジャッジ時間 | 1,754 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | AC | 3 ms
7,168 KB |
testcase_03 | AC | 4 ms
7,296 KB |
testcase_04 | AC | 4 ms
7,168 KB |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | AC | 3 ms
7,296 KB |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef pair<int,int> PII; typedef long long LL; typedef unsigned long long ULL; template<class T> inline bool amax (T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool amin (T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; } template<class T> ostream& operator << (ostream &os, const vector<T> &v) { os << "["; for (typename vector<T>::const_iterator it = v.begin(); it != v.end(); it++) { os << (it != v.begin() ? ", " : "") << *it; } os << "]"; return os; } template<class T> ostream& operator << (ostream &os, const set<T> &s) { os << "["; for (typename set<T>::const_iterator it = s.begin(); it != s.end(); it++) { os << (it != s.begin() ? ", " : "") << *it; } os << "]"; return os; } template<class Key, class Val> ostream& operator << (ostream &os, const map<Key, Val> &m) { os << "{"; for (typename map<Key, Val>::const_iterator it = m.begin(); it != m.end(); it++) { os << (it != m.begin() ? ", " : "") << it->first << ":" << it->second; } os << "}"; return os; } template<class T, class S> ostream& operator << (ostream &os, const pair<T, S> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; } template <class T> istream& operator >> (istream &is, vector<T> &v) { for (size_t i = 0; i < v.size(); i++) is >> v[i]; return is; } template <class Target, class Source> inline Target lexical_cast (const Source &s) { Target t; stringstream ss; ss << s; ss >> t; return t; } //> v < ^ (clock wise) int dx[] = {1,0,-1,0}; int dy[] = {0,1,0,-1}; const int INFI = 1<<28; const long long int INFL = 1LL<<60; const double INFD = 1e+300; const float INFF = 1e+100; const double EPS = 1e-8; const long long int MOD = 1000000007; int solve (); int main () { cout.setf(ios::fixed); cout.precision(10); ios_base::sync_with_stdio(false); solve(); return 0; } int solve () { int n1, n2; string s, t; cin >> n1 >> n2 >> s >> t; int dp[1011][1011] = {0}; for (int i = 0; i < s.size(); i++) { for (int j = 0; j < t.size(); j++) { if (s[i] == t[j]) dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j]+1); else { dp[i+1][j] = max(dp[i+1][j], dp[i][j]); dp[i][j+1] = max(dp[i][j+1], dp[i][j]); } } } int ans = t.size(); for (int i = 0; i < s.size(); i++) { for (int j = 0; j < t.size(); j++) { if (s[i] == t[j]) { int a = dp[i+1][j+1]; ans = min(ans, int(max(i-a, j-a)+max(s.size()-i, t.size()-j))); } } } cout << ans << endl; return 0; }