QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#466867 | #7689. Flipping Cards | Water_OR# | WA | 1ms | 5704kb | C++17 | 1.7kb | 2024-07-08 11:18:04 | 2024-07-08 11:18:05 |
Judging History
answer
#include <bits/stdc++.h>
size_t n;
typedef std::pair<int, int> two;
two input_array[300005];
int worth[300005];
inline bool check(int mid) {
int counter = 0;
// std::cout << "# " << mid << "\n|";
for (size_t i = 0; i < n; ++i) {
if (input_array[i].first < mid) { ++counter; }
if (input_array[i].first < mid && input_array[i].second >= mid) { worth[i] = 1; }
else if (input_array[i].first >= mid && input_array[i].second < mid) { worth[i] = -1; }
else { worth[i] = 0; }
// std::cout << " " << worth[i];
}
// std::cout << "\n| " << counter << "\n";
for (size_t i = 1; i < n; ++i) { worth[i] += worth[i - 1]; }
int min_index = -1;
for (size_t i = 0; i < n; ++i) {
if (worth[i] - (min_index < 0 ? 0 : worth[min_index]) >= counter - n / 2) { return true; }
if (worth[i] < worth[min_index]) { min_index = i; }
}
return false;
}
inline void solve() {
size_t *index_array;
index_array = new size_t[n];
for (size_t i = 0; i < n; ++i) { index_array[i] = i; }
std::sort(index_array, index_array + n, [=](const size_t &x, const size_t &y) { return input_array[x].first < input_array[y].first; });
int answer = input_array[index_array[n / 2]].first;
size_t length = INT32_MAX - answer;
while (length > 0) {
size_t half = length - (length >> 1);
int mid = answer + half;
if (check(mid)) {
answer = mid;
length = length - half;
} else {
length = half - 1;
}
}
std::cout << answer << std::endl;
}
signed main() {
std::cin >> n;
for (size_t i = 0; i < n; ++i) {
std::cin >> input_array[i].first >> input_array[i].second;
}
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3584kb
input:
5 3 6 5 2 4 7 6 4 2 8
output:
6
result:
ok 1 number(s): "6"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5704kb
input:
1 2 1
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3640kb
input:
1 212055293 384338286
output:
384338286
result:
ok 1 number(s): "384338286"
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3704kb
input:
99 749159996 323524232 125448341 365892333 481980673 143665393 394405973 44741918 687549448 513811513 287088118 385131171 11865696 666468353 449920567 373650719 671547289 116780561 41003675 671513243 351534153 507850962 374160874 985661954 222519431 600582098 987220654 704142246 856147059 37783620 1...
output:
995384916
result:
wrong answer 1st numbers differ - expected: '528957505', found: '995384916'