QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#292979 | #4428. Fence | ahsoltan | AC ✓ | 184ms | 50332kb | C++20 | 1.3kb | 2023-12-28 18:38:39 | 2023-12-28 18:38:40 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 2137
#endif
struct node {
int s[2];
int cnt;
};
void solve() {
int n;
list<node> lst;
cin >> n;
int m = 1;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
m = max(m, a);
lst.push_back({{a, 0}, -1});
}
for (int i = 1; i <= m; i++) {
int ans = 0;
int c = 0;
for (auto it = lst.begin(); it != lst.end(); it++) {
if (it->cnt == -1) {
int a = it->s[0] / i;
int b = it->s[0] % i;
int s0 = ((a + 1) / 2) * i + (a % 2 == 0 ? b : 0);
int s1 = (a / 2) * i + (a % 2 == 1 ? b : 0);
ans += c % 2 == 0 ? s0 : s1;
c += a + (b > 0);
if (i == it->s[0]) {
it->cnt = 1;
}
} else {
ans += it->s[c % 2];
c += it->cnt;
}
if (it->cnt != -1 && it != lst.begin() && prev(it)->cnt != -1) {
auto p = prev(it);
int pp = p->cnt % 2;
it->s[0] += p->s[pp];
it->s[1] += p->s[pp ^ 1];
if (pp) {
swap(it->s[0], it->s[1]);
}
it->cnt += p->cnt;
lst.erase(p);
}
}
cout << ans << '\n';
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 184ms
memory: 19160kb
input:
5 333834 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
output:
500000 500000 499995 499987 500000 500032 499996 499987 500032 500000 499994 499998 499981 499996 500080 500090 500077 500032 499980 499915 500035 499941 500055 499923 500000 499980 499935 500042 500174 499905 500002 499998 500218 499899 499965 500010 500144 500242 499839 499915 499987 500010 500122...
result:
ok 2500000 lines
Test #2:
score: 0
Accepted
time: 91ms
memory: 8248kb
input:
5 48356 1 1 2 2 1 1 1 1 2 4 8 4 1 2 128 4 1 1 2 1 1 2 2 1 1 1 4 1 1 1 2 1 2 8 8 1 1 1 1 8 1 2 1 2 1 1 1 1 8 1 2 1 2 1 2 1 2 1 1 8 1 2 4 1 1 1 1 1 4 1 2 1 1 1 2 1 2 64 1 256 1 1 1 1 1 2 32 1 1 2 1 1 2 2 1 1 1 1 1 1 4 1 1 2 2 1 1 1 1 1 1 2 1 2 256 4 1 1 2 1 2 1 2 2 1 1 2 2 2 2 1 1 1 2 1 32 1 1 1 4 1 1...
output:
500000 499939 500012 499925 499701 499996 499780 499879 500247 499914 500226 500164 500084 500054 499449 499819 500132 500378 500533 500517 499941 499527 500493 500808 500635 499680 500903 500128 500111 500413 499462 500244 500233 499885 499983 500105 499925 500185 499961 499466 500376 500081 498569...
result:
ok 987898 lines
Test #3:
score: 0
Accepted
time: 65ms
memory: 8432kb
input:
5 100000 1 10 9 6 2 9 5 8 6 8 3 10 10 4 8 10 5 4 8 1 3 3 10 6 8 2 1 1 7 4 4 7 3 3 2 7 3 8 4 8 8 8 9 7 1 6 7 5 1 6 5 6 10 7 1 7 10 4 9 6 7 3 4 2 7 7 8 9 7 1 8 4 1 6 10 1 3 8 8 5 6 4 10 5 10 3 4 1 8 2 8 4 6 1 7 2 10 2 2 3 3 3 4 6 6 6 6 7 8 8 8 9 9 9 9 9 10 10 4 5 10 3 1 5 6 7 9 5 3 2 2 3 1 2 1 6 1 1 6...
output:
275038 275208 276333 274460 274715 278680 279579 271029 278720 274871 251536 251586 251550 251533 251687 251362 251680 251736 251758 251640 252228 251127 251367 250702 251853 250779 250632 250725 251045 251774 251515 249096 250101 253104 247732 248767 248976 249529 253658 252323 252069 251541 251651...
result:
ok 1010971 lines
Test #4:
score: 0
Accepted
time: 142ms
memory: 50332kb
input:
5 1413 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 1...
output:
499496 499496 499494 499848 499491 500202 499487 500553 499498 500905 499497 501264 499498 501599 499446 501961 499443 502306 499413 502649 499443 503017 499414 503329 499499 503710 499498 504049 499501 504360 499310 504777 499233 505155 499499 505440 499170 505761 499498 506160 499091 506583 499505...
result:
ok 502830 lines
Test #5:
score: 0
Accepted
time: 0ms
memory: 3784kb
input:
5 1 1 1 3 2 1 1 2 1 2 2 3 1
output:
1 2 2 3 1 2 1 2 3 3
result:
ok 10 lines
Extra Test:
score: 0
Extra Test Passed