結果

問題 No.2495 Three Sets
ユーザー PAKACHUPAKACHU
提出日時 2023-10-07 00:08:36
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 563 ms / 3,000 ms
コード長 1,639 bytes
コンパイル時間 2,694 ms
コンパイル使用メモリ 133,644 KB
実行使用メモリ 4,784 KB
最終ジャッジ日時 2023-10-07 00:08:47
合計ジャッジ時間 10,618 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 118 ms
4,380 KB
testcase_01 AC 194 ms
4,380 KB
testcase_02 AC 353 ms
4,376 KB
testcase_03 AC 190 ms
4,380 KB
testcase_04 AC 120 ms
4,376 KB
testcase_05 AC 123 ms
4,376 KB
testcase_06 AC 250 ms
4,380 KB
testcase_07 AC 395 ms
4,376 KB
testcase_08 AC 404 ms
4,380 KB
testcase_09 AC 189 ms
4,376 KB
testcase_10 AC 187 ms
4,380 KB
testcase_11 AC 451 ms
4,376 KB
testcase_12 AC 431 ms
4,380 KB
testcase_13 AC 478 ms
4,380 KB
testcase_14 AC 519 ms
4,448 KB
testcase_15 AC 487 ms
4,376 KB
testcase_16 AC 563 ms
4,780 KB
testcase_17 AC 512 ms
4,784 KB
testcase_18 AC 41 ms
4,376 KB
testcase_19 AC 124 ms
4,680 KB
testcase_20 AC 531 ms
4,716 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
int dx[8] = { 1, 0, -1, 0, 1, 1, -1, -1 }, dy[8] = { 0, 1, 0, -1, 1, -1, 1, -1 };
const long long mod = 998244353;
const ll inf = 1LL << 60;
const int INF = 5e8;

const int M = 3000;

int main()
{
    int na, nb, nc;
    cin >> na >> nb >> nc;
    vector<int> a(na), b(nb), c(nc);
    for (int i = 0; i < na; i++)
        cin >> a[i];
    for (int i = 0; i < nb; i++)
        cin >> b[i];
    for (int i = 0; i < nc; i++)
        cin >> c[i];

    auto conv = [&](vector<int>& v) {
        vector<int> cnt(2 * M + 1);
        for (int i = 0; i < (int)v.size(); i++) {
            cnt[v[i] + M]++;
        }

        vector<pair<ll, ll>> res(2 * M + 1);
        ll sum = 0, cntsum = 0;
        for (int i = M; i >= -M; i--) {
            cntsum += cnt[i + M];
            sum += cnt[i + M] * i;
            res[i + M] = { sum, cntsum };
        }
        return res;
    };

    auto va = conv(a);
    auto vb = conv(b);
    auto vc = conv(c);

    auto ceil = [&](ll a, ll b) {
        if (a > 0)
            return (a + b - 1) / b;
        else
            return a / b;
    };

    ll ans = -inf;
    for (auto [sb, cb] : vb) {
        for (auto [sc, cc] : vc) {
            if (cb == 0) {
                ans = max(ans, na * sc + sb * cc);
            } else {
                ll lim = ceil(-sc, cb);
                auto [sa, ca] = lim > M ? pair<ll, ll> { 0, 0 } : va[max(0LL, lim + M)];
                ans = max(ans, sa * cb + sb * cc + sc * ca);
            }
        }
    }
    cout << ans << endl;
}
0