結果
問題 | No.8105 Міжнародний підрядок саміт |
ユーザー |
|
提出日時 | 2023-09-15 16:30:51 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,145 bytes |
コンパイル時間 | 3,023 ms |
コンパイル使用メモリ | 245,676 KB |
実行使用メモリ | 10,752 KB |
最終ジャッジ日時 | 2024-07-02 18:55:16 |
合計ジャッジ時間 | 7,651 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | TLE * 1 -- * 3 |
ソースコード
// すべての入力は素数なので, 素数列に含まれる等差数列を調べる.// https://en.wikipedia.org/wiki/Primes_in_arithmetic_progression#Minimal_primes_in_AP// を見ると, N も素数であることから, A_{N-1} <= 10^9 を満たすためには N <= 13 でないといけないことが分かる.#include <bits/stdc++.h>#define rep(i, n) for (int i = 0; i < (n); i++)using namespace std;using lint = long long;const lint INF = 1LL << 61;void solve() {lint n, p;cin >> n >> p;vector<lint> A(n);rep (i, n) cin >> A[i];lint ans = 0;rep (S, 1 << n) {if (S == 0) continue;lint evenness = INF;for (int T = S;; T = (T - 1) & S) {lint tmp = 0;rep (i, n) {if (S >> i & 1) {tmp += (T >> i & 1 ? 1 : -1) * A[i];}}evenness = min(evenness, abs(tmp));if (T == 0) break;}ans = (ans + evenness) % p;}cout << ans << "\n";}int main() {int t;cin >> t;rep (_, t) {solve();}return 0;}