답안 #340347

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
340347 2020-12-27T13:15:04 Z beksultan04 원형 문자열 (IZhO13_rowords) C++14
16 / 100
26 ms 11884 KB
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define pii pair<int,int>
#define OK puts("OK");
#define NO puts("NO");
#define YES puts("YES");
#define fr first
#define sc second
#define ret return
#define scan1(a) scanf("%d",&a);
#define scan2(a,b) scanf("%d %d",&a, &b);
#define scan3(a,b,c) scanf("%d %d %d",&a,&b,&c);
#define all(s) s.begin(),s.end()
#define allr(s) s.rbegin(),s.rend()
#define pb push_back
#define sz(v) (int)v.size()
#define endi puts("");
#define eps 1e-12
const int N = 1e5+12,INF=1e9+7;
int dp[2001][2001];
main(){
    string a,b;
    int i,j,n,m;
    cin>>a>>b;
    n = a.size();m = b.size();
    for (i=1;i<=n;++i){
        for (j=1;j<=m;++j){
            dp[i][j] = max(dp[i][j-1],dp[i-1][j]);
            if (a[i-1]==b[j-1]){
                dp[i][j] = max(dp[i][j],dp[i-1][j-1]+1);
            }
        }
    }
    int ans = dp[n][m];
    for (i=0;i<n;++i){


        a.pb(a[0]);
        a.erase(a.begin());

        for (i=1;i<=n;++i){
            for (j=1;j<=m;++j){
                dp[i][j] = max(dp[i][j-1],dp[i-1][j]);
                if (a[i-1]==b[j-1]){
                    dp[i][j] = max(dp[i][j],dp[i-1][j-1]+1);
                }
            }
        }
        ans = max(ans,dp[n][m]);
    }
    reverse(all(b));
    for (i=0;i<n;++i){


        a.pb(a[0]);
        a.erase(a.begin());

        for (i=1;i<=n;++i){
            for (j=1;j<=m;++j){
                dp[i][j] = max(dp[i][j-1],dp[i-1][j]);
                if (a[i-1]==b[j-1]){
                    dp[i][j] = max(dp[i][j],dp[i-1][j-1]+1);
                }
            }
        }

        ans = max(ans,dp[n][m]);
    }


    cout <<ans;
}

Compilation message

rowords.cpp:22:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   22 | main(){
      |      ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Incorrect 1 ms 364 KB Output isn't correct
4 Correct 1 ms 492 KB Output is correct
5 Incorrect 1 ms 492 KB Output isn't correct
6 Correct 5 ms 4716 KB Output is correct
7 Correct 18 ms 8172 KB Output is correct
8 Incorrect 19 ms 8192 KB Output isn't correct
9 Incorrect 18 ms 8172 KB Output isn't correct
10 Incorrect 18 ms 8172 KB Output isn't correct
11 Incorrect 19 ms 8940 KB Output isn't correct
12 Correct 26 ms 9708 KB Output is correct
13 Incorrect 22 ms 9708 KB Output isn't correct
14 Incorrect 20 ms 9196 KB Output isn't correct
15 Incorrect 23 ms 9964 KB Output isn't correct
16 Incorrect 21 ms 8812 KB Output isn't correct
17 Incorrect 16 ms 9324 KB Output isn't correct
18 Incorrect 23 ms 11500 KB Output isn't correct
19 Incorrect 17 ms 8172 KB Output isn't correct
20 Incorrect 22 ms 10220 KB Output isn't correct
21 Incorrect 10 ms 8172 KB Output isn't correct
22 Incorrect 13 ms 9324 KB Output isn't correct
23 Incorrect 15 ms 9964 KB Output isn't correct
24 Incorrect 16 ms 10476 KB Output isn't correct
25 Incorrect 21 ms 11884 KB Output isn't correct