Submission #34706816
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,n) for (ll i=a;i<(ll)n;i++)
ll read(){ll r;scanf("%lld",&r);return r;} // read
int n ;
ll maximize(const ll * a) { // 相邻至少一个选,最大和
ll c[2] = {0,0}; // 0:第i个不选, 1个选
rep(i,0,n) tie(c[0],c[1]) = make_pair(c[1],max(c[0],c[1])+ a[i]);
return max(c[0],c[1]);
}
// 左小于等于 右大于
template <class F> ll binary_search_lambda(ll ok, ll ng, const F& check) {
while (abs(ok - ng) > 1) {
ll md = (ok + ng) / 2;
(check(md) > 0 ? ok : ng) = md;
}
return ok;
}
const ll t12 = 1000000000000;
const ll t9 = 1000000000;
const ll t3 = 1000;
ll a[100010];
ll b[100010];
int main() {
n = read();;
rep(i,0,n) a[i] = read();
ll average = binary_search_lambda(0, t12 + 1, [&](const ll thres) {
rep(i,0,n) b[i] = a[i] * t3 - thres;
return maximize(b) >= 0;
});
ll median = binary_search_lambda(0, t9 + 1, [&](const ll thres) {
rep(i,0,n) b[i] = a[i] >= thres ? 1 : -1;
return maximize(b) > 0;
});
printf("%lld.%03lld\n", average/t3,average%t3);
printf("%lld\n",median);
return 0;
}
Submission Info
Submission Time |
|
Task |
E - Average and Median |
User |
cromarmot |
Language |
C++ (GCC 9.2.1) |
Score |
500 |
Code Size |
1141 Byte |
Status |
AC |
Exec Time |
37 ms |
Memory |
5296 KiB |
Compile Error
./Main.cpp: In function ‘ll read()’:
./Main.cpp:5:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
5 | ll read(){ll r;scanf("%lld",&r);return r;} // read
| ~~~~~^~~~~~~~~~~
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
500 / 500 |
Status |
|
|
Set Name |
Test Cases |
Sample |
example_00.txt, example_01.txt |
All |
example_00.txt, example_01.txt, test_00.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt, test_20.txt, test_21.txt, test_22.txt, test_23.txt, test_24.txt, test_25.txt, test_26.txt, test_27.txt, test_28.txt, test_29.txt, test_30.txt |
Case Name |
Status |
Exec Time |
Memory |
example_00.txt |
AC |
8 ms |
3536 KiB |
example_01.txt |
AC |
2 ms |
3644 KiB |
test_00.txt |
AC |
37 ms |
5200 KiB |
test_01.txt |
AC |
27 ms |
5088 KiB |
test_02.txt |
AC |
20 ms |
4552 KiB |
test_03.txt |
AC |
26 ms |
4724 KiB |
test_04.txt |
AC |
27 ms |
4880 KiB |
test_05.txt |
AC |
14 ms |
4176 KiB |
test_06.txt |
AC |
19 ms |
4244 KiB |
test_07.txt |
AC |
16 ms |
4460 KiB |
test_08.txt |
AC |
30 ms |
5184 KiB |
test_09.txt |
AC |
22 ms |
4620 KiB |
test_10.txt |
AC |
33 ms |
5076 KiB |
test_11.txt |
AC |
33 ms |
5196 KiB |
test_12.txt |
AC |
30 ms |
4944 KiB |
test_13.txt |
AC |
29 ms |
4788 KiB |
test_14.txt |
AC |
29 ms |
4880 KiB |
test_15.txt |
AC |
32 ms |
5124 KiB |
test_16.txt |
AC |
32 ms |
5204 KiB |
test_17.txt |
AC |
24 ms |
4656 KiB |
test_18.txt |
AC |
20 ms |
4476 KiB |
test_19.txt |
AC |
26 ms |
5028 KiB |
test_20.txt |
AC |
29 ms |
5196 KiB |
test_21.txt |
AC |
29 ms |
5296 KiB |
test_22.txt |
AC |
16 ms |
4360 KiB |
test_23.txt |
AC |
6 ms |
3712 KiB |
test_24.txt |
AC |
11 ms |
3900 KiB |
test_25.txt |
AC |
28 ms |
5076 KiB |
test_26.txt |
AC |
25 ms |
5196 KiB |
test_27.txt |
AC |
4 ms |
3816 KiB |
test_28.txt |
AC |
28 ms |
5156 KiB |
test_29.txt |
AC |
32 ms |
5120 KiB |
test_30.txt |
AC |
23 ms |
5196 KiB |