ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#278 | #5. 「WyOJ Round 1」炽 · 踏浪而歌 | recall | 100 | 3436ms | 6404kb | C++14 | 3.3kb | 2025-04-18 15:21:50 | 2025-04-18 18:03:53 |
answer
#include <bits/stdc++.h>
// #define int i64
using i64 = long long;
using u64 = unsigned long long;
using u32 = unsigned;
// using i128 = __int128;
// using u128 = unsigned __int128;
inline void solve(){
int n;
std::cin >> n;
std::vector<int> a(n + 1);
int s = 0;
bool ffg = 1;
for (int i = 1; i <= n; i++) {
std::cin >> a[i];
s += a[i];
}
for (int i = 2; i <= n; i++) {
ffg &= (a[i] <= a[i - 1]);
}
int maxn = (*std::max_element(a.begin() + 1, a.end()));
int k = std::max(maxn, (s + 1) / 2);
std::cout << k << '\n';
std::map<int, int> cnt;
std::set<int> S;
for (int i = 1; i <= n; i++) {
if (a[i] > 0) {
cnt[a[i]]++;
S.insert(i);
}
}
auto del = [&](int v) {
auto it = cnt.find(v);
if (--it->second == 0) cnt.erase(it);
};
auto add = [&](int v) {
cnt[v]++;
};
int cts = s;
for (int sp = 1; sp <= k; sp++) {
int res = k - sp;
int i = (*S.begin());
bool fg = 0;
auto it = prev(cnt.end());
int aa = it -> first, bb = 0;
if (it != cnt.begin()) {
auto itt = prev(it);
bb = itt -> first;
}
int j = i;
auto wk = [&](){
int dw = (i == j ? 1 : 2);
int ns = cts - dw;
if (res < (ns + 1) / 2) return 0;
int cA = it->second;
int mx = cA - (a[i] == aa) - (j != i && a[j] == aa ? 1 : 0);
int tmx = (mx > 0 ? aa : bb);
int ni = a[i] - 1;
tmx = std::max(tmx, ni);
if (i ^ j){
tmx = std::max(tmx, a[j] - 1);
}
if (res < tmx) return 0;
std::cout << i << " " << j << "\n";
del(a[i]);
if (i == j) {
a[i]--, cts--;
if (a[i] > 0) {
add(a[i]);
} else {
S.erase(i);
}
} else {
del(a[j]);
a[i]--, a[j]--;
cts -= 2;
if (a[i] > 0) {
add(a[i]);
} else {
S.erase(i);
}
if (a[j] > 0) {
add(a[j]);
} else {
S.erase(j);
}
}
fg = 1;
return 1;
};
if(!ffg){
wk();
for (auto it = S.upper_bound(i); it != S.end(); it++) {
j = (*it);
if (wk()) {
break;
}
}
} else {
std::vector<int> tp;
tp.push_back(i);
for (auto it = S.upper_bound(i); it != S.end(); it++) {
tp.push_back(*it);
}
for (auto vv : tp) {
j = vv;
if (wk()) {
break;
}
}
}
}
}
signed main() {
std::ios::sync_with_stdio(0);
std::cin.tie(0), std::cout.tie(0);
int t = 1;
while(t--) solve();
return 0;
}
这程序好像有点Bug,我给组数据试试?
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 1ms
memory: 3328kb
input:
6 3 4 1 2 4 6
output:
10 1 2 1 2 1 2 2 3 4 6 4 6 5 6 5 6 5 6 5 6
result:
ok 21 numbers
Test #2:
score: 10
Accepted
time: 1413ms
memory: 3380kb
input:
1000 1000 1000 1000 999 996 993 991 991 991 991 991 991 988 988 988 988 987 984 980 980 978 978 977 ...
output:
259517 1 1 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1...
result:
ok 519035 numbers
Test #3:
score: 10
Accepted
time: 211ms
memory: 3508kb
input:
5 93761 154479 466694 134030 151036
output:
500000 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1...
result:
ok 1000001 numbers
Test #4:
score: 10
Accepted
time: 263ms
memory: 5176kb
input:
56700 20 9 3 26 6 14 11 26 15 4 7 7 18 3 55 16 0 2 71 8 21 3 15 21 2 25 38 10 2 15 3 1 3 15 6 2 26 5...
output:
500000 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 3 1 3 1 3 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 4 5 4 5 4 5 4...
result:
ok 1000001 numbers
Test #5:
score: 10
Accepted
time: 237ms
memory: 4148kb
input:
18574 19 245 80 2 53 157 18 27 35 19 109 14 30 97 26 10 5 22 142 102 13 114 67 70 142 131 10 177 18 ...
output:
500000 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 2 3 2 3 2 3 2 3 2...
result:
ok 1000001 numbers
Test #6:
score: 10
Accepted
time: 268ms
memory: 4444kb
input:
36045 6 62 19 5 21 38 42 13 52 3 10 4 14 65 24 15 9 21 19 24 1 3 2 59 2 19 80 28 9 39 49 26 20 20 14...
output:
500000 1 2 1 2 1 2 1 2 1 2 1 2 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2...
result:
ok 1000001 numbers
Test #7:
score: 10
Accepted
time: 233ms
memory: 3376kb
input:
100 442 37503 827 703 10394 1215 23599 313 1705 10819 6152 89 341 3448 778 7153 20397 5166 2735 2100...
output:
500000 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1...
result:
ok 1000001 numbers
Test #8:
score: 10
Accepted
time: 287ms
memory: 3540kb
input:
1000 6 436 820 182 327 3272 993 1042 321 2717 69 4321 706 4565 1280 528 1632 1317 916 125 262 1712 6...
output:
500000 1 2 1 2 1 2 1 2 1 2 1 2 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2...
result:
ok 1000001 numbers
Test #9:
score: 10
Accepted
time: 257ms
memory: 3872kb
input:
10000 6 107 38 107 3 28 89 15 30 19 89 2 435 75 45 55 119 125 15 42 101 83 9 134 3 278 292 55 255 2 ...
output:
500000 1 2 1 2 1 2 1 2 1 2 1 2 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2...
result:
ok 1000001 numbers
Test #10:
score: 10
Accepted
time: 266ms
memory: 6404kb
input:
100000 3 3 62 19 5 21 0 17 21 2 1 36 3 11 2 3 10 22 17 3 10 0 4 3 11 20 11 22 12 12 12 1 10 4 9 6 4 ...
output:
500000 1 2 1 2 1 2 3 4 3 4 3 4 3 4 3 4 3 4 3 4 3 4 3 4 3 4 3 4 3 4 3 4 3 4 3 4 3 4 3 4 3 4 3 4 3 5 3...
result:
ok 1000001 numbers
Extra Test:
score: 0
Extra Test Passed