結果

問題 No.545 ママの大事な二人の子供
ユーザー RyuRyu
提出日時 2018-06-24 10:03:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,719 bytes
コンパイル時間 1,490 ms
コンパイル使用メモリ 169,548 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-13 13:29:50
合計ジャッジ時間 7,632 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 7 ms
4,376 KB
testcase_19 AC 22 ms
4,380 KB
testcase_20 AC 82 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1,282 ms
4,376 KB
testcase_23 TLE -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, init, n) for(int i = init; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define Cout(obj) cout << obj << endl
#define Size(obj) (obj).size()
#define fcout cout << fixed << setprecision(10)
#define fi first
#define se second

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to, cost;
};

const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N;
    cin >> N;

    vector<ll> A(N), B(N);
    REP(i, N)
    {
        cin >> A[i] >> B[i];
    }

    int n = N / 2, half = N - n;

    vector<ll> candiA, candiB;

    REP(S, 1 << n)
    {
        ll sumA = 0, sumB = 0;

        REP(i, n)
        {
            if((S >> i) & 1)
            {
                sumA += A[i];
            }
            else
            {
                sumB += B[i];
            }
        }

        candiA.push_back(sumA);
        candiB.push_back(sumB);
    }

    ll ans = llINF;

    REP(S, 1 << half)
    {
        ll sumA = 0, sumB = 0;

        REP(i, half)
        {
            if((S >> i) & 1)
            {
                sumA += A[i + n];
            }
            else
            {
                sumB += B[i + n];
            }
        }

        REP(i, Size(candiA))
        {
            ans = min(ans, abs(candiA[i] - candiB[i] + sumA - sumB));
        }
    }

    Cout(ans);

    return 0;
}
0