結果

問題 No.225 文字列変更(medium)
ユーザー tubo28tubo28
提出日時 2015-06-17 18:45:47
言語 C++11
(gcc 11.4.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 612 bytes
コンパイル時間 281 ms
コンパイル使用メモリ 52,164 KB
最終ジャッジ日時 2024-04-27 02:07:59
合計ジャッジ時間 568 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp:4:31: error: ‘string’ does not name a type; did you mean ‘stdin’?
    4 | int LevenshteinDistance(const string& str1, const string& str2){
      |                               ^~~~~~
      |                               stdin
main.cpp:4:51: error: ‘string’ does not name a type; did you mean ‘stdin’?
    4 | int LevenshteinDistance(const string& str1, const string& str2){
      |                                                   ^~~~~~
      |                                                   stdin
main.cpp: In function ‘int LevenshteinDistance(const int&, const int&)’:
main.cpp:6:19: error: request for member ‘size’ in ‘str1’, which is of non-class type ‘const int’
    6 |     int l1 = str1.size(), l2 = str2.size();
      |                   ^~~~
main.cpp:8:11: error: ‘l2’ was not declared in this scope; did you mean ‘l1’?
    8 |     rep(i,l2+1) dp[0][i] = i;
      |           ^~
main.cpp:3:32: note: in definition of macro ‘rep’
    3 | #define rep(i,b) for(int i=0;i<b;i++)
      |                                ^
main.cpp:9:20: error: ‘l2’ was not declared in this scope; did you mean ‘l1’?
    9 |     rep(i,l1)rep(j,l2){
      |                    ^~
main.cpp:3:32: note: in definition of macro ‘rep’
    3 | #define rep(i,b) for(int i=0;i<b;i++)
      |                                ^
main.cpp:11:58: error: invalid types ‘const int[int]’ for array subscript
   11 |         dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j] + (str1[i]!=str2[j]));
      |                                                          ^
main.cpp:11:67: error: invalid types ‘const int[int]’ for array subscript
   11 |         dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j] + (str1[i]!=str2[j]));
      |                                                                   ^
main.cpp:13:19: error: ‘l2’ was not declared in this scope; did you mean ‘l1’?
   13 |     return dp[l1][l2];
      |                   ^~
      |          

ソースコード

diff #

#include <algorithm>
using namespace std;
#define rep(i,b) for(int i=0;i<b;i++)
int LevenshteinDistance(const string& str1, const string& str2){
    static int dp[2048][2048]; // 16 MB
    int l1 = str1.size(), l2 = str2.size();
    rep(i,l1+1) dp[i][0] = i;
    rep(i,l2+1) dp[0][i] = i;
    rep(i,l1)rep(j,l2){
        dp[i+1][j+1] = min(dp[i][j+1], dp[i+1][j]) + 1;
        dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j] + (str1[i]!=str2[j]));
    }
    return dp[l1][l2];
}

#include <iostream>
int main(){
    int n,m;
    string s,t;
    cin >> n >> m >> s >> t;
    cout << LevenshteinDistance(s,t) << endl;
}
0