結果
| 問題 | No.8105 Міжнародний підрядок саміт |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-04-03 09:12:28 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,200 bytes |
| コンパイル時間 | 1,384 ms |
| コンパイル使用メモリ | 195,368 KB |
| 実行使用メモリ | 7,852 KB |
| 最終ジャッジ日時 | 2025-11-10 01:11:29 |
| 合計ジャッジ時間 | 5,068 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 1 WA * 2 RE * 1 |
ソースコード
#pragma region template
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
constexpr ll inf = 3001001000100100100LL;
#define endl '\n'
#define rep(i, n) for (ll i = 0; i < (n); ++i)
template <class T, class U>
bool chmin(T& m, const U& v) {
if (v < m) {
m = v;
return true;
}
return false;
}
struct setup_main {
setup_main() {
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
std::cout << fixed << setprecision(15);
}
} setup_main_;
ll N, P;
ll A[13], ans[1 << 13];
void dfs(ll i, ll s, ll b) {
if (i == N) {
chmin(ans[b], abs(s));
return;
}
ll nb = (b << 1);
dfs(i + 1, s, nb);
dfs(i + 1, s - A[i], nb + 1);
dfs(i + 1, s + A[i], nb + 1);
}
void solve() {
cin >> N >> P;
rep(i, N) cin >> A[i];
if (N > 1 and A[0] == A[1]) {
cout << (N % 2 ? A[0] : 0) << endl;
return;
}
rep(i, 1 << N) ans[i] = inf;
dfs(1, 0, 0);
dfs(1, A[0], 1);
ll a = 0;
rep(i, 1 << N) a += ans[i];
cout << a % P << endl;
}
signed main() {
ll T;
cin >> T;
while (T--) {
solve();
}
}