QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#426094 | #7615. Sequence Folding | real_sigma_team# | TL | 3416ms | 347648kb | C++20 | 1.4kb | 2024-05-30 20:58:11 | 2024-05-30 20:58:11 |
Judging History
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());
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;
}
cost[x] = min(cost[x], 1ll);
cost[y] = min(cost[y], 1ll);
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: 100
Accepted
time: 0ms
memory: 3820kb
input:
8 3 1 5 8
output:
2
result:
ok single line: '2'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
1 1 1
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Accepted
time: 2293ms
memory: 222624kb
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:
99999
result:
ok single line: '99999'
Test #4:
score: 0
Accepted
time: 2827ms
memory: 285176kb
input:
549755813888 100000 16886305 20807233 27844305 30727441 30898344 35755457 38085835 43336454 47877882 50347884 53237225 53718183 60030541 66954859 80773500 82511603 84025040 86398615 93070876 94502940 98906398 100677488 103720017 105522694 116741042 122492007 135222584 155167916 160926866 166110647 1...
output:
100000
result:
ok single line: '100000'
Test #5:
score: 0
Accepted
time: 3416ms
memory: 347648kb
input:
17592186044416 100000 44842545 229248515 253567434 347949154 349195610 404810585 639421407 650796923 1019260054 1250861689 1315840401 1318619991 1339387462 1388173647 1406074815 1459749263 1707998226 1902480662 2060860604 2075157570 2410720375 2589192480 2742051226 2784829021 3019629868 3194189913 3...
output:
100000
result:
ok single line: '100000'
Test #6:
score: -100
Time Limit Exceeded
input:
562949953421312 100000 8468403039 19260915102 24550792804 45571277635 47757798888 50487845666 53656890708 58778712483 63838097144 65697633747 74717895118 75607193564 75790076603 82739180544 88493216722 90960251492 93191423725 93775335122 96870622706 97818052601 107098516035 116573978680 117388104977...