QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#660400 | #7689. Flipping Cards | Kdlyh | WA | 0ms | 3812kb | C++20 | 2.9kb | 2024-10-20 10:59:03 | 2024-10-20 10:59:03 |
Judging History
answer
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <stack>
using i64 = long long;
// #ifdef LOCAL
// #else
// #define debug(X...)
// #endif
void solve()
{
// #define tests
int n; std::cin >> n;
std::vector<int> a(n), b(n);
for (int i = 0; i < n; i++) {std::cin >> a[i] >> b[i];}
auto get = [&](const int& i) {
if (a[i] > b[i]) {return -1;}
if (a[i] < b[i]) {return 1;}
return 0;
};
std::vector<int> deal(n); for (int i = 0; i < n; i++) {deal.at(i) = get(i);}
std::vector<int>final_nums(n);
/* for(int i = 0 ; i < n ; i++){
std::cerr << deal[i] << " ";
}*/
int l = 0, r = -1, sl = 0, slr = 0, len = 0, tmpl;
for(int li = 0, i = 0 ; i < n ; i++){
sl += deal[i];
tmpl++;
if(sl < 0){
li = i + 1;
sl = 0;
tmpl = 0;
}
if(sl > slr || (tmpl > len && sl == slr)){
slr = sl;
l = li;
r = i;
len = tmpl;
}
}
//debug(l, r);
//std::cerr << l << " " << r;
for(int i = 0 ; i < n ; i++){
if(i >= l && i <= r){
final_nums[i] = b[i];
}else{
final_nums[i] = a[i];
}
}
//std::cerr << final_nums[0];
sort(final_nums.begin(), final_nums.end());
std::cout << final_nums[(n + 1) / 2 - 1];
// auto check = [&](const int mid) {
// std::vector<int> pre(n + 1);
// auto get = [&](const int& i) {
// if (a[i] > mid and b[i] <= mid) {return 1;}
// if (a[i] <= mid and b[i] > mid) {return -1;}
// return 0;
// };
// for (int i = 0; i < n; i++) {pre[i + 1] = pre[i] + get(i);}
// int bef{}; for (int i = 0; i < n; i++) {if (a[i] <= mid) {bef += 1;}}
// std::vector<int> pre_mn(n + 1);//[1 ~ i], pre[i - 1]
// for (int i = 0; i < n; i++) {pre_mn[i + 1] = std::min(pre_mn[i], pre[i + 1]);}
// int cnt{}; for (int r = 1; r <= n; r++) {
// cnt = std::max(cnt, bef + pre[r] - pre_mn[r]);
// }
// return cnt >= (n + 1) / 2;
// };
// int lo{}, hi{(int)1E9}; while (lo <= hi) {
// int mid{(int)(lo + hi >> 1)}; check(mid) ? hi = mid - 1 : lo = mid + 1;
// }
// std::cout << hi + 1 << "\n";
}
signed main()
{
std::cin.tie(nullptr) -> sync_with_stdio(false);
int _{1};
#ifdef tests
std::cin >> _;
#endif
while (_--) {solve();}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3812kb
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: 0ms
memory: 3800kb
input:
1 2 1
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3520kb
input:
1 212055293 384338286
output:
384338286
result:
ok 1 number(s): "384338286"
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3524kb
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:
512721865
result:
wrong answer 1st numbers differ - expected: '528957505', found: '512721865'