QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#426084#7615. Sequence Foldingreal_sigma_team#WA 1ms3652kbC++201.5kb2024-05-30 20:55:262024-05-30 20:55:27

Judging History

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

  • [2024-05-30 20:55:27]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3652kb
  • [2024-05-30 20:55:26]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

using ll = long long;


#define int long long

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);

    ll n;
    int m;
    cin >> n >> m;
    map<ll, int> cost, val;
    vector<ll> pts;
    for (int i = 0; i < m; ++i) {
        ll x;
        cin >> x;
        cost[x] = 1;
        val[x] = 1;
        pts.push_back(x);
    }
    ll pw = 1;
    ll ans = 0;
    while (n != 1) {
        for (auto& x : pts) {
            x = min(x, n + 1 - x);
        }
        sort(pts.begin(), pts.end());
        pts.resize(unique(pts.begin(), pts.end()) - pts.begin());
//        cout << n << ' ' << ans << endl;
//        for (auto x : pts) cout << x << ' ';
//        cout << endl;
        for (auto x : pts) {
            ll y = n + 1 - x;
            if (!val.count(x) || !cost.count(x)) {
                val[x] = 0;
                cost[x] = pw;
            }
            if (!val.count(y) || !cost.count(y)) {
                val[y] = 0;
                cost[y] = pw;
            }
//            cerr << n << ' ' << x << ' ' << y << ' ' << val[x] << ' ' << cost[x] << ' ' << val[y] << ' ' << cost[y] << endl;
            if (val[x] == val[y]) {
                cost[x] += cost[y];
            } else {
                if (cost[y] < cost[x]) swap(cost[x], cost[y]), swap(val[x], val[y]);
                ans += cost[x];
                val[x] = val[y];
                cost[x] = cost[y] - cost[x];
            }
        }
        n /= 2;
        pw *= 2;
    }
    cout << ans;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3652kb

input:

8 3
1 5 8

output:

3

result:

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