답안 #340344

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
340344 2020-12-27T13:11:34 Z beksultan04 원형 문자열 (IZhO13_rowords) C++14
24 / 100
2000 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 = 3e5+12,INF=100500;
int q[N],n,m;
int dp[2001][2001];

inline void 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);
            }
        }
    }
}

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

main(){
    string a,b;
    string ss,s;
    cin>>ss>>s;
    n = ss.size();m = s.size();
    int i,j;
    for (i=0;i<n;++i){
        a.pb(ss[i]);
    }
    for (i=0;i<m;++i){
        b.pb(s[i]);
    }
    fun(a,b);
    int ans = dp[n][m];
    for (i=0;i<n;++i){
        rev(a);
        fun(a,b);
        ans = max(ans,dp[n][m]);
    }
    reverse(all(b));
    for (i=0;i<n;++i){
        rev(a);fun(a,b);
        ans = max(ans,dp[n][m]);
    }


    cout <<ans;
}

Compilation message

rowords.cpp:41:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   41 | main(){
      |      ^
rowords.cpp: In function 'int main()':
rowords.cpp:46:11: warning: unused variable 'j' [-Wunused-variable]
   46 |     int i,j;
      |           ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 825 ms 4844 KB Output is correct
7 Execution timed out 2083 ms 8172 KB Time limit exceeded
8 Execution timed out 2076 ms 8172 KB Time limit exceeded
9 Execution timed out 2099 ms 8172 KB Time limit exceeded
10 Execution timed out 2072 ms 8172 KB Time limit exceeded
11 Execution timed out 2095 ms 8940 KB Time limit exceeded
12 Execution timed out 2055 ms 9708 KB Time limit exceeded
13 Execution timed out 2084 ms 9708 KB Time limit exceeded
14 Execution timed out 2058 ms 9196 KB Time limit exceeded
15 Execution timed out 2089 ms 9980 KB Time limit exceeded
16 Execution timed out 2045 ms 8812 KB Time limit exceeded
17 Execution timed out 2099 ms 9324 KB Time limit exceeded
18 Execution timed out 2086 ms 11500 KB Time limit exceeded
19 Execution timed out 2100 ms 8172 KB Time limit exceeded
20 Execution timed out 2081 ms 10220 KB Time limit exceeded
21 Execution timed out 2051 ms 8172 KB Time limit exceeded
22 Execution timed out 2096 ms 9324 KB Time limit exceeded
23 Execution timed out 2088 ms 9964 KB Time limit exceeded
24 Execution timed out 2090 ms 10604 KB Time limit exceeded
25 Execution timed out 2094 ms 11884 KB Time limit exceeded