답안 #339776

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
339776 2020-12-26T07:48:26 Z beksultan04 원형 문자열 (IZhO13_rowords) C++14
16 / 100
2000 ms 16492 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("%lld",&a);
#define scan2(a,b) scanf("%lld %lld",&a, &b);
#define scan3(a,b,c) scanf("%lld %lld %lld",&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 = 3e5+12,INF=100500;
int q[N],n,m;
int dp[2001][2001];

int fun(string &a,string &b){

    int i,j;
    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);
            }
        }
    }
    ret dp[n][m];
}

void rev(string &a){
    a.pb(a[0]);
    a.erase(a.begin());
}

main(){
    string a,b;
    cin>>a>>b;
    n = a.size();m = b.size();
    int ans = fun(a,b),i,j;
    for (i=0;i<n;++i){
            rev(a);
        for (j=0;j<m;++j){
            rev(b);
            ans = max(ans,fun(a,b));
        }
    }


    cout <<ans;
}

Compilation message

rowords.cpp:43:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   43 | main(){
      |      ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 24 ms 492 KB Output is correct
5 Correct 11 ms 492 KB Output is correct
6 Execution timed out 2023 ms 5100 KB Time limit exceeded
7 Execution timed out 2071 ms 12140 KB Time limit exceeded
8 Execution timed out 2079 ms 12140 KB Time limit exceeded
9 Execution timed out 2029 ms 12140 KB Time limit exceeded
10 Execution timed out 2088 ms 12140 KB Time limit exceeded
11 Execution timed out 2077 ms 13292 KB Time limit exceeded
12 Execution timed out 2078 ms 15212 KB Time limit exceeded
13 Execution timed out 2086 ms 15212 KB Time limit exceeded
14 Execution timed out 2086 ms 13932 KB Time limit exceeded
15 Execution timed out 2084 ms 15980 KB Time limit exceeded
16 Execution timed out 2081 ms 13292 KB Time limit exceeded
17 Execution timed out 2077 ms 12652 KB Time limit exceeded
18 Execution timed out 2056 ms 16492 KB Time limit exceeded
19 Execution timed out 2064 ms 12140 KB Time limit exceeded
20 Execution timed out 2086 ms 14828 KB Time limit exceeded
21 Execution timed out 2059 ms 9196 KB Time limit exceeded
22 Execution timed out 2076 ms 11116 KB Time limit exceeded
23 Execution timed out 2091 ms 12524 KB Time limit exceeded
24 Execution timed out 2084 ms 13164 KB Time limit exceeded
25 Execution timed out 2084 ms 15340 KB Time limit exceeded