提出 #73103395
ソースコード 拡げる
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <array>
#define fastio cin.tie(0)->sync_with_stdio(0)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define compress(v) sort(all(v)), v.erase(unique(all(v)), v.end())
#define sz(x) (int)(x).size()
using namespace std;
typedef long long ll;
int main() {
fastio; int T; cin >> T;
for (int tc = 0; tc < T; tc++) {
ll N, M; cin >> N >> M;
vector<ll> v(N); ll sum = 0;
for (auto& i : v) { cin >> i; sum += i; }
map<ll,array<ll,3>> dp;
auto calc = [&](auto calc, ll l, ll x) -> array<ll,3> {
if (l < x) return { 0, 0, 0 };
if (l < 2*x) return { 1, l, 0 };
if (dp.count(l)) return dp[l];
auto r1 = calc(calc, l/2, x), r2 = calc(calc, (l+1)/2, x);
if (r1[0]+r2[0] > 1) return dp[l] = { r1[0]+r2[0], r1[1]+r2[1], r1[2]+r2[2]+1 };
else dp[l] = { 1, l, 0 };
};
ll t = (N+M+1)/2;
auto chk = [&](ll mid) {
if (mid-1 > (sum-N-M)/t) return false;
dp.clear();
ll res = 0, cnt = 0, len = 0, cut = 0;
for (auto i : v) {
if (i >= mid) {
cnt++;
auto [s, l, c] = calc(calc, i, mid);
len += l; res += s; cut += c;
}
}
if (cut > M) return cnt+M >= t;
return res - max(0LL, (N+M-res)-(sum-len)) >= t;
};
ll st = 1, en = 1e9, ans = 0;
while (st <= en) {
ll mid = (st+en)/2;
if (chk(mid)) {
ans = mid;
st = mid+1;
}
else {
en = mid-1;
}
}
cout << ans << "\n";
}
return 0;
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | F - Half and Median |
| ユーザ | Lov34ever |
| 言語 | C++23 (GCC 15.2.0) |
| 得点 | 0 |
| コード長 | 1895 Byte |
| 結果 | WA |
| 実行時間 | > 4000 ms |
| メモリ | 166848 KiB |
コンパイルエラー
./Main.cpp: In lambda function:
./Main.cpp:28:9: warning: control reaches end of non-void function [-Wreturn-type]
28 | };
| ^
ジャッジ結果
| セット名 | Sample | All | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 0 / 550 | ||||||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | 0_sample_1.txt |
| All | 0_sample_1.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt, 1_20.txt, 1_21.txt, 1_22.txt, 1_23.txt, 1_24.txt, 1_25.txt, 2_01.txt, 2_02.txt, 2_03.txt, 2_04.txt, 2_05.txt, 2_06.txt, 2_07.txt, 2_08.txt, 2_09.txt, 2_10.txt, 3_01.txt, 3_02.txt, 3_03.txt, 3_04.txt, 3_05.txt, 3_06.txt, 4_01.txt, 4_02.txt, 4_03.txt, 4_04.txt, 4_05.txt, 4_06.txt, 4_07.txt, 5_1.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 0_sample_1.txt | AC | 1 ms | 3452 KiB |
| 1_01.txt | WA | 1568 ms | 93688 KiB |
| 1_02.txt | WA | 1492 ms | 98864 KiB |
| 1_03.txt | AC | 1143 ms | 62068 KiB |
| 1_04.txt | WA | 2005 ms | 83512 KiB |
| 1_05.txt | AC | 120 ms | 7448 KiB |
| 1_06.txt | WA | 2179 ms | 166680 KiB |
| 1_07.txt | WA | 2171 ms | 165704 KiB |
| 1_08.txt | WA | 58 ms | 7956 KiB |
| 1_09.txt | WA | 145 ms | 7956 KiB |
| 1_10.txt | WA | 133 ms | 8088 KiB |
| 1_11.txt | TLE | > 4000 ms | 166848 KiB |
| 1_12.txt | WA | 2189 ms | 166296 KiB |
| 1_13.txt | WA | 305 ms | 8084 KiB |
| 1_14.txt | AC | 21 ms | 4172 KiB |
| 1_15.txt | WA | 63 ms | 8084 KiB |
| 1_16.txt | AC | 2183 ms | 166520 KiB |
| 1_17.txt | AC | 2186 ms | 166844 KiB |
| 1_18.txt | TLE | > 4000 ms | 166648 KiB |
| 1_19.txt | TLE | > 4000 ms | 166548 KiB |
| 1_20.txt | AC | 2198 ms | 166680 KiB |
| 1_21.txt | AC | 59 ms | 8088 KiB |
| 1_22.txt | AC | 21 ms | 4268 KiB |
| 1_23.txt | AC | 53 ms | 8088 KiB |
| 1_24.txt | AC | 2243 ms | 166656 KiB |
| 1_25.txt | AC | 54 ms | 8012 KiB |
| 2_01.txt | WA | 921 ms | 3944 KiB |
| 2_02.txt | WA | 861 ms | 3884 KiB |
| 2_03.txt | WA | 992 ms | 3868 KiB |
| 2_04.txt | WA | 894 ms | 3928 KiB |
| 2_05.txt | WA | 962 ms | 3972 KiB |
| 2_06.txt | WA | 583 ms | 3652 KiB |
| 2_07.txt | WA | 566 ms | 3668 KiB |
| 2_08.txt | WA | 585 ms | 3648 KiB |
| 2_09.txt | WA | 566 ms | 3668 KiB |
| 2_10.txt | WA | 585 ms | 3628 KiB |
| 3_01.txt | WA | 10 ms | 3792 KiB |
| 3_02.txt | WA | 14 ms | 3544 KiB |
| 3_03.txt | WA | 33 ms | 3636 KiB |
| 3_04.txt | WA | 91 ms | 3520 KiB |
| 3_05.txt | WA | 7 ms | 3644 KiB |
| 3_06.txt | WA | 5 ms | 3448 KiB |
| 4_01.txt | AC | 8 ms | 4184 KiB |
| 4_02.txt | AC | 8 ms | 4152 KiB |
| 4_03.txt | WA | 13 ms | 4216 KiB |
| 4_04.txt | AC | 11 ms | 4248 KiB |
| 4_05.txt | AC | 8 ms | 4188 KiB |
| 4_06.txt | AC | 11 ms | 4248 KiB |
| 4_07.txt | WA | 11 ms | 4288 KiB |
| 5_1.txt | WA | 754 ms | 3772 KiB |