QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#405487 | #7613. Inverse Problem | ucup-team3215 | WA | 56ms | 5072kb | C++20 | 3.4kb | 2024-05-06 00:57:54 | 2024-05-06 00:57:56 |
Judging History
answer
#include <algorithm>
#include <cstdint>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
constexpr int mod = 1e9 + 7, cut = 6;
auto& mul(auto&& a, auto b) { return a = a * (uint64_t) b % mod; }
int inv(int a) { for (int r = 1, b = mod - 2; ; b /= 2, mul(a, a)) if (!b) return r; else if (b % 2) mul(r, a); }
using namespace std;
template <typename K, typename V, int mlf = 4>
struct HT {
int capacity;
vector<pair<K, int>> knx;
vector<V> values;
vector<int> head;
HT(): capacity{4 * mlf}, head(capacity, -1) {
}
void emplace(K k, V v) {
knx.push_back({k, head[k & capacity - 1]});
values.push_back(v);
head[k & capacity - 1] = knx.size() - 1;
maybe_rehash();
}
int find(K k) {
for (int i = head[k & capacity - 1]; ~i; i = knx[i].second) if (knx[i].first == k) return i;
return -1;
}
void clear() {
knx.clear();
values.clear();
head.assign(capacity, -1);
}
void maybe_rehash() {
if (knx.size() * mlf <= capacity) return;
head.assign(capacity *= 2, -1);
for (int i = 0; i < knx.size(); ++i) {
knx[i].second = head[knx[i].first & capacity - 1];
head[knx[i].first & capacity - 1] = i;
}
}
};
vector<HT<int, vector<int>>> high(1);
vector<int> inv_(1);
void gen_high(int n0, int n1, int n, int c, int p, auto&& cur) {
high[n1 - n].emplace(p, cur);
for (; c > cut; --c) if (c <= n) {
int np = p;
for (int i = 0; i < c; ++i) mul(np, inv_[n0 - i]);
cur.push_back(c);
gen_high(n0, n1, n - c, c, np, cur);
cur.pop_back();
}
}
vector<int> qs;
vector<vector<int>> ans;
void solve(int n0, int n, int c, int p, auto&& cur) {
for (int i = 0; i < qs.size(); ++i) if (ans[i].empty() && ~high[n].find(mul(+p, qs[i]))) {
ans[i] = cur;
auto& t = high[n].values[high[n].find(mul(+p, qs[i]))];
ans[i].insert(ans[i].end(), t.begin(), t.end());
}
for (; c > 0; --c) if (c <= n) {
int np = p;
for (int i = 0; i < c; ++i) mul(np, n0 - i);
cur.push_back(c);
solve(n0, n - c, c, np, cur);
cur.pop_back();
}
}
int main() {
int tc; cin >> tc;
qs.resize(tc);
ans.resize(tc);
for (int i = 0; i < tc; ++i) {
qs[i] = i + 1;
if (qs[i] == 1) ans[i] = {-1};
else if (qs[i] == 2) ans[i] = {-1};
qs[i] = inv(qs[i]);
}
for (int n = 1, done = 0; !done++; ++n) {
if (n % 2 == 1) {
inv_.push_back(inv(n));
inv_.push_back(inv(n + 1));
high.push_back({});
high.push_back({});
for (auto& x: high) x.clear();
gen_high(n, n + 1, n + 1, n + 1, 1, vector<int>{});
} else for (int i = 0; i <= n; ++i) {
high[i].head.assign(high[i].capacity, -1);
for (int j = 0; j < high[i].knx.size(); ++j) {
int key = 1;
for (auto x: high[i].values[j]) mul(key, n - x);
high[i].knx[j] = {key, high[i].head[key & high[i].capacity - 1]};
high[i].head[key & high[i].capacity - 1] = j;
}
}
solve(n, n, cut, mul(n + 1, n + 2), vector<int>{});
for (int i = 0; i < tc; ++i) done &= !ans[i].empty();
}
for (int i = 0; i < tc; ++i) {
if (qs[i] == 1) cout << "1\n";
else {
if (ans[i][0] == -1) ans[i] = {};
cout << accumulate(ans[i].begin(), ans[i].end(), 0) + 2 << '\n' << "1 2\n";
for (int j = 0, k = 2; j < ans[i].size(); ++j)
while (ans[i][j]--) cout << j + 1 << ' ' << ++k << '\n';
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 56ms
memory: 5072kb
input:
4 2 360 1 509949433
output:
1 2 1 2 66 1 2 1 3 1 4 2 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 4 22 4 23 4 24 4 25 4 26 4 27 4 28 4 29 4 30 4 31 4 32 4 33 4 34 4 35 4 36 4 37 5 38 5 39 5 40 5 41 5 42 5 43 5 44 5 45 5 46 5 47 5 48 5 49 6 50 6 51 6 52 6 53 6 54 6 55 6 56 6 57 6 58 7 59 7 60 7 ...
result:
wrong answer Liczba kolorowań jest błędna!