제출 #884798

#제출 시각아이디문제언어결과실행 시간메모리
884798racoon23원형 문자열 (IZhO13_rowords)C++17
20 / 100
2096 ms14116 KiB
#include<bits/stdc++.h>
using namespace std;

#define endl '\n'
#define int long long
const int MOD = 1e9 + 7;
const int help = (1 << 11) - 1;
const int MAXN = 1e5;
int n;
vector<int>arr;
vector<int> adj[MAXN + 11];
int offSet = 1e5 + 1;
bool vis[MAXN + 12];

void dfs(int s) {
    cout << s << " ";
    for (auto child : adj[s]) {
        if (vis[child] == 0) {
            dfs(child);
        }
    }
    vis[s] = 1;
}


int ans(int i, int j, string &a, string &b, vector<vector<int>>&dp) {
    if (i >= a.size() | j >= b.size()) {
        return 0;
    }

    if (dp[i][j] != -1)return dp[i][j];

    if (a[i] == b[j]) {
        return ans(i + 1, j + 1, a, b, dp) + 1;
    }

    return dp[i][j] = max(ans(i, j + 1, a, b, dp), ans(i + 1, j, a, b, dp));
}

int LCS(string&a, string&b) {
    vector<vector<int>>dp(a.size(), vector<int>(b.size(), -1));
    return ans(0, 0, a, b, dp);
}


string left(int i, string &a) {
    string ret = "";
    // ret.push_back
    for (int j = i; j >= 0; j--)ret.push_back(a[j]);
    for (int j = a.size() - 1; j > i; j--)ret.push_back(a[j]);
    return ret;

}

string right(int i, string& a) {
    string ret = "";
    // ret.push_back
    for (int j = i; j < a.size(); j++)ret.push_back(a[j]);
    for (int j = 0; j < i; j++)ret.push_back(a[j]);
    return ret;
}

void solve() {
    string a, b;
    cin >> a >> b;
    int ans2 = 0;
    string l, r;
    for (int rot = 0; rot < a.size(); rot++) {
        l = left(rot, a);
        r = right(rot, a);
        ans2 = max(ans2, max(LCS(l, b), LCS(r, b)));
    }

    cout << ans2 << endl;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cout.tie(0);
    cin.tie(0);

    int tt = 1;
    //cin>>tt;
    while (tt--) {
        solve();
    }
}

컴파일 시 표준 에러 (stderr) 메시지

rowords.cpp: In function 'long long int ans(long long int, long long int, std::string&, std::string&, std::vector<std::vector<long long int> >&)':
rowords.cpp:27:11: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     if (i >= a.size() | j >= b.size()) {
      |         ~~^~~~~~~~~~~
rowords.cpp:27:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     if (i >= a.size() | j >= b.size()) {
      |                         ~~^~~~~~~~~~~
rowords.cpp:27:11: warning: suggest parentheses around comparison in operand of '|' [-Wparentheses]
   27 |     if (i >= a.size() | j >= b.size()) {
      |         ~~^~~~~~~~~~~
rowords.cpp: In function 'std::string right(long long int, std::string&)':
rowords.cpp:58:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |     for (int j = i; j < a.size(); j++)ret.push_back(a[j]);
      |                     ~~^~~~~~~~~~
rowords.cpp: In function 'void solve()':
rowords.cpp:68:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |     for (int rot = 0; rot < a.size(); rot++) {
      |                       ~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...