Submission #5338305


Source Code Expand

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
using namespace std;
template <class T, class U> inline void chmax(T & a, U const & b) { a = max<T>(a, b); }
template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

int solve(const string & s, const string & t) {
    int n = s.length();
    vector<vector<int> > dp = vectors(n + 1, n + 1, 0);
    REP (i, n + 1) {
        REP (j, n + 1) {
            if (i - 1 >= 0) chmax(dp[i][j], dp[i - 1][j]);
            if (j - 1 >= 0) chmax(dp[i][j], dp[i][j - 1]);
            if (i - 1 >= 0 and j - 1 >= 0) chmax(dp[i][j], dp[i - 1][j - 1] + (s[i - 1] == t[j - 1]));
        }
    }
    return dp[n][n] + 1;
}

int main() {
    string s, t; cin >> s >> t;
    cout << solve(s, t) << endl;
    return 0;
}

Submission Info

Submission Time
Task A - わたのはら
User kimiyuki
Language C++14 (GCC 5.4.1)
Score 300
Code Size 989 Byte
Status AC
Exec Time 159 ms
Memory 98176 KiB

Judge Result

Set Name Sample Subtask1
Score / Max Score 0 / 0 300 / 300
Status
AC × 2
AC × 16
Set Name Test Cases
Sample sample_1.txt, sample_2.txt
Subtask1 sample_1.txt, sample_2.txt, small_1.txt, small_2.txt, small_3.txt, small_4.txt, small_5.txt, small_6.txt, small_7.txt, large_1.txt, large_2.txt, large_3.txt, large_4.txt, large_5.txt, large_6.txt, large_7.txt
Case Name Status Exec Time Memory
large_1.txt AC 36 ms 20992 KiB
large_2.txt AC 52 ms 30976 KiB
large_3.txt AC 59 ms 35584 KiB
large_4.txt AC 80 ms 48256 KiB
large_5.txt AC 47 ms 27776 KiB
large_6.txt AC 108 ms 66048 KiB
large_7.txt AC 159 ms 98176 KiB
sample_1.txt AC 1 ms 256 KiB
sample_2.txt AC 1 ms 256 KiB
small_1.txt AC 1 ms 384 KiB
small_2.txt AC 3 ms 1280 KiB
small_3.txt AC 3 ms 1280 KiB
small_4.txt AC 5 ms 2432 KiB
small_5.txt AC 2 ms 640 KiB
small_6.txt AC 2 ms 768 KiB
small_7.txt AC 2 ms 512 KiB