結果

問題 No.225 文字列変更(medium)
ユーザー cielciel
提出日時 2015-06-13 02:27:12
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 36 ms / 5,000 ms
コード長 1,357 bytes
コンパイル時間 611 ms
コンパイル使用メモリ 78,288 KB
実行使用メモリ 18,088 KB
最終ジャッジ日時 2023-08-25 22:47:26
合計ジャッジ時間 1,789 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
8,980 KB
testcase_01 AC 23 ms
13,168 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 35 ms
17,200 KB
testcase_13 AC 35 ms
18,088 KB
testcase_14 AC 34 ms
17,632 KB
testcase_15 AC 36 ms
17,160 KB
testcase_16 AC 33 ms
17,352 KB
testcase_17 AC 35 ms
17,084 KB
testcase_18 AC 33 ms
16,788 KB
testcase_19 AC 33 ms
17,072 KB
testcase_20 AC 33 ms
16,252 KB
testcase_21 AC 33 ms
17,140 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//AOJ DPL_1_Eとかぶってませんか.
//ところでこの問題,発展問題があるのですがご存知でしょうか.
//発展問題も解けるコードを今日出すことはやめておきます.

#include <vector>
#include <algorithm>
#include <string>
#include <iostream>
#include <tuple>
using namespace std;
typedef vector<int> vi;
typedef tuple<int,int,int> tiii;
typedef vector<tiii> vtiii;
void alignment(string &x, string &y){
    vector<vi>a(x.length()+1,vi(y.length()+1));
    vector<vtiii>back(x.length()+1,vtiii(y.length()+1));
    string tx,ty;
    int i,j,k;
    for(i=1;i<a.size();i++){a[i][0]=a[i-1][0]-1;back[i][0]=make_tuple(i-1,0,0);}
    for(j=1;j<a[0].size();j++){a[0][j]=a[0][j-1]-1;back[0][j]=make_tuple(0,j-1,1);}
    for(i=1;i<a.size();i++){
        for(j=1;j<a[0].size();j++){
            vi Z{x[i-1]==y[j-1]?a[i-1][j-1]:(a[i-1][j-1]-1),a[i-1][j]-1,a[i][j-1]-1};
            vi::iterator z=max_element(Z.begin(),Z.end());
            a[i][j]=*z;
            switch(z-Z.begin()){
                case 0: back[i][j]=make_tuple(i-1,j-1,2);break;
                case 1: back[i][j]=make_tuple(i-1,j  ,0);break;
                case 2: back[i][j]=make_tuple(i  ,j-1,1);break;
            }
        }
    }
    cout<<-a[x.length()][y.length()]<<endl;
}
int main(){
    string s,t;
    cin>>s>>s>>s>>t;
    alignment(s,t);
}
0