QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#398086 | #7990. 广播 | DopplerXD | WA | 0ms | 3668kb | C++20 | 1.0kb | 2024-04-24 22:05:26 | 2024-04-24 22:05:27 |
Judging History
answer
// https://qoj.ac/contest/1464/problem/7990
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e3 + 5;
int m, n;
int p[N], q[N];
int dp[N][N]; // dp[i][j]表示从p[a] q[b]开始向前,满足条件的插入1的最少数量
int dfs(int a, int b) {
if (dp[a][b]) return dp[a][b];
if (a == 0 || b == 0) {
return 0;
}
if (p[a] == p[b] || p[a] == 1 || p[b] == 1)
dp[a][b] = dfs(a - 1, b - 1);
else {
int x = dfs(a - 1, b) + 1;
int y = dfs(a, b - 1) + 1;
dp[a][b] = min(x, y);
}
return dp[a][b];
}
int main()
{
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> m >> n;
for (int i = 1; i <= m; i++) {
cin >> p[i];
}
for (int i = 1; i <= n; i++) {
cin >> q[i];
}
cout << dfs(m, n) << endl;
// for (int i = 1; i <= m; i++) {
// for (int j = 1; j <= n; j++) {
// cout << dp[i][j] << " ";
// }
// cout << endl;
// }
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3552kb
input:
4 2 2 1 3 2 4 2
output:
1
result:
ok single line: '1'
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3668kb
input:
1 1 2 3
output:
0
result:
wrong answer 1st lines differ - expected: '1', found: '0'