QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#185475 | #4908. 完全表示 | hos_lyric# | 35 | 21ms | 7060kb | C++14 | 7.2kb | 2023-09-22 09:03:48 | 2024-07-04 02:06:38 |
Judging History
answer
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")
////////////////////////////////////////////////////////////////////////////////
template <unsigned M_> struct ModInt {
static constexpr unsigned M = M_;
unsigned x;
constexpr ModInt() : x(0U) {}
constexpr ModInt(unsigned x_) : x(x_ % M) {}
constexpr ModInt(unsigned long long x_) : x(x_ % M) {}
constexpr ModInt(int x_) : x(((x_ %= static_cast<int>(M)) < 0) ? (x_ + static_cast<int>(M)) : x_) {}
constexpr ModInt(long long x_) : x(((x_ %= static_cast<long long>(M)) < 0) ? (x_ + static_cast<long long>(M)) : x_) {}
ModInt &operator+=(const ModInt &a) { x = ((x += a.x) >= M) ? (x - M) : x; return *this; }
ModInt &operator-=(const ModInt &a) { x = ((x -= a.x) >= M) ? (x + M) : x; return *this; }
ModInt &operator*=(const ModInt &a) { x = (static_cast<unsigned long long>(x) * a.x) % M; return *this; }
ModInt &operator/=(const ModInt &a) { return (*this *= a.inv()); }
ModInt pow(long long e) const {
if (e < 0) return inv().pow(-e);
ModInt a = *this, b = 1U; for (; e; e >>= 1) { if (e & 1) b *= a; a *= a; } return b;
}
ModInt inv() const {
unsigned a = M, b = x; int y = 0, z = 1;
for (; b; ) { const unsigned q = a / b; const unsigned c = a - q * b; a = b; b = c; const int w = y - static_cast<int>(q) * z; y = z; z = w; }
assert(a == 1U); return ModInt(y);
}
ModInt operator+() const { return *this; }
ModInt operator-() const { ModInt a; a.x = x ? (M - x) : 0U; return a; }
ModInt operator+(const ModInt &a) const { return (ModInt(*this) += a); }
ModInt operator-(const ModInt &a) const { return (ModInt(*this) -= a); }
ModInt operator*(const ModInt &a) const { return (ModInt(*this) *= a); }
ModInt operator/(const ModInt &a) const { return (ModInt(*this) /= a); }
template <class T> friend ModInt operator+(T a, const ModInt &b) { return (ModInt(a) += b); }
template <class T> friend ModInt operator-(T a, const ModInt &b) { return (ModInt(a) -= b); }
template <class T> friend ModInt operator*(T a, const ModInt &b) { return (ModInt(a) *= b); }
template <class T> friend ModInt operator/(T a, const ModInt &b) { return (ModInt(a) /= b); }
explicit operator bool() const { return x; }
bool operator==(const ModInt &a) const { return (x == a.x); }
bool operator!=(const ModInt &a) const { return (x != a.x); }
friend std::ostream &operator<<(std::ostream &os, const ModInt &a) { return os << a.x; }
};
////////////////////////////////////////////////////////////////////////////////
constexpr unsigned MO = 164511353;
using Mint = ModInt<MO>;
constexpr int LIM_INV = 200'010;
Mint inv[LIM_INV], fac[LIM_INV], invFac[LIM_INV];
void prepare() {
inv[1] = 1;
for (int i = 2; i < LIM_INV; ++i) {
inv[i] = -((Mint::M / i) * inv[Mint::M % i]);
}
fac[0] = invFac[0] = 1;
for (int i = 1; i < LIM_INV; ++i) {
fac[i] = fac[i - 1] * i;
invFac[i] = invFac[i - 1] * inv[i];
}
}
Mint binom(Int n, Int k) {
if (n < 0) {
if (k >= 0) {
return ((k & 1) ? -1 : +1) * binom(-n + k - 1, k);
} else if (n - k >= 0) {
return (((n - k) & 1) ? -1 : +1) * binom(-k - 1, n - k);
} else {
return 0;
}
} else {
if (0 <= k && k <= n) {
assert(n < LIM_INV);
return fac[n] * invFac[k] * invFac[n - k];
} else {
return 0;
}
}
}
int N, Q, M;
int T;
namespace brute_t1 {
int V;
vector<vector<int>> ADD;
vector<vector<int>> pss;
vector<Mint> pw;
Mint ans;
void dfs(int u, int chosen, int spanning) {
if (u == V) {
if (spanning == (1 << V) - 1) {
const int pop = __builtin_popcount(chosen);
ans += pw[pop];
}
} else {
dfs(u + 1, chosen, spanning);
int ne = 0;
for (int v = 0; v < V; ++v) if (spanning >> v & 1) {
ne |= pss[u][v];
}
dfs(u + 1, chosen | 1 << u, ne);
}
}
Mint run() {
vector<int> QQ(N + 1);
QQ[0] = 1;
for (int i = 1; i <= N; ++i) {
QQ[i] = QQ[i - 1] * Q;
}
V = QQ[N];
ADD.assign(V, vector<int>(V));
for (int u = 0; u < V; ++u) for (int v = 0; v < V; ++v) {
int w = 0;
for (int i = 0; i < N; ++i) {
const int ux = u / QQ[i] % Q;
const int vx = v / QQ[i] % Q;
const int wx = (ux + vx) % Q;
w += wx * QQ[i];
}
ADD[u][v] = w;
}
pss.assign(V, vector<int>(V, 0));
for (int u = 0; u < V; ++u) {
for (int v = 0; v < V; ++v) {
int w = v;
for (int q = 0; q < Q; ++q) {
pss[u][v] |= 1 << w;
w = ADD[w][u];
}
}
}
pw.resize(V + 1);
for (int pop = 0; pop <= V; ++pop) {
pw[pop] = Mint(pop).pow(M);
}
ans = 0;
dfs(0, 0, 1);
return ans;
}
} // brute_t1
namespace field_m0 {
vector<Mint> QQ, QQ2;
int ord;
vector<Mint> fs;
Mint qbinom(int n, int k) {
const int nq = n / ord, nr = n % ord;
const int kq = k / ord, kr = k % ord;
if (kr > nr) return 0;
return binom(nq, kq) * (fs[nr] / (fs[kr] * fs[nr - kr]));
}
Mint run() {
QQ.resize(N + 1);
QQ2.resize(N + 1);
QQ[0] = 1;
QQ2[0] = 1;
for (int i = 1; i <= N; ++i) {
QQ[i] = QQ[i - 1] * Q;
QQ2[i] = QQ2[i - 1] * QQ[i - 1];
}
ord = N + 1;
for (int i = 1; i <= N; ++i) {
if (QQ[i] == 1) {
ord = i;
break;
}
}
cerr<<"ord = "<<ord<<endl;
fs.resize(ord);
fs[0] = 1;
for (int i = 1; i < ord; ++i) {
fs[i] = fs[i - 1] * (QQ[i] - 1);
}
Mint ans = 0;
{
// 2^(Q^k)
Mint two = 2;
for (int k = 0; k <= N; ++k) {
ans += (((N-k)&1)?-1:+1) * QQ2[N - k] * qbinom(N, k) * two;
two = two.pow(Q);
}
}
return ans;
}
} // field_m0
int main() {
prepare();
for (; ~scanf("%d%d%d", &N, &Q, &M); ) {
scanf("%d", &T);
assert(T == 1);
int qq = 1;
for (int i = 0; i < N; ++i) {
chmin(qq *= Q, 21);
}
Mint ans = 0;
if (T == 1 && qq <= 20) {
cerr<<"<brute_t1>"<<endl;
ans = brute_t1::run();
} else if (M == 0) {
cerr<<"<field_m0>"<<endl;
ans = field_m0::run();
}
printf("%u\n", ans.x);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 0ms
memory: 6148kb
input:
2 3 665 1
output:
51745605
result:
ok "51745605"
Test #2:
score: 0
Accepted
time: 0ms
memory: 6128kb
input:
2 4 641 1
output:
54153482
result:
ok "54153482"
Test #3:
score: 0
Accepted
time: 3ms
memory: 6408kb
input:
1 6 656 1
output:
119347748
result:
ok "119347748"
Test #4:
score: 0
Accepted
time: 3ms
memory: 6444kb
input:
1 8 170 1
output:
126971959
result:
ok "126971959"
Test #5:
score: 0
Accepted
time: 3ms
memory: 6408kb
input:
1 9 816 1
output:
14287284
result:
ok "14287284"
Test #6:
score: 0
Accepted
time: 3ms
memory: 6212kb
input:
1 12 233 1
output:
37178137
result:
ok "37178137"
Test #7:
score: 0
Accepted
time: 4ms
memory: 6408kb
input:
1 16 244 1
output:
91022688
result:
ok "91022688"
Test #8:
score: 0
Accepted
time: 5ms
memory: 6156kb
input:
1 18 218 1
output:
93037058
result:
ok "93037058"
Test #9:
score: 0
Accepted
time: 12ms
memory: 6168kb
input:
1 19 645 1
output:
53944276
result:
ok "53944276"
Test #10:
score: 0
Accepted
time: 17ms
memory: 6152kb
input:
1 20 333 1
output:
81197702
result:
ok "81197702"
Test #11:
score: 0
Accepted
time: 0ms
memory: 6152kb
input:
1 2 893 1
output:
17672119
result:
ok "17672119"
Test #12:
score: 0
Accepted
time: 8ms
memory: 6188kb
input:
1 19 887 1
output:
58567516
result:
ok "58567516"
Test #13:
score: 0
Accepted
time: 3ms
memory: 6148kb
input:
2 3 504 1
output:
60763909
result:
ok "60763909"
Subtask #2:
score: 15
Accepted
Test #14:
score: 15
Accepted
time: 3ms
memory: 6148kb
input:
19 90203 0 1
output:
142145213
result:
ok "142145213"
Test #15:
score: 0
Accepted
time: 3ms
memory: 6448kb
input:
18 9697 0 1
output:
153592927
result:
ok "153592927"
Test #16:
score: 0
Accepted
time: 3ms
memory: 6152kb
input:
20 41 0 1
output:
112957727
result:
ok "112957727"
Test #17:
score: 0
Accepted
time: 3ms
memory: 6128kb
input:
20 99991 0 1
output:
151341559
result:
ok "151341559"
Subtask #3:
score: 5
Accepted
Dependency #2:
100%
Accepted
Test #18:
score: 5
Accepted
time: 3ms
memory: 6200kb
input:
999 9749 0 1
output:
77370298
result:
ok "77370298"
Test #19:
score: 0
Accepted
time: 3ms
memory: 6420kb
input:
997 55103 0 1
output:
92054017
result:
ok "92054017"
Test #20:
score: 0
Accepted
time: 0ms
memory: 6164kb
input:
1000 41 0 1
output:
6438830
result:
ok "6438830"
Test #21:
score: 0
Accepted
time: 0ms
memory: 6180kb
input:
1000 99991 0 1
output:
31676606
result:
ok "31676606"
Subtask #4:
score: 5
Accepted
Dependency #3:
100%
Accepted
Test #22:
score: 5
Accepted
time: 20ms
memory: 7060kb
input:
99996 20089 0 1
output:
163612442
result:
ok "163612442"
Test #23:
score: 0
Accepted
time: 15ms
memory: 7048kb
input:
99996 17707 0 1
output:
109099283
result:
ok "109099283"
Test #24:
score: 0
Accepted
time: 16ms
memory: 6952kb
input:
100000 41 0 1
output:
131161322
result:
ok "131161322"
Test #25:
score: 0
Accepted
time: 21ms
memory: 6964kb
input:
100000 99991 0 1
output:
84487741
result:
ok "84487741"
Subtask #5:
score: 0
Wrong Answer
Test #26:
score: 0
Wrong Answer
time: 3ms
memory: 6112kb
input:
998 24 0 1
output:
109954642
result:
wrong answer 1st words differ - expected: '75129854', found: '109954642'
Subtask #6:
score: 0
Skipped
Dependency #4:
100%
Accepted
Dependency #5:
0%
Subtask #7:
score: 0
Skipped
Dependency #6:
0%
Subtask #8:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #7:
0%
Subtask #9:
score: 0
Runtime Error
Test #46:
score: 0
Runtime Error
input:
99997 3 997 2 0 1 2 1 2 0 2 0 1 0 0 0 0 1 2 0 2 1