結果
問題 | No.2918 Divide Applicants Fairly |
ユーザー | けいと |
提出日時 | 2024-10-09 00:23:55 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 3,180 bytes |
コンパイル時間 | 1,326 ms |
コンパイル使用メモリ | 99,112 KB |
実行使用メモリ | 403,312 KB |
最終ジャッジ日時 | 2024-10-09 00:24:00 |
合計ジャッジ時間 | 4,839 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
10,496 KB |
testcase_01 | AC | 1 ms
5,248 KB |
testcase_02 | AC | 1 ms
5,248 KB |
testcase_03 | TLE | - |
testcase_04 | -- | - |
testcase_05 | -- | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
testcase_40 | -- | - |
testcase_41 | -- | - |
testcase_42 | -- | - |
testcase_43 | -- | - |
testcase_44 | -- | - |
testcase_45 | -- | - |
testcase_46 | -- | - |
testcase_47 | -- | - |
testcase_48 | -- | - |
testcase_49 | -- | - |
testcase_50 | -- | - |
testcase_51 | -- | - |
testcase_52 | -- | - |
testcase_53 | -- | - |
testcase_54 | -- | - |
testcase_55 | -- | - |
testcase_56 | -- | - |
testcase_57 | -- | - |
testcase_58 | -- | - |
testcase_59 | -- | - |
testcase_60 | -- | - |
testcase_61 | -- | - |
testcase_62 | -- | - |
testcase_63 | -- | - |
ソースコード
#include <iostream> #include <vector> #include <algorithm> #include <map> #include <cmath> #include <climits> #include <bitset> using namespace std; typedef long long ll; int N; vector<int> R; int main() { cin >> N; R.resize(N); ll total_sum = 0; for (int i = 0; i < N; ++i) { cin >> R[i]; total_sum += R[i]; } ll min_diff = LLONG_MAX; if (N <= 40) { int total_N = N; vector<int> indices(N); for (int i = 0; i < N; ++i) { indices[i] = i; } for (int total_k = 2; total_k <= N; total_k += 2) { vector<vector<int>> subsets; vector<bool> select(N, false); for (int i = 0; i < total_k; ++i) { select[i] = true; } do { vector<int> subset_indices; for (int i = 0; i < N; ++i) { if (select[i]) { subset_indices.push_back(i); } } subsets.push_back(subset_indices); } while (prev_permutation(select.begin(), select.end())); for (auto& subset : subsets) { int k = total_k / 2; int subset_size = subset.size(); vector<int> subset_ratings; for (int idx : subset) { subset_ratings.push_back(R[idx]); } int m = subset_size; vector<bool> team_select(m, false); for (int i = 0; i < k; ++i) { team_select[i] = true; } ll total_selected_sum = 0; for (int r : subset_ratings) { total_selected_sum += r; } do { ll team1_sum = 0; for (int i = 0; i < m; ++i) { if (team_select[i]) { team1_sum += subset_ratings[i]; } } ll team2_sum = total_selected_sum - team1_sum; ll diff = abs(team1_sum - team2_sum); if (diff < min_diff) { min_diff = diff; } } while (prev_permutation(team_select.begin(), team_select.end())); } } } else { int total_k = N; if (total_k % 2 != 0) { total_k = N - 1; } vector<pair<int, int>> rating_with_index; for (int i = 0; i < N; ++i) { rating_with_index.emplace_back(R[i], i); } sort(rating_with_index.begin(), rating_with_index.end(), greater<pair<int, int>>()); ll team1_sum = 0; ll team2_sum = 0; for (int i = 0; i < total_k; ++i) { if (i % 2 == 0) { team1_sum += rating_with_index[i].first; } else { team2_sum += rating_with_index[i].first; } } ll diff = abs(team1_sum - team2_sum); if (diff < min_diff) { min_diff = diff; } } cout << min_diff << endl; return 0; }