QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#377338#7990. 广播plutosWA 1ms5652kbC++171.2kb2024-04-05 12:37:132024-04-05 12:37:13

Judging History

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

  • [2024-04-05 12:37:13]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5652kb
  • [2024-04-05 12:37:13]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
const int N = 2e5 + 10;
using ll = long long;
ll p[N], q[N];
int main() {
    ll n, m;
    cin >> m >> n;
    if (m >= n) {
        for (int i = 1; i <= m; i++) cin >> p[i];
        for (int i = 1; i <= n; i++) cin >> q[i];
    } else {
        for (int i = 1; i <= m; i++) cin >> q[i];
        for (int i = 1; i <= n; i++) cin >> p[i];
        swap(n, m);
    }

    for (int i = 1; i <= m / 2; i++) swap(p[i], p[m - i + 1]);
    for (int i = 1; i <= n / 2; i++) swap(q[i], q[n - i + 1]);

    vector<vector<ll>> dp(m + 2,vector<ll>( n + 2, 1e18) );
    dp[0][0] = 0;
    ll ans = 1e18;

    for (int i = 1; i <= m; i++) {
        for (int j = 1; j <= n; j++) {
            if( p[i] == q[j])
                dp[i][j] = min(dp[i][j] , dp[i-1][j-1]);
            if(p[i] == 1) {
                dp[i][j] = min(dp[i][j] , dp[i-1][j]);
            }
            if(q[j] == 1) {
                dp[i][j] = min(dp[i][j] , dp[i][j - 1]);
            }
            dp[i][j] = min(dp[i][j],dp[i-1][j] + 1);
            dp[i][j] = min(dp[i][j],dp[i][j - 1] + 1);
//            cout<<dp[i][j]<<" \n"[j==n];
        }
        ans = min(ans,dp[i][n]);
    }
    cout<<ans<<"\n";
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5652kb

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: 3612kb

input:

1 1
2
3

output:

1000000000000000000

result:

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