QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#502246#7615. Sequence FoldingpandapythonerRE 0ms3624kbC++232.0kb2024-08-03 01:50:092024-08-03 01:50:10

Judging History

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

  • [2024-08-03 01:50:10]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3624kb
  • [2024-08-03 01:50:09]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;


#define ll long long
#define flt double
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define rep(i, n) for(int i = 0; i < n; i += 1)
#define len(a) ((int)(a).size())


const ll inf = 1e18;
mt19937 rnd(234);


int32_t main() {
    if (1) {
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
    }
    ll n, m;
    cin >> n >> m;
    vector<pair<ll, int>> a;
    rep(i, m) {
        ll p;
        cin >> p;
        --p;
        a.push_back(make_pair(p, 1));
    }
    ll moves = 0;
    while (n > 1) {
        assert(n % 2 == 0);
        n /= 2;
        vector<pair<ll, int>> b, c;
        for (auto [p, x] : a) {
            if (p < n) {
                b.push_back(make_pair(p, x));
            } else {
                c.push_back(make_pair(2 * n - p - 1, x));
            }
        }
        reverse(all(c));
        a.clear();
        int i = 0;
        int j = 0;
        while (i < len(b) or j < len(c)) {
            if (i < len(b) and j < len(c) and b[i].first == c[j].first) {
                if (b[i].second == 2) {
                    a.push_back(c[i]);
                } else if (c[i].second == 2) {
                    a.push_back(b[i]);
                } else {
                    assert(b[i] == c[i]);
                    a.push_back(b[i]);
                }
                ++i;
                ++j;
                continue;
            }
            if (j == len(c) or (i < len(b) and b[i].first < c[j].first)) {
                if (b[i].second == 1) {
                    moves += 1;
                    a.push_back(make_pair(b[i].first, 2));
                }
                ++i;
            } else {
                if (c[j].second == 1) {
                    moves += 1;
                    a.push_back(make_pair(c[j].first, 2));
                }
                ++j;
            }
        }
    }
    cout << moves << "\n";
    return 0;
}

詳細信息

Test #1:

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

input:

8 3
1 5 8

output:

2

result:

ok single line: '2'

Test #2:

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

input:

1 1
1

output:

0

result:

ok single line: '0'

Test #3:

score: -100
Runtime Error

input:

17179869184 100000
138476 774165 993977 1152277 1236393 1244970 1534017 1693701 1763926 1778781 1842066 1874644 1885666 2120429 2485344 2977941 3158255 3340476 3504862 4000117 4066652 4197639 4338723 4389163 4576965 4761601 5097091 5175412 5295902 5810551 5855982 6001770 6111262 6163309 6351547 6582...

output:


result: