結果

問題 No.225 文字列変更(medium)
ユーザー 0w10w1
提出日時 2016-12-05 16:35:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 13 ms / 5,000 ms
コード長 1,412 bytes
コンパイル時間 1,914 ms
コンパイル使用メモリ 164,760 KB
実行使用メモリ 7,524 KB
最終ジャッジ日時 2023-08-26 00:43:25
合計ジャッジ時間 2,773 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
7,284 KB
testcase_01 AC 8 ms
7,304 KB
testcase_02 AC 4 ms
7,232 KB
testcase_03 AC 5 ms
7,388 KB
testcase_04 AC 5 ms
7,432 KB
testcase_05 AC 5 ms
7,348 KB
testcase_06 AC 5 ms
7,240 KB
testcase_07 AC 4 ms
7,392 KB
testcase_08 AC 5 ms
7,504 KB
testcase_09 AC 5 ms
7,240 KB
testcase_10 AC 5 ms
7,300 KB
testcase_11 AC 4 ms
7,400 KB
testcase_12 AC 12 ms
7,228 KB
testcase_13 AC 10 ms
7,232 KB
testcase_14 AC 11 ms
7,244 KB
testcase_15 AC 13 ms
7,236 KB
testcase_16 AC 11 ms
7,292 KB
testcase_17 AC 12 ms
7,300 KB
testcase_18 AC 13 ms
7,524 KB
testcase_19 AC 11 ms
7,216 KB
testcase_20 AC 12 ms
7,244 KB
testcase_21 AC 11 ms
7,224 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair< int, int > pii;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< ll > vl;
typedef vector< vl > vvl;
typedef vector< pii > vp;
typedef vector< vp > vvp;
typedef vector< string > vs;
typedef vector< double > vd;
typedef vector< vd > vvd;

template< class T1, class T2 >
int upmin( T1 &x, T2 v ){
  if( x > v ){
    x = v;
    return 1;
  }
  return 0;
}

template< class T1, class T2 >
int upmax( T1 &x, T2 v ){
  if( x < v ){
    x = v;
    return 1;
  }
  return 0;
}

const int INF = 0x3f3f3f3f;

int N, M;
string S;
string T;

void init(){
  cin >> N >> M;
  cin >> S;
  cin >> T;
}

int dp[ 1000 + 1 ][ 1000 + 1 ];

void preprocess(){
  memset( dp, INF, sizeof( dp ) );
  dp[ 0 ][ 0 ] = 0;
  for( int i = 0; i <= N; ++i )
    for( int j = 0; j <= M; ++j )
      if( dp[ i ][ j ] < INF ){
        if( i < N and j < M and S[ i ] == T[ j ] )
          upmin( dp[ i + 1 ][ j + 1 ], dp[ i ][ j ] );
        if( i + 1 <= N and j + 1 <= M )
          upmin( dp[ i + 1 ][ j + 1 ], dp[ i ][ j ] + 1 );
        if( i + 1 <= N )
          upmin( dp[ i + 1 ][ j ], dp[ i ][ j ] + 1 );
        if( j + 1 <= M )
          upmin( dp[ i ][ j + 1 ], dp[ i ][ j ] + 1 );
      }
}

void solve(){
  cout << dp[ N ][ M ] << endl;
}

signed main(){
  ios::sync_with_stdio( 0 );
  init();
  preprocess();
  solve();
  return 0;
}
0