QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#547032 | #7689. Flipping Cards | XiaoretaW | WA | 0ms | 3748kb | C++20 | 1.9kb | 2024-09-04 17:10:02 | 2024-09-04 17:10:03 |
Judging History
answer
#include <bits/stdc++.h>
#define debug(...) 42;
#ifdef LOCAL
#include "debug.h"
#endif
using namespace std;
#define V vector
#define fi first
#define se second
#define mp make_pair
#define sz(a) ((int)a.size())
#define all(a) a.begin(), a.end()
#define F(i, l, r) for (int i = l; i < r; ++i)
#define R(i, l, r) for (int i = r-1; i >= l; --i)
typedef long long LL;
typedef double DB;
typedef pair<int, int> PII;
template<typename T> bool setmin(T &a, T b) { return (a > b ? a = b, 1 : 0); }
template<typename T> bool setmax(T &a, T b) { return (a < b ? a = b, 1 : 0); }
// mt19937_64 rng {chrono::steady_clock::now().time_since_epoch().count()};
/* -------------Main code------------- */
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int n; cin >> n;
vector<int> a(n), b(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
cin >> b[i];
}
auto ck = [&](long long mid) {
int cnt = 0;
for (int i = 0; i < n; i++) {
cnt += (a[i] < mid);
}
if (cnt <= n / 2) return true;
vector<int> cont(n);
for (int i = 0; i < n; i++) {
if (a[i] < mid and b[i] >= mid) cont[i] = 1;
if (a[i] >= mid and b[i] < mid) cont[i] = -1;
}
vector<int> pref(n);
pref[0] = cont[0];
for (int i = 1; i < n; i++) {
pref[i] = pref[i - 1] + cont[i];
}
int mx = -n, minVal = 0;
for (int i = 0; i < n; i++) {
setmax(mx, pref[i] - minVal);
setmin(minVal, pref[i]);
}
return (cnt - mx) <= (n / 2);
};
long long l = 0, r = 1e9;
while (l < r) {
long long mid = (l + r + 1) >> 1;
if (ck(mid)) l = mid;
else r = mid - 1;
}
cout << l << '\n';
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3476kb
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: 3540kb
input:
1 2 1
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3748kb
input:
1 212055293 384338286
output:
384338286
result:
ok 1 number(s): "384338286"
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3612kb
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:
507850962
result:
wrong answer 1st numbers differ - expected: '528957505', found: '507850962'