70 求 hack
查看原帖
70 求 hack
267364
cq_loves_Capoo楼主2022/7/24 20:53
#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
int n, m;
int l[N], r[N];
int lst[N], a[N];
int read()
{
    char ch = getchar();
    int s = 0;
    while (!isdigit(ch)) ch = getchar();
    while (isdigit(ch)) s = s * 10 + ch - 48, ch = getchar();
    return s;
}
int solve()
{
    int res = -2e9;
    for (int i = 1; i <= n; i++)
    {
        if (l[i] == r[i])
        {
            res = max(res, i - lst[l[i]] - 1 - l[i]);
            lst[l[i]] = i;
            a[++m] = l[i];
        }
        else 
        {
            res = max(res, i - lst[l[i]] - 1 - l[i]);
            res = max(res, i - lst[r[i]] - 1 - r[i]);
        }
    }
    sort(a + 1, a + 1 + m);
    int k = -1;
    for (int i = 2; i <= m; i++) if (a[i] - a[i - 1] > 1) { k = a[i] - 1; break; }
    if (k == -1) k = a[m] + 1;
    res = max(res, n - k);
    return res;
}
signed main()
{
    n = read();
    for (int i = 1; i <= n; i++) l[i] = read();
    for (int i = 1; i <= n; i++) r[i] = read();
    printf("%d\n", solve());
    return 0;
}

大样例都过了,WA 了 3 4 5 三个点

2022/7/24 20:53
加载中...