QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#323028#7130. Long binary sequenceToboWA 0ms3648kbC++202.5kb2024-02-08 10:09:102024-02-08 10:09:10

Judging History

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

  • [2024-02-08 10:09:10]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3648kb
  • [2024-02-08 10:09:10]
  • 提交

answer

#include <bits/stdc++.h>
#pragma GCC optimize(3, "Ofast", "inline")
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> s;
using i64 = long long;
// using u32 = unsigned int;
// using u64 = unsigned long long;
// using i128 = __int128_t;
using namespace std;
const int N = 1e3 + 5;
// const int B = 3e6;
// const int M = 2e6 + 5;
const int base = 13131;
// const int base = 17171;
// const int mod = 998244353;
// const int mod = 1e9 + 7;
const i64 mod = 1000000000000000003LL;
// const double pi = acos(-1);

int n, m, x[N];
void solve()
{
    cin >> n >> m;
    for (int i = 1; i <= m; i++)
        cin >> x[i];
    x[m + 1] = n + 1;
    auto cal = [&](vector<pair<int, int>> tmp) -> i64
    {
        sort(tmp.begin(), tmp.end(), greater<>());
        vector<pair<int, int>> a;
        a.push_back(tmp[0]);
        for (int i = 1; i < tmp.size(); i++)
        {
            if (tmp[i].first == tmp[i - 1].first)
                continue;
            a.push_back(tmp[i]);
        }
        i64 res = (i64)a[0].first * a[0].second;
        for (int i = 1; i < a.size(); i++)
            res += (i64)a[i].first * (a[i].second - a[i - 1].second);
        return res;
    };
    i64 ans = 0;
    {
        for (int i = 1; i <= m + 1; i++)
            ans = max(ans, 1ll * x[i] - x[i - 1] - 1);
        vector<pair<int, int>> tmp;
        for (int i = 1; i <= m; i++)
            tmp.push_back({x[i] - x[i - 1], x[i + 1] - x[i]});
        ans += cal(tmp);
    }
    for (int len = 2; len <= m; len++)
    {
        map<i64, vector<pair<int, int>>> tmp;
        i64 cur = 0, h = 1;
        for (int j = 2; j < len; j++)
        {
            cur = ((__int128_t)cur * base % mod + x[j] - x[j - 1]) % mod;
            h = (__int128_t)h * base % mod;
        }
        for (int j = len; j <= m; j++)
        {
            cur = ((__int128_t)cur * base % mod + x[j] - x[j - 1]) % mod;
            tmp[cur].push_back({x[j - len + 1] - x[j - len], x[j + 1] - x[j]});
            cur = (cur + mod - (__int128_t)h * (x[j - len + 2] - x[j - len + 1]) % mod) % mod;
        }
        for (auto [_, t] : tmp)
            ans += cal(t);
    }
    cout << ans << '\n';
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    // cin >> t;
    cout << fixed << setprecision(10);
    while (t--)
        solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3 2
1 3

output:

5

result:

ok 1 number(s): "5"

Test #2:

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

input:

1000000000 1
1

output:

1999999999

result:

ok 1 number(s): "1999999999"

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3536kb

input:

98 10
13 19 25 32 36 48 61 73 81 93

output:

3619

result:

wrong answer 1st numbers differ - expected: '3653', found: '3619'