結果
問題 | No.1711 Divide LCM |
ユーザー | SSRS |
提出日時 | 2021-10-15 22:54:58 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,544 bytes |
コンパイル時間 | 2,139 ms |
コンパイル使用メモリ | 189,324 KB |
実行使用メモリ | 76,192 KB |
最終ジャッジ日時 | 2024-09-17 17:59:19 |
合計ジャッジ時間 | 16,936 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | WA | - |
testcase_02 | AC | 2 ms
6,944 KB |
testcase_03 | AC | 3 ms
6,940 KB |
testcase_04 | AC | 8 ms
6,940 KB |
testcase_05 | AC | 28 ms
9,124 KB |
testcase_06 | AC | 10 ms
6,940 KB |
testcase_07 | AC | 22 ms
6,940 KB |
testcase_08 | AC | 10 ms
6,940 KB |
testcase_09 | AC | 48 ms
14,040 KB |
testcase_10 | AC | 11 ms
6,940 KB |
testcase_11 | AC | 70 ms
15,880 KB |
testcase_12 | AC | 12 ms
6,940 KB |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | AC | 3 ms
6,940 KB |
testcase_30 | WA | - |
testcase_31 | AC | 4 ms
6,940 KB |
testcase_32 | AC | 265 ms
26,836 KB |
testcase_33 | AC | 176 ms
25,556 KB |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | TLE | - |
testcase_39 | -- | - |
testcase_40 | -- | - |
testcase_41 | -- | - |
testcase_42 | -- | - |
testcase_43 | -- | - |
testcase_44 | -- | - |
ソースコード
#include <bits/stdc++.h> using namespace std; void dfs(vector<int> &ans, bool &ok, int &cnt, vector<unsigned long long> &hash, vector<unsigned long long> &ng, vector<int> &curr, unsigned long long ch, int sz, int p){ if (p == cnt){ if (curr.size() == sz){ auto itr = lower_bound(ng.begin(), ng.end(), ch); if (itr == ng.end()){ ans = curr; ok = true; } else if (*itr != ch){ ans = curr; ok = true; } } } else { dfs(ans, ok, cnt, hash, ng, curr, ch, sz, p + 1); if (ok){ return; } if (curr.size() < sz){ curr.push_back(p); dfs(ans, ok, cnt, hash, ng, curr, ch ^ hash[p], sz, p + 1); curr.pop_back(); } } } int main(){ mt19937 mt(chrono::steady_clock::now().time_since_epoch().count()); int N; cin >> N; vector<int> m(N); vector<vector<int>> p(N), e(N); for (int i = 0; i < N; i++){ cin >> m[i]; p[i] = vector<int>(m[i]); e[i] = vector<int>(m[i]); for (int j = 0; j < m[i]; j++){ cin >> p[i][j] >> e[i][j]; } } vector<int> P; for (int i = 0; i < N; i++){ for (int j = 0; j < m[i]; j++){ P.push_back(p[i][j]); } } sort(P.begin(), P.end()); P.erase(unique(P.begin(), P.end()), P.end()); int cnt = P.size(); for (int i = 0; i < N; i++){ for (int j = 0; j < m[i]; j++){ p[i][j] = lower_bound(P.begin(), P.end(), p[i][j]) - P.begin(); } } vector<int> mx(cnt, -1); for (int i = 0; i < N; i++){ for (int j = 0; j < m[i]; j++){ mx[p[i][j]] = max(mx[p[i][j]], e[i][j]); } } vector<vector<int>> s(N); for (int i = 0; i < N; i++){ for (int j = 0; j < m[i]; j++){ if (mx[p[i][j]] == e[i][j]){ s[i].push_back(p[i][j]); } } } bool ok = true; for (int i = 0; i < N; i++){ if (s[i].size() == cnt){ ok = false; } } if (!ok){ cout << -1 << endl; } else { vector<unsigned long long> hash(cnt, 0); for (int i = 0; i < cnt; i++){ for (int j = 0; j < 64; j++){ hash[i] *= 2; hash[i] += mt() % 2; } } vector<unsigned long long> ng; for (int i = 0; i < N; i++){ int cnt2 = s[i].size(); for (int j = 0; j < (1 << cnt2); j++){ int sz = __builtin_popcount(j); unsigned long long S = 0; for (int k = 0; k < cnt2; k++){ S ^= hash[s[i][k]]; } ng.push_back(S); } } sort(ng.begin(), ng.end()); ng.erase(unique(ng.begin(), ng.end()), ng.end()); vector<int> ans; for (int i = 1; i <= 10; i++){ vector<int> curr; unsigned long long chh = 0; bool ok2 = false; dfs(ans, ok2, cnt, hash, ng, curr, chh, i, 0); if (ok2){ break; } } vector<int> A(N, 1); for (int i = 0; i < N; i++){ for (int j = 0; j < m[i]; j++){ for (int k = 0; k < e[i][j]; k++){ A[i] *= P[p[i][j]]; } } } int k = ans.size(); vector<vector<int>> S(k); for (int i = 0; i < N; i++){ for (int j = 0; j < k; j++){ bool ok2 = true; int cnt2 = s[i].size(); for (int l = 0; l < cnt2; l++){ if (s[i][l] == ans[j]){ ok2 = false; } } if (ok2){ S[j].push_back(A[i]); break; } } } cout << k << endl; for (int i = 0; i < k; i++){ int n = S[i].size(); cout << n; for (int j = 0; j < n; j++){ cout << ' ' << S[i][j]; } cout << endl; } } }