QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#414193 | #7990. 广播 | aurorawhitesea | WA | 8ms | 19608kb | C++14 | 1.2kb | 2024-05-18 16:55:26 | 2024-05-18 16:55:26 |
Judging History
answer
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <numeric>
using namespace std;
int a[2010], b[2010], dp[2010][2010];
int main()
{
int n, m;
scanf("%d%d", &n, &m);
for (int i = 1; i <= n ; ++i)
scanf("%d", &a[i]);
for (int i = 1; i <= m ; ++i)
scanf("%d", &b[i]);
for (int i = 0; i <= n ; ++i)
{
for (int j = 0; j <= m ; ++j)
{
dp[i][j] = 1e9;
}
}
reverse(a+1, a+n+1);
reverse(b+1,b+m+1);
dp[n+1][m+1] = 0;
dp[0][0] = dp[1][1] = dp[0][1] = dp[1][0] = 0;
int ans = 1e9;
for (int i = 1; i <= n ; ++i)
{
for (int j = 1; j <= m ; ++j)
{
if(a[i] == b[j] || a[i] == 1|| b[i] == 1)
dp[i][j] = min(dp[i-1][j-1], dp[i][j]);
else
dp[i][j] = min(dp[i-1][j]+1,dp[i][j-1]+1);
if( i == n || j == m)
{
ans = min(ans , dp[i][j]);
}
}
}
printf("%d\n", ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3868kb
input:
4 2 2 1 3 2 4 2
output:
1
result:
ok single line: '1'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3860kb
input:
1 1 2 3
output:
1
result:
ok single line: '1'
Test #3:
score: -100
Wrong Answer
time: 8ms
memory: 19608kb
input:
1997 1970 1235 1225 1169 368 1 1 1444 1 1189 775 788 114 1609 1169 821 1708 821 1370 1444 1356 775 1747 1661 775 1692 1960 788 1866 382 1444 1356 1868 309 788 1609 211 1160 1225 1370 1609 1692 1064 1356 788 1707 775 1707 1064 1356 1160 1692 368 129 1235 1868 1370 1160 775 368 129 1747 334 1503 1444 ...
output:
1829
result:
wrong answer 1st lines differ - expected: '1813', found: '1829'