QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#640714#7990. 广播ucup-team3519#WA 8ms18688kbC++171002b2024-10-14 15:29:182024-10-14 15:29:19

Judging History

你现在查看的是最新测评结果

  • [2024-10-14 15:29:19]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:18688kb
  • [2024-10-14 15:29:18]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define V vector
#define pb push_back
const int INF = 2e9 + 100;
void solve() {
    int n, m; cin >> n >> m;
    V<int> a(n + 1);
    V<int> b(m + 1);
    for(int i = 1; i <= n; i++) cin >> a[i];
    for(int i = 1; i <= m; i++) cin >> b[i];

    if(m > n) swap(m, n), swap(a, b);

    V<V<int>> dp(n + 2, V<int>(m + 2, INF / 2));
    dp[1][1] = 0;
    
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            if(a[i] == b[j]) {
                dp[i + 1][j + 1] = min(dp[i][j], dp[i + 1][j + 1]);
            }
            dp[i + 1][j] = min(dp[i][j] + 1, dp[i + 1][j]);
            dp[i][j + 1] = min(dp[i][j] + 1, dp[i][j + 1]);
        }
    }

    int ans = INF;

    for(int i = 1; i <= n + 1; i++) {
        ans = min(ans, dp[i][m + 1]);
    }
    cout << ans << endl;
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    int t = 1; 
    // cin >> t;
    while(t--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3596kb

input:

4 2
2 1 3 2
4 2

output:

1

result:

ok single line: '1'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3508kb

input:

1 1
2
3

output:

1

result:

ok single line: '1'

Test #3:

score: -100
Wrong Answer
time: 8ms
memory: 18688kb

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:

1852

result:

wrong answer 1st lines differ - expected: '1813', found: '1852'