QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#727313 | #4264. 普罗达科特 | TheZone | Compile Error | / | / | C++20 | 14.9kb | 2024-11-09 12:40:16 | 2024-11-09 12:40:17 |
Judging History
This is the latest submission verdict.
- [2024-11-09 12:40:17]
- Judged
- Verdict: Compile Error
- Time: 0ms
- Memory: 0kb
- [2024-11-09 12:40:16]
- Submitted
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 <random>
#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 = 1'000'000'021;
using Mint = ModInt<MO>;
constexpr int LIM_INV = 1010;
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;
}
}
}
////////////////////////////////////////////////////////////////////////////////
Mint interpolateIota(const vector<Mint> &fs, Mint x) {
const int fsLen = fs.size();
vector<Mint> prodR(fsLen + 1);
prodR[fsLen] = 1;
for (int i = fsLen; --i >= 0; ) prodR[i] = (x - i) * prodR[i + 1];
Mint ans = 0;
Mint prodL = 1;
for (int i = 0; i < fsLen; ++i) {
// (i - 0) ... (i - (i - 1)) (i - (i + 1)) ... (i - (fsLen - 1))
ans += invFac[i] * (((fsLen - 1 - i) & 1) ? -1 : +1) *
invFac[fsLen - 1 - i] * fs[i] * prodL * prodR[i + 1];
prodL *= (x - i);
}
return ans;
}
void exper() {
constexpr int K = 25;
set<int> dp[K + 1][K + 1];
dp[0][0].insert(1);
for (int k = 0; k < K; ++k) for (int f = 0; f <= k; ++f) {
for (const int l : dp[k][f]) {
for (int dk = 1; dk <= K - k; ++dk) {
dp[k + dk][f + 1].insert(l / __gcd(l, dk) * dk);
}
}
}
for (int k = 1; k <= K; ++k) {
int mx = 0;
for (int f = 1; f <= k; ++f) chmax(mx, *dp[k][f].rbegin() * f);
cerr << k << ": " << mx << ";";
for (int f = 1; f <= k; ++f) cerr << " " << *dp[k][f].rbegin();
cerr << endl;
}
}
/*
c: part of partition of K
1 / (1 - x^c)
PIE: (1 - x^((b+1)c)) / (1 - x^c)
*/
// max[partition of K] (lcm * length)
constexpr int LEN = 5040;
int N, K;
vector<Int> A, B;
vector<int> fs;
// [x^a] x^((b+1)i) / Q(x)
vector<vector<Mint>> at;
// P(x^(b+1)) / Q(x)
Mint sub(int c, Mint w, const vector<Mint> &ps) {
for (; c && !fs[c]; --c) {}
Mint ret = 0;
if (!c) {
ret = w;
for (int n = 0; n < N; ++n) {
Mint sum = 0;
for (int i = 0; i < (int)ps.size(); ++i) {
sum += ps[i] * at[n][i];
}
ret *= sum;
}
} else {
auto pps = ps;
for (int g = 0; ; ++g) {
ret += sub(c - 1, w * binom(fs[c], g) * (g&1?-1:+1), pps);
if (g == fs[c]) break;
pps.resize((int)pps.size() + c, 0);
for (int i = (int)pps.size(); --i >= c; ) pps[i] -= pps[i - c];
}
}
return ret;
}
Mint ans0, ans1;
// rs = (\prod[c] (1 / Q(x))) mod x^LEN
void dfs(int k, int c, int s, Mint w, const vector<Mint> &rs) {
if (!k) {
int l = 1, m = 0;
for (c = 1; c <= K; ++c) if (fs[c]) {
l = l / __gcd(l, c) * c;
m += fs[c];
}
assert(l * m <= LEN);
vector<vector<Mint>> rss(l, vector<Mint>(m));
for (int i = 0; i < l * m; ++i) rss[i % l][i / l] = rs[i];
at.assign(N, vector<Mint>(K + 1, 0));
for (int n = 0; n < N; ++n) {
Int a = A[n];
for (int i = 0; i <= K; ++i) {
at[n][i] = interpolateIota(rss[a % l], a / l);
if ((a -= (B[n] + 1)) < 0) break;
}
}
const Mint res = sub(K, 1, {1});
ans0 += s * w * res;
ans1 += w * res;
} else {
for (chmin(c, k); c; --c) {
int ss = s;
Mint ww = w;
auto rrs = rs;
int &f = fs[c];
for (f = 1; f * c <= k; ++f) {
if ((c-1)&1) ss = -ss;
ww *= inv[c];
ww *= inv[f];
for (int i = c; i < LEN; ++i) rrs[i] += rrs[i - c];
dfs(k - f * c, c - 1, ss, ww, rrs);
}
f = 0;
}
}
}
int main() {
prepare();
// exper();
for (; ~scanf("%d%d", &N, &K); ) {
A.resize(N); for (int n = 0; n < N; ++n) scanf("%lld", &A[n]);
B.resize(N); for (int n = 0; n < N; ++n) scanf("%lld", &B[n]);
fs.assign(K + 1, 0);
ans0 = ans1 = 0;
vector<Mint> rs(LEN, 0);
rs[0] = 1;
dfs(K, K, 1, 1, rs);
printf("%u %u\n", ans0.x, ans1.x);
}
return 0;
}
/*#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 <random>
#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 = 1'000'000'021;
using Mint = ModInt<MO>;
constexpr int LIM_INV = 1010;
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;
}
}
}
////////////////////////////////////////////////////////////////////////////////
Mint interpolateIota(const vector<Mint> &fs, Mint x) {
const int fsLen = fs.size();
vector<Mint> prodR(fsLen + 1);
prodR[fsLen] = 1;
for (int i = fsLen; --i >= 0; ) prodR[i] = (x - i) * prodR[i + 1];
Mint ans = 0;
Mint prodL = 1;
for (int i = 0; i < fsLen; ++i) {
// (i - 0) ... (i - (i - 1)) (i - (i + 1)) ... (i - (fsLen - 1))
ans += invFac[i] * (((fsLen - 1 - i) & 1) ? -1 : +1) *
invFac[fsLen - 1 - i] * fs[i] * prodL * prodR[i + 1];
prodL *= (x - i);
}
return ans;
}
void exper() {
constexpr int K = 25;
set<int> dp[K + 1][K + 1];
dp[0][0].insert(1);
for (int k = 0; k < K; ++k) for (int f = 0; f <= k; ++f) {
for (const int l : dp[k][f]) {
for (int dk = 1; dk <= K - k; ++dk) {
dp[k + dk][f + 1].insert(l / __gcd(l, dk) * dk);
}
}
}
for (int k = 1; k <= K; ++k) {
int mx = 0;
for (int f = 1; f <= k; ++f) chmax(mx, *dp[k][f].rbegin() * f);
cerr << k << ": " << mx << ";";
for (int f = 1; f <= k; ++f) cerr << " " << *dp[k][f].rbegin();
cerr << endl;
}
}
/*
c: part of partition of K
1 / (1 - x^c)
PIE: (1 - x^((b+1)c)) / (1 - x^c)
*/
// max[partition of K] (lcm * length)
constexpr int LEN = 5040;
int N, K;
vector<Int> A, B;
vector<int> fs;
// [x^a] x^((b+1)i) / Q(x)
vector<vector<Mint>> at;
// P(x^(b+1)) / Q(x)
Mint sub(int c, Mint w, const vector<Mint> &ps) {
for (; c && !fs[c]; --c) {}
Mint ret = 0;
if (!c) {
ret = w;
for (int n = 0; n < N; ++n) {
Mint sum = 0;
for (int i = 0; i < (int)ps.size(); ++i) {
sum += ps[i] * at[n][i];
}
ret *= sum;
}
} else {
auto pps = ps;
for (int g = 0; ; ++g) {
ret += sub(c - 1, w * binom(fs[c], g) * (g&1?-1:+1), pps);
if (g == fs[c]) break;
pps.resize((int)pps.size() + c, 0);
for (int i = (int)pps.size(); --i >= c; ) pps[i] -= pps[i - c];
}
}
return ret;
}
Mint ans0, ans1;
// rs = (\prod[c] (1 / Q(x))) mod x^LEN
void dfs(int k, int c, int s, Mint w, const vector<Mint> &rs) {
if (!k) {
int l = 1, m = 0;
for (c = 1; c <= K; ++c) if (fs[c]) {
l = l / __gcd(l, c) * c;
m += fs[c];
}
}
return 0;
}
*/
Details
answer.code:410:15: error: redefinition of ‘constexpr const int LEN’ 410 | constexpr int LEN = 5040; | ^~~ answer.code:158:15: note: ‘constexpr const int LEN’ previously defined here 158 | constexpr int LEN = 5040; | ^~~ answer.code:412:5: error: redefinition of ‘int N’ 412 | int N, K; | ^ answer.code:160:5: note: ‘int N’ previously declared here 160 | int N, K; | ^ answer.code:412:8: error: redefinition of ‘int K’ 412 | int N, K; | ^ answer.code:160:8: note: ‘int K’ previously declared here 160 | int N, K; | ^ answer.code:413:13: error: redefinition of ‘std::vector<long long int> A’ 413 | vector<Int> A, B; | ^ answer.code:161:13: note: ‘std::vector<long long int> A’ previously defined here 161 | vector<Int> A, B; | ^ answer.code:413:16: error: redefinition of ‘std::vector<long long int> B’ 413 | vector<Int> A, B; | ^ answer.code:161:16: note: ‘std::vector<long long int> B’ previously defined here 161 | vector<Int> A, B; | ^ answer.code:415:13: error: redefinition of ‘std::vector<int> fs’ 415 | vector<int> fs; | ^~ answer.code:163:13: note: ‘std::vector<int> fs’ previously defined here 163 | vector<int> fs; | ^~ answer.code:418:22: error: redefinition of ‘std::vector<std::vector<ModInt<1000000021> > > at’ 418 | vector<vector<Mint>> at; | ^~ answer.code:166:22: note: ‘std::vector<std::vector<ModInt<1000000021> > > at’ previously defined here 166 | vector<vector<Mint>> at; | ^~ answer.code:421:6: error: redefinition of ‘Mint sub(int, Mint, const std::vector<ModInt<1000000021> >&)’ 421 | Mint sub(int c, Mint w, const vector<Mint> &ps) { | ^~~ answer.code:169:6: note: ‘Mint sub(int, Mint, const std::vector<ModInt<1000000021> >&)’ previously defined here 169 | Mint sub(int c, Mint w, const vector<Mint> &ps) { | ^~~ answer.code:445:6: error: redefinition of ‘Mint ans0’ 445 | Mint ans0, ans1; | ^~~~ answer.code:193:6: note: ‘Mint ans0’ previously defined here 193 | Mint ans0, ans1; | ^~~~ answer.code:445:12: error: redefinition of ‘Mint ans1’ 445 | Mint ans0, ans1; | ^~~~ answer.code:193:12: note: ‘Mint ans1’ previously defined here 193 | Mint ans0, ans1; | ^~~~ answer.code:448:6: error: redefinition of ‘void dfs(int, int, int, Mint, const std::vector<ModInt<1000000021> >&)’ 448 | void dfs(int k, int c, int s, Mint w, const vector<Mint> &rs) { | ^~~ answer.code:196:6: note: ‘void dfs(int, int, int, Mint, const std::vector<ModInt<1000000021> >&)’ previously defined here 196 | void dfs(int k, int c, int s, Mint w, const vector<Mint> &rs) { | ^~~ answer.code: In function ‘void dfs(int, int, int, Mint, const std::vector<ModInt<1000000021> >&)’: answer.code:456:10: error: return-statement with a value, in function returning ‘void’ [-fpermissive] 456 | return 0; | ^ answer.code: At global scope: answer.code:458:2: error: expected unqualified-id before ‘/’ token 458 | */ | ^ answer.code: In function ‘int main()’: answer.code:240:51: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 240 | A.resize(N); for (int n = 0; n < N; ++n) scanf("%lld", &A[n]); | ~~~~~^~~~~~~~~~~~~~~ answer.code:241:51: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 241 | B.resize(N); for (int n = 0; n < N; ++n) scanf("%lld", &B[n]); | ~~~~~^~~~~~~~~~~~~~~