QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#189985 | #4922. 生活在对角线下 | hos_lyric# | 10 | 112ms | 92124kb | C++14 | 6.2kb | 2023-09-28 04:00:14 | 2024-07-04 02:10:49 |
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 = 998244353;
using Mint = ModInt<MO>;
constexpr int LIM_INV = 400'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;
}
}
}
Mint path(int dx, int dy) {
return (dx >= 0 && dy >= 0) ? (fac[dx + dy] * invFac[dx] * invFac[dy]) : 0;
}
constexpr int MAX_T = 100'010;
constexpr int MAX_PQ = 10;
int T, C, P, Q, L;
int N[MAX_T], M[MAX_T];
Mint F[MAX_T][MAX_PQ];
namespace brute {
constexpr int SMALL = 1010;
Mint g[SMALL][SMALL];
Mint dp[MAX_PQ][SMALL][SMALL][2];
vector<Mint> run() {
memset(dp, 0, sizeof(dp));
for (int p = 0; p < P; ++p) for (int q = 0; q < Q; ++q) {
const int id = p * Q + q;
dp[id][0][0][0] = 1;
for (int x = 0; x <= L; ++x) for (int y = 0; y <= L + C; ++y) {
if (y <= x) {
dp[id][x][y][1] += dp[id][x][y][0] * Mint(x).pow(p) * Mint(y).pow(q);
}
dp[id][x + 1][y][0] += dp[id][x][y][0];
dp[id][x + 1][y][1] += dp[id][x][y][1];
dp[id][x][y + 1][0] += dp[id][x][y][0];
dp[id][x][y + 1][1] += dp[id][x][y][1];
}
// cerr<<"p = "<<p<<", q = "<<q<<endl;
// for(int x=0;x<=L;++x){for(int y=0;y<=L+C;++y)cerr<<dp[id][x][y][0]<<","<<dp[id][x][y][1]<<" ";cerr<<endl;}
}
vector<Mint> ans(T, 0);
for (int t = 0; t < T; ++t) {
for (int p = 0; p < P; ++p) for (int q = 0; q < Q; ++q) {
const int id = p * Q + q;
ans[t] += F[t][id] * dp[id][N[t]][M[t]][1];
}
}
return ans;
}
} // brute
int main() {
for (; ~scanf("%d%d%d%d%d", &T, &C, &P, &Q, &L); ) {
++P;
++Q;
for (int t = 0; t < T; ++t) {
scanf("%d%d", &N[t], &M[t]);
assert(N[t] + C == M[t]);
for (int p = 0; p < P; ++p) for (int q = 0; q < Q; ++q) {
scanf("%u", &F[t][p * Q + q].x);
}
}
const auto ans = brute::run();
for (int t = 0; t < T; ++t) {
printf("%u\n", ans[t].x);
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 1
Accepted
Test #1:
score: 1
Accepted
time: 29ms
memory: 91732kb
input:
1 -10 1 2 1000 825 815 107973512 400177523 812303207 164088430 603506669 337780072
output:
360076089
result:
ok 1 number(s): "360076089"
Test #2:
score: 0
Accepted
time: 26ms
memory: 88476kb
input:
1 424 1 4 576 130 554 926445673 393820912 634481616 292175028 733650737 100427548 899689095 876811717 849191704 696040532
output:
564712546
result:
ok 1 number(s): "564712546"
Test #3:
score: 0
Accepted
time: 36ms
memory: 89788kb
input:
1 -171 2 1 1000 805 634 250066876 719653007 284194184 531322789 491311782 185842441
output:
910556244
result:
ok 1 number(s): "910556244"
Test #4:
score: 0
Accepted
time: 58ms
memory: 91488kb
input:
1 11 4 1 989 142 153 581558550 138798754 575233123 788754497 582314564 303591688 635874631 658261955 615116681 498307457
output:
918405181
result:
ok 1 number(s): "918405181"
Test #5:
score: 0
Accepted
time: 41ms
memory: 88152kb
input:
1 -87 1 2 1000 164 77 264180617 338145439 610918500 800846696 216126209 112962819
output:
629819261
result:
ok 1 number(s): "629819261"
Subtask #2:
score: 9
Accepted
Dependency #1:
100%
Accepted
Test #6:
score: 9
Accepted
time: 96ms
memory: 92124kb
input:
100000 -99 2 1 1000 712 613 238230707 820405654 473765646 826816733 751513618 421153458 209 110 22075351 398854663 148159396 487281124 972932017 200517786 383 284 22252771 205525630 491328752 607545155 561318911 135661425 929 830 156478040 89922795 380802607 32081978 898588032 110586958 956 857 4206...
output:
863094157 570366074 281608243 247495628 396961441 855444791 694374848 782506902 280202079 688077364 610676536 115373962 360154110 834242083 887647721 164293717 759683961 710870451 213441970 863772654 514218158 532711794 558875294 421795761 517787006 458381459 506983637 742686106 435175768 111255264 ...
result:
ok 100000 numbers
Test #7:
score: 0
Accepted
time: 112ms
memory: 91996kb
input:
100000 252 3 1 748 130 382 311369319 709099006 49474431 724072531 761415026 251406187 389170658 169808960 581 833 89779535 938252574 504798466 677842435 654289171 763708659 719082912 762770851 691 943 571693157 187035992 300995260 403041189 726726538 63983502 814000657 315732021 121 373 339102104 42...
output:
516270157 614211606 655396807 981733406 752565578 312973289 850750616 826813023 753739511 227580123 199177890 403714939 559334967 370464926 363937285 583678656 239132195 834163477 111915553 68813179 875627540 299872127 660063389 31474925 464946255 125818391 645016505 267670615 440441568 356463850 84...
result:
ok 100000 numbers
Test #8:
score: 0
Accepted
time: 112ms
memory: 91612kb
input:
100000 195 2 2 805 325 520 266481322 663615421 428019284 968378746 158386978 211891009 161987045 142931644 790431809 621 816 756898302 952132541 196745128 424307295 926376261 130425563 604844618 645296808 252920984 60 255 873310227 887037637 787608776 98214115 355810775 242821836 537250851 650821017...
output:
922269244 757786754 400099571 332972619 780501723 469958234 540206804 924583388 519189002 566620024 244468115 73221163 663221021 159111716 451144022 658783977 656844692 831466434 186871631 60740257 542611012 773315130 755261907 193772041 628947709 363111530 452621670 349808610 264947076 342250907 16...
result:
ok 100000 numbers
Subtask #3:
score: 0
Time Limit Exceeded
Test #9:
score: 0
Time Limit Exceeded
input:
1 4683 0 0 95317 86560 91243 412303217
output:
result:
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #3:
0%
Subtask #6:
score: 0
Time Limit Exceeded
Test #41:
score: 0
Time Limit Exceeded
input:
100000 0 2 1 100000 48964 48964 666670967 90494987 74847122 615108201 29533064 582540229 14418 14418 391779909 223696706 701170191 885097597 551643398 25626747 81584 81584 951326734 520293397 13860946 896899117 821166399 282263457 76849 76849 598606953 879771697 930252135 671750715 673503431 3060699...
output:
result:
Subtask #7:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
0%