QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#875685 | #9684. 倾诉 | testngifaicnslvthis | 0 | 23ms | 3968kb | C++14 | 2.7kb | 2025-01-30 03:20:18 | 2025-01-30 03:20:18 |
Judging History
answer
#include "bits/stdc++.h"
using namespace std;
using i64 = long long;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
int main() {
cin.tie(0)->sync_with_stdio(0);
int T;
cin >> T;
while (T--) {
int n, k;
cin >> n >> k;
vector<double> a(n);
for (int i = 0; i < n; i++) {
int x;
cin >> x;
a[i] = x;
}
double left = 0, right = *max_element(a.begin(), a.end());
vector<int> s(n);
for (int iter = 0; iter < 100; iter++) {
double mid = (left + right) / 2;
bool ok = true;
for (int i = 0; i < n; i++) {
if (mid >= a[i]) {
s[i] = 0;
} else {
double ratio = a[i] / mid;
s[i] = ceil(log2(ratio));
}
}
for (int i = 1; i < n; i++) {
if (s[i] < s[i-1]) {
s[i] = s[i-1];
}
}
int total = 0;
for (int i = 0; i < n; i++) {
total += s[i];
if (total > k) break;
}
if (total <= k) {
right = mid;
} else {
left = mid;
}
}
double max_val = 0;
vector<int> s_final(n);
for (int i = 0; i < n; i++) {
if (right >= a[i]) {
s_final[i] = 0;
} else {
double ratio = a[i] / right;
s_final[i] = ceil(log2(ratio));
}
}
for (int i = 1; i < n; i++) {
if (s_final[i] < s_final[i-1]) {
s_final[i] = s_final[i-1];
}
}
for (int i = 0; i < n; i++) {
double val = a[i] / (1LL << s_final[i]);
max_val = max(max_val, val);
}
i64 numerator = 0;
int exponent = 0;
while (exponent <= 60) {
i64 candidate = round(max_val * (1LL << exponent));
if (abs(candidate / (double)(1LL << exponent) - max_val) < 1e-9) {
numerator = candidate;
break;
}
exponent++;
}
while (exponent > 0 && (numerator % 2) == 0) {
numerator /= 2;
exponent--;
}
string s_bin;
if (numerator == 0) {
s_bin = "0";
} else {
while (numerator) {
s_bin += (numerator % 2) + '0';
numerator /= 2;
}
reverse(s_bin.begin(), s_bin.end());
}
cout << s_bin << '\n';
}
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3840kb
input:
5 6 1 11764 28428 28179 18698 6443 20288 6 3 29 17548 61962 31242 8172 4107 6 15 7 2 239427 137145 171239 3 6 4 294 211 407 190 2 2 6 5 197190 265870 12121 144584 21313 14169
output:
110111100001100 1111001000001010 111010011101000011 100100110 110000001001000110
result:
wrong answer 1st lines differ - expected: '110111100001100000000', found: '110111100001100'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Wrong Answer
Test #60:
score: 0
Wrong Answer
time: 5ms
memory: 3968kb
input:
1666 6 1 282 719 29 355 388 275 6 1 348 766 91 299 474 96 6 23 5 2 8554 8554 8554 2 6 1 84 195 23 37 120 117 6 3 8 3 51 62 28 5 6 3 3 64 64 4 4 2 6 9 5 552 552 552 552 5 6 3 3611 1144 417 3461 459 755 6 3 777 315 1007 5 2 1061 6 6 1300 2101 4 1877 360 2434 6 1 384 713 168 25 524 390 6 3 203 18 305 1...
output:
1011001111 1011111110 1000010110101 11000011 110011 1000000 100010100 111000011011 1111101111 10011000001 1011001001 100110001 101111011110 10001100000 100110111111 1010101111 10111000 101101100 10111010110 1000000 1011010000011 110111111011 101101000 100000 10001000110111 10000100110 100000111111 1...
result:
wrong answer 1st lines differ - expected: '110000100100000', found: '1011001111'
Subtask #6:
score: 0
Wrong Answer
Test #80:
score: 0
Wrong Answer
time: 23ms
memory: 3840kb
input:
3333 6 1000000000 131727 7 4 170194 6 59263 6 1000000000 417714 286613 7 310122 6 4 6 1000000000 63764 2430 2696 6699 8478 22261 6 1000000000 217 131 6 1487 2927 2 6 1000000000 26225 27991 3842 72525 4521 5231 6 1000000000 34409 26001 23563 19345 30764 24919 6 1000000000 97981 138532 59280 82393 128...
output:
1010011001 110010111111 11111001 10111 1000110111 100001101 1000011101 1010011 1100000101001 1 100011101 101110110011 1 1101001 10011011101 1010101011 100001101 111101 1011010101 1101 10001001111 1001110101 110101 1111 110111111 10111111011 110010111 111 1111111001 11001001 1010001 11001 10000000011...
result:
wrong answer 1st lines differ - expected: '10100110001101001000000', found: '1010011001'
Subtask #7:
score: 0
Skipped
Dependency #4:
0%