Submission #872686

# Submission time Handle Problem Language Result Execution time Memory
872686 2023-11-13T14:47:20 Z RedGrey1993 Round words (IZhO13_rowords) C++17
32 / 100
57 ms 11292 KB
#include <bits/stdc++.h>
 
using namespace std;
 
template <typename T1, typename T2> istream &operator>>(istream &is, const pair<T1, T2> &pa) { is >> pa.first >> pa.second; return is; }
template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (auto &v : vec) is >> v; return is; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa) { os << "(" << pa.first << "," << pa.second << ")"; return os; }
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template <typename T> ostream &operator<<(ostream &os, const deque<T> &vec) { os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template <typename T> ostream &operator<<(ostream &os, const set<T> &vec) { os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template <typename T> ostream &operator<<(ostream &os, const multiset<T> &vec) { os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template <typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec) { os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec) { os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template <typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp) { os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template <typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp) { os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template <typename T> void resize_array(vector<T> &vec, int len) { vec.resize(len); }
template <typename T, typename... Args> void resize_array(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) resize_array(v, args...); }
template <typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template <typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }
 
template <unsigned int MOD>
class ModInt {
public:
    ModInt(unsigned long long _v = 0) { set_v((_v % MOD + MOD)); }
    explicit operator bool() const { return val != 0; }
    ModInt operator-() const { return ModInt() - *this; }
    ModInt operator+(const ModInt &r) const { return ModInt().set_v(val + r.val); }
    ModInt operator-(const ModInt &r) const { return ModInt().set_v(val + MOD - r.val); }
    ModInt operator*(const ModInt &r) const { return ModInt().set_v((unsigned int)((unsigned long long)(val)*r.val % MOD)); }
    ModInt operator/(const ModInt &r) const { return *this * r.inv(); }
    ModInt &operator+=(const ModInt &r) { return *this = *this + r; }
    ModInt &operator-=(const ModInt &r) { return *this = *this - r; }
    ModInt &operator*=(const ModInt &r) { return *this = *this * r; }
    ModInt &operator/=(const ModInt &r) { return *this = *this / r; }
    // ModInt &operator=(unsigned long long _v) { set_v((_v % MOD + MOD)); return *this; }
    unsigned int operator=(unsigned long long _v) { set_v((_v % MOD + MOD)); return val; }
    bool operator==(const ModInt &r) const { return val == r.val; }
    bool operator!=(const ModInt &r) const { return val != r.val; }
    ModInt pow(long long n) const {
        ModInt x = *this, r = 1;
        while (n) {
            if (n & 1)
                r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    ModInt inv() const { return pow(MOD - 2); }
    unsigned int get_val() { return val; }
    friend ostream &operator<<(ostream &os, const ModInt &r) { return os << r.val; }
    friend istream &operator>>(istream &is, ModInt &r) { return is >> r.val; }
private:
    unsigned int val;
    ModInt &set_v(unsigned int _v) {
        val = (_v < MOD) ? _v : _v - MOD;
        return *this;
    }
};
constexpr unsigned int mod = 1e9+7;
using Mint = ModInt<mod>;
 
#define rep(i, a, n) for (int i = a; i < (n); i++)
#define per(i, a, n) for (int i = (n)-1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef double db;
#if DEBUG
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;
#else
#define dbg(x)
#endif
 
using Mint2 = ModInt<mod-1>;
class Solution {
    struct Line {
        long long m, c;
        long long Eval(long long x) { return m * x + c; }
        long double IntersectX(Line l) { return (long double)(c - l.c) / (l.m - m); }
    };

public:
    void Solve() {
        string s,t;
        while(cin>>s>>t) {
            s += s;
            // dbg(s);
            int n = sz(s), m=sz(t);

            auto get_lcs = [&] () {
                vector<vi> dp(n+1, vi(m+1));
                rep(i,0,n) {
                    rep(j,0,m) {
                        if (s[i] == t[j]) dp[i+1][j+1] = dp[i][j] + 1;
                        else dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j]);
                    }
                }

                // dbg(dp[n/2][m]);

                int ans = 0;
                rep(last, n/2, n) {
                    int x = last, y = m;
                    int cnt = 0;
                    while(x > last - n/2 && y && dp[x][y]) {
                        if (s[x-1] == t[y-1]) {
                            // dbg(mp(last,s));
                            // dbg(mp(x,s[x-1]));
                            // dbg(mp(y,t[y-1]));
                            x--; y--;
                            cnt++;
                        } else if (dp[x][y] == dp[x][y-1]) y--;
                        else x--;
                    }
                    // dbg(mp(x,y));
                    // dbg(mp(last, cnt));
                    ans = max(ans, cnt);
                }
                // dbg(ans);
                return ans;
            };

            int ans = get_lcs();
            reverse(all(s));
            ans = max(ans, get_lcs());
            cout << ans << endl;
        }
    }
private:
};
 
// #define USACO 1
void set_io(const string &name = "") {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#if FILE_IO || USACO
    if (!name.empty()) {
        freopen((name + ".in").c_str(), "r", stdin);
        freopen((name + ".out").c_str(), "w", stdout);
    }
#endif
}

int main() {
#if USACO
    set_io("time");
#else
    set_io("input");
#endif
    Solution().Solve();

    return 0;
}


# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 1 ms 348 KB Output isn't correct
6 Correct 6 ms 1200 KB Output is correct
7 Correct 18 ms 8364 KB Output is correct
8 Incorrect 18 ms 8284 KB Output isn't correct
9 Incorrect 23 ms 8372 KB Output isn't correct
10 Incorrect 29 ms 8284 KB Output isn't correct
11 Incorrect 35 ms 9160 KB Output isn't correct
12 Correct 18 ms 10636 KB Output is correct
13 Incorrect 35 ms 10588 KB Output isn't correct
14 Incorrect 36 ms 9580 KB Output isn't correct
15 Incorrect 44 ms 11292 KB Output isn't correct
16 Incorrect 24 ms 9168 KB Output isn't correct
17 Incorrect 37 ms 7004 KB Output isn't correct
18 Correct 50 ms 10824 KB Output is correct
19 Incorrect 31 ms 8284 KB Output isn't correct
20 Incorrect 34 ms 9660 KB Output isn't correct
21 Incorrect 32 ms 2616 KB Output isn't correct
22 Incorrect 40 ms 4152 KB Output isn't correct
23 Incorrect 43 ms 5540 KB Output isn't correct
24 Incorrect 49 ms 5844 KB Output isn't correct
25 Incorrect 57 ms 7592 KB Output isn't correct