QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#377528 | #7990. 广播 | Destiny# | WA | 13ms | 38792kb | C++20 | 1.6kb | 2024-04-05 14:46:51 | 2024-04-05 14:46:51 |
Judging History
answer
#define TLE ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#include<bits/stdc++.h>
using namespace std;
using ll =long long;
#define int ll
const int N=1e6+500;
int a[N],b[N];
int dp[2005][2005];
signed main(){
TLE;
// dp[i][j]表示q前i和p前j匹配 q中加了几个1
// 推出 p中加了(dp[i][j]+i-j)个1 一共加了sum=dp[i][j]+i-j+dp[i][j]=2*dp[i][j]+i-j
// a[i]匹配b[j] dp[i][j]=dp[i-1][j-1]
// 不匹配 i,j-1 +1 i-1,j
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>a[n-i+1];
}
// for(int i=1;i<=n;i++){
// cout<<a[i]<<" ";
// }
// cout<<'\n';
for(int i=1;i<=m;i++){
cin>>b[m-i+1];
}
// for(int i=1;i<=m;i++){
// cout<<b[i]<<" ";
// }
// cout<<'\n';
for(int i=0;i<=n;i++){
for(int j=0;j<=m;j++){
dp[i][j]=1e9;
}
}
dp[0][0]=0;
for(int i=1;i<=n;i++) dp[i][0]=i;
for(int i=1;i<=m;i++) dp[0][i]=i;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(a[i]==1||b[j]==1||a[i]==b[j]){
dp[i][j]=min(dp[i-1][j-1],dp[i][j]);
}
dp[i][j]=min({dp[i][j],dp[i][j-1]+1,dp[i-1][j]});
// cout<<i<<" "<<j<<" "<<dp[i][j]<<'\n';
}
}
int ans=min(n,m);
for(int i=1;i<=m;i++){
ans=min(ans,dp[n][i]*2+n-i);
// cout<<n<<" "<<i<<" "<<dp[n][i]*2+n-i<<'\n';
}
for(int i=1;i<=n;i++){
ans=min(ans,dp[i][m]*2+i-m);
// cout<<i<<" "<<m<<" "<<dp[i][m]*2+i-m<<'\n';
}
cout<<ans<<'\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7668kb
input:
4 2 2 1 3 2 4 2
output:
1
result:
ok single line: '1'
Test #2:
score: 0
Accepted
time: 1ms
memory: 7728kb
input:
1 1 2 3
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 11ms
memory: 38792kb
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:
1813
result:
ok single line: '1813'
Test #4:
score: -100
Wrong Answer
time: 13ms
memory: 38424kb
input:
2000 1999 251 690 1357 1183 815 1939 1665 251 1070 354 783 1901 386 521 69 960 1 295 295 632 215 920 1763 69 1575 1246 1 1720 743 1192 959 830 595 1073 655 1763 301 632 518 319 1371 1844 768 501 400 1362 1533 1776 1319 241 178 1447 9 1339 1192 603 1 461 1113 396 1532 738 955 1005 835 690 430 495 119...
output:
1953
result:
wrong answer 1st lines differ - expected: '1951', found: '1953'