QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#626947#7990. 广播hhhyh#WA 13ms18640kbC++231.6kb2024-10-10 14:09:352024-10-10 14:09:37

Judging History

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

  • [2024-10-10 14:09:37]
  • 评测
  • 测评结果:WA
  • 用时:13ms
  • 内存:18640kb
  • [2024-10-10 14:09:35]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define all(x) x.begin(), x.end()
void solve()
{
    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(m);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = 0; i < m; i++)
        cin >> b[i];
    reverse(all(a));
    reverse(all(b));
    auto work = [&](vector<int> &a, vector<int> &b)
    {
        int n = a.size(), m = b.size();
        vector<vector<int>> dp(n + 1, vector<int>(m + 1, 1e6));
        // 匹配完成m个最小的cost
        for (int i = 0; i <= n; i++)
            dp[i][0] = i;
        for (int i = 0; i <= m; i++)
            dp[0][i] = i;
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
            {
                if (a[i] == b[j])
                {
                    dp[i + 1][j + 1] = min({
                        dp[i + 1][j + 1],
                        dp[i][j],
                        dp[i+1][j]+1,
                        dp[i][j+1]+1
                    });
                }
                else
                {
                    dp[i + 1][j + 1] = min({dp[i + 1][j + 1],
                                            dp[i + 1][j] + 1,
                                            dp[i][j + 1] + 1});
                }
            }
        int res=1e6;
        for(int i=0;i<=n;i++)res=min(dp[i][m],res);
        for(int i=0;i<=m;i++)res=min(dp[n][i],res);
        return res;
    };
    cout<<work(a,b)<<endl;
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int T = 1;
    while (T--)
        solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4 2
2 1 3 2
4 2

output:

1

result:

ok single line: '1'

Test #2:

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

input:

1 1
2
3

output:

1

result:

ok single line: '1'

Test #3:

score: -100
Wrong Answer
time: 13ms
memory: 18640kb

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:

1850

result:

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