Submission #5968450
Source Code Expand
#include <bits/stdc++.h>
#define N (long long)(1e9 + 7)
using namespace std;
long long n, m;
vector<long long> s, t;
long long dp[2005][2005] = {0};
long long solve();
int main() {
cin >> n >> m;
s.resize(n);
t.resize(m);
for(int i = 0; i < n; ++i) cin >> s[i];
for(int i = 0; i < m; ++i) cin >> t[i];
cout << solve() << endl;
return 0;
}
long long solve() {
dp[0][0] = 1;
for(int i = 0; i <= n; ++i) dp[i][0] = 1;
for(int i = 0; i <= m; ++i) dp[0][i] = 1;
for(int i = 0; i < n; ++i)
for(int j = 0; j < m; ++j) {
dp[i + 1][j + 1] =
(dp[i + 1][j] + dp[i][j + 1] - dp[i][j] + N) % N;
if(s[i] == t[j]) dp[i + 1][j + 1] += dp[i][j] % N;
dp[i + 1][j + 1] %= N;
}
return dp[n][m];
}
Submission Info
| Submission Time | |
|---|---|
| Task | E - Common Subsequence |
| User | m_tsubasa |
| Language | C++14 (GCC 5.4.1) |
| Score | 500 |
| Code Size | 774 Byte |
| Status | AC |
| Exec Time | 43 ms |
| Memory | 31616 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 500 / 500 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | s1.txt, s2.txt, s3.txt, s4.txt, s5.txt |
| All | 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, s1.txt, s2.txt, s3.txt, s4.txt, s5.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 01.txt | AC | 1 ms | 384 KiB |
| 02.txt | AC | 1 ms | 512 KiB |
| 03.txt | AC | 1 ms | 512 KiB |
| 04.txt | AC | 1 ms | 384 KiB |
| 05.txt | AC | 1 ms | 512 KiB |
| 06.txt | AC | 40 ms | 31488 KiB |
| 07.txt | AC | 41 ms | 31232 KiB |
| 08.txt | AC | 39 ms | 30976 KiB |
| 09.txt | AC | 39 ms | 31104 KiB |
| 10.txt | AC | 38 ms | 30976 KiB |
| 11.txt | AC | 40 ms | 30976 KiB |
| 12.txt | AC | 40 ms | 30976 KiB |
| 13.txt | AC | 40 ms | 30976 KiB |
| 14.txt | AC | 40 ms | 30976 KiB |
| 15.txt | AC | 39 ms | 30976 KiB |
| 16.txt | AC | 39 ms | 30976 KiB |
| 17.txt | AC | 41 ms | 31488 KiB |
| 18.txt | AC | 39 ms | 30976 KiB |
| 19.txt | AC | 39 ms | 30976 KiB |
| 20.txt | AC | 39 ms | 30976 KiB |
| 21.txt | AC | 43 ms | 31104 KiB |
| 22.txt | AC | 42 ms | 31360 KiB |
| 23.txt | AC | 4 ms | 9216 KiB |
| 24.txt | AC | 37 ms | 30976 KiB |
| 25.txt | AC | 9 ms | 29568 KiB |
| 26.txt | AC | 4 ms | 1664 KiB |
| 27.txt | AC | 41 ms | 31616 KiB |
| 28.txt | AC | 41 ms | 31616 KiB |
| s1.txt | AC | 1 ms | 256 KiB |
| s2.txt | AC | 1 ms | 256 KiB |
| s3.txt | AC | 1 ms | 256 KiB |
| s4.txt | AC | 1 ms | 256 KiB |
| s5.txt | AC | 1 ms | 384 KiB |