結果
問題 |
No.2918 Divide Applicants Fairly
|
ユーザー |
![]() |
提出日時 | 2024-10-07 16:04:19 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,654 bytes |
コンパイル時間 | 2,934 ms |
コンパイル使用メモリ | 117,756 KB |
実行使用メモリ | 178,044 KB |
最終ジャッジ日時 | 2024-10-07 16:04:31 |
合計ジャッジ時間 | 11,722 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 58 TLE * 1 |
ソースコード
#include <iostream> #include <vector> #include <algorithm> #include <limits> #include <stack> using namespace std; long long popcount(long long n) { long long c = (n & 0x5555555555555555) + ((n >> 1) & 0x5555555555555555); c = (c & 0x3333333333333333) + ((c >> 2) & 0x3333333333333333); c = (c & 0x0f0f0f0f0f0f0f0f) + ((c >> 4) & 0x0f0f0f0f0f0f0f0f); c = (c & 0x00ff00ff00ff00ff) + ((c >> 8) & 0x00ff00ff00ff00ff); c = (c & 0x0000ffff0000ffff) + ((c >> 16) & 0x0000ffff0000ffff); c = (c & 0x00000000ffffffff) + ((c >> 32) & 0x00000000ffffffff); return c; } struct StackElement { long long r; int c; int i; }; int main() { int N; cin >> N; vector<int> R(N); for (int i = 0; i < N; ++i) { cin >> R[i]; } if (N >= 26) { cout << 0 << endl; return 0; } vector<vector<long long>> dp(N + 1); stack<StackElement> stack; stack.push({0, 0, -1}); while (!stack.empty()) { StackElement element = stack.top(); stack.pop(); dp[element.c].push_back(element.r); if ((element.c + 1) * 2 > N) { continue; } for (int j = element.i + 1; j < N; ++j) { stack.push({element.r + R[j], element.c + 1, j}); } } long long ans = numeric_limits<long long>::max(); for (int n = 1; n <= N; ++n) { if (2 * n > N) { break; } int le = dp[n].size(); sort(dp[n].begin(), dp[n].end()); for (int i = 0; i < le - 1; ++i) { ans = min(ans, dp[n][i + 1] - dp[n][i]); } } cout << ans << endl; return 0; }