QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#734790 | #9572. Bingo | MiniLong | WA | 242ms | 37220kb | C++20 | 5.1kb | 2024-11-11 15:08:09 | 2024-11-11 15:08:10 |
Judging History
answer
#include <bits/stdc++.h>
#define _rep(i, x, y) for(int i = x; i <= y; ++i)
#define _req(i, x, y) for(int i = x; i >= y; --i)
#define _rev(i, u) for(int i = head[u]; i; i = e[i].nxt)
#define pb push_back
#define fi first
#define se second
#define mst(f, i) memset(f, i, sizeof f)
using namespace std;
#ifdef ONLINE_JUDGE
#define debug(...) 0
#else
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#endif
typedef long long ll;
typedef pair<int, int> PII;
namespace fastio{
char ibuf[1 << 20],*p1 = ibuf, *p2 = ibuf;
#define get() p1 == p2 && (p2 = (p1 = ibuf) + fread(ibuf, 1, 1 << 20, stdin), p1 == p2) ? EOF : *p1++
template<typename T> inline void read(T &t){
T x = 0, f = 1;
char c = getchar();
while(!isdigit(c)){
if(c == '-') f = -f;
c = getchar();
}
while(isdigit(c)) x = x * 10 + c - '0', c = getchar();
t = x * f;
}
template<typename T, typename ... Args> inline void read(T &t, Args&... args){
read(t);
read(args...);
}
template<typename T> void write(T t){
if(t < 0) putchar('-'), t = -t;
if(t >= 10) write(t / 10);
putchar(t % 10 + '0');
}
template<typename T, typename ... Args> void write(T t, Args... args){
write(t), putchar(' '), write(args...);
}
template<typename T> void writeln(T t){
write(t);
puts("");
}
template<typename T> void writes(T t){
write(t), putchar(' ');
}
#undef get
};
using namespace fastio;
#define multitest() int T; read(T); _rep(tCase, 1, T)
namespace Calculation{
const ll mod = 998244353;
ll ksm(ll p, ll h){ll base = p % mod, res = 1; while(h){if(h & 1ll) res = res * base % mod; base = base * base % mod, h >>= 1ll;} return res;}
void dec(ll &x, ll y){x = ((x - y) % mod + mod) % mod;}
void add(ll &x, ll y){x = (x + y) % mod;}
void mul(ll &x, ll y){x = x * y % mod;}
ll sub(ll x, ll y){return ((x - y) % mod + mod) % mod;}
ll pls(ll x, ll y){return ((x + y) % mod + mod) % mod;}
ll mult(ll x, ll y){return x * y % mod;}
}
using namespace Calculation;
const int N = 2e5 + 5, _ = 2e5;
int n, m, len, a[N], lsh[N], cnt[N];
ll fac[N], ifac[N];
ll C(ll n, ll m){
if(n < m || m < 0) return 0;
if(n == m || !m) return 1;
return fac[n] * ifac[m] % mod * ifac[n - m] % mod;
}
ll f[N], g[N], h[N];
namespace PolyNomial{
const int G = 3;
void pmul(ll *a, ll *b, int n){_rep(i, 0, n) a[i] = 1ll * a[i] * b[i] % mod;}
void NTT(ll *a, int n){
static ll f[N << 2], prebuf[N << 2];
static int tr[N << 2];
_rep(i, 0, n - 1) tr[i] = (tr[i >> 1] >> 1) | ((i & 1) ? (n >> 1) : 0), f[i] = a[i];
_rep(i, 0, n - 1) if(i < tr[i]) swap(f[i], f[tr[i]]);
for(int len = 2; len <= n; len <<= 1){
int p = len >> 1;
ll buf = ksm(G, (mod - 1) / len);
prebuf[0] = 1; _rep(i, 1, p - 1) prebuf[i] = prebuf[i - 1] * buf % mod;
for(int k = 0; k < n; k += len){
_rep(i, 0, p - 1){
ll cur = f[i | k | p] % mod * prebuf[i] % mod;
f[i | k | p] = f[i | k] + mod - cur;
f[i | k] += cur;
}
}
}
_rep(i, 0, n - 1) a[i] = f[i] % mod, f[i] = 0;
}
void INTT(ll *a, int n){
NTT(a, n), reverse(a + 1, a + n); ll invn = ksm(n, mod - 2);
_rep(i, 0, n - 1) a[i] = 1ll * a[i] * invn % mod;
}
void mul(ll *a, ll *b, int n, int m){
static ll f[N << 2], g[N << 2];
int lim = 1; for(; lim <= n + m; lim <<= 1);
_rep(i, 0, n) f[i] = a[i]; _rep(i, 0, m) g[i] = b[i];
NTT(f, lim), NTT(g, lim), pmul(f, g, lim - 1), INTT(f, lim);
_rep(i, 0, n + m) a[i] = f[i];
_rep(i, 0, lim - 1) f[i] = g[i] = 0;
}
}
int main(){
fac[0] = ifac[0] = fac[1] = ifac[1] = 1;
_rep(i, 2, _) fac[i] = fac[i - 1] * i % mod, ifac[i] = (mod - mod / i) * ifac[mod % i] % mod;
_rep(i, 2, _) ifac[i] = ifac[i - 1] * ifac[i] % mod;
multitest(){
read(n, m);
_rep(i, 1, n * m) read(a[i]), lsh[++len] = a[i];
sort(lsh + 1, lsh + 1 + len), len = unique(lsh + 1, lsh + 1 + len) - lsh - 1;
_rep(i, 1, n * m) a[i] = lower_bound(lsh + 1, lsh + 1 + len, a[i]) - lsh, cnt[a[i]]++;
_rep(i, 1, len) cnt[i] += cnt[i - 1];
ll ans = 0;
_rep(i, 0, n) _rep(j, 0, m){
ll cur = (i + j & 1) ? (mod - 1) : 1, t = i * m + j * n - i * j;
mul(cur, C(n, i) * C(m, j) % mod * fac[(n - i) * (m - j)] % mod * fac[t] % mod);
add(f[t], cur * ifac[t] % mod);
}
_rep(i, 0, n * m) g[i] = ifac[i];
PolyNomial::mul(f, g, n * m, n * m);
_rep(k, 1, len){
h[k] = f[cnt[k - 1]] * fac[cnt[k - 1]] % mod;
}
_rep(i, 1, len) add(ans, (h[i] - h[i + 1] + mod) % mod * lsh[i] % mod);
writeln(ans);
_rep(i, 1, len) f[i] = cnt[i] = 0;
_rep(i, 0, n * m * 2) f[i] = g[i] = h[i] = 0;
len = 0;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 17952kb
input:
4 2 2 1 3 2 4 3 1 10 10 10 1 3 20 10 30 3 4 1 1 4 5 1 4 1 9 1 9 8 10
output:
56 60 60 855346687
result:
ok 4 number(s): "56 60 60 855346687"
Test #2:
score: 0
Accepted
time: 5ms
memory: 20060kb
input:
1 2 2 0 0 998244352 998244352
output:
998244345
result:
ok 1 number(s): "998244345"
Test #3:
score: 0
Accepted
time: 72ms
memory: 20040kb
input:
900 1 1 810487041 1 2 569006976 247513378 1 3 424212910 256484544 661426830 1 4 701056586 563296095 702740883 723333858 1 5 725786515 738465053 821758167 170452477 34260723 1 6 204184507 619884535 208921865 898995024 768400582 369477346 1 7 225635227 321139203 724076812 439129905 405005469 369864252...
output:
810487041 495026756 540662911 541929691 118309348 270925149 575366228 709974238 761347712 304011276 14811741 366145628 638305530 240546928 484276475 603344008 926633861 161768904 239961447 329781933 315752584 578075668 259941994 600147169 402221164 890998500 154285994 181862417 47930994 273729619 64...
result:
ok 900 numbers
Test #4:
score: 0
Accepted
time: 101ms
memory: 22152kb
input:
400 1 995 548100968 635656907 177366910 971271357 314579375 529572241 948721678 455918644 95745688 164857981 499083775 827896554 496889261 111294651 646048809 758286431 163045934 917399362 189372614 267754648 966443706 921589740 228089960 473153545 482816423 37567957 495730380 864445591 568695110 78...
output:
954668084 677509135 636173666 415373646 477286237 209886549 398423120 24466622 672440292 390142124 498517438 305197486 239833057 500821845 475519894 347179487 974036742 810602822 75196204 48378743 393961176 290898056 957916898 434124418 663457674 225283495 704304053 338701802 670053839 137083082 165...
result:
ok 400 numbers
Test #5:
score: 0
Accepted
time: 149ms
memory: 18572kb
input:
40 92 99 14480275 12892621 932457558 584861415 926346518 101583802 498448003 884757899 463949215 661256632 872663851 651132350 565253214 18404795 810166895 145370572 123351313 298382303 777283720 775900024 613503856 817112784 713304484 541301622 595768594 550989875 960159831 571815058 777864097 3608...
output:
614712898 16225927 313765200 824491114 60971514 769510634 58341639 808667102 527187053 319496150 267177120 409701892 245708713 115397703 928197397 533118123 931076329 448328887 672878477 180728812 385639338 504093069 846218180 981546177 906805965 315620628 863877552 348963788 781585156 982673320 275...
result:
ok 40 numbers
Test #6:
score: 0
Accepted
time: 134ms
memory: 18568kb
input:
40 86 92 479103936 690362573 387313968 428679987 770097821 67859949 744428797 919332570 530162857 389639443 851979342 310332074 863845681 155743453 442066584 996725021 385646576 447381083 64960590 818019444 260564007 16381359 36238584 609449698 12466296 532193395 262308857 279184524 454814687 400578...
output:
147127348 995441625 947321329 200561175 846810174 626764591 235790337 30932003 384829067 254218916 20342301 451884441 634808121 241161955 246093492 515701050 978130791 502129313 3431507 775910032 464454612 153447682 53092548 316439192 101505498 40191013 225025922 133184210 209384134 330521977 360716...
result:
ok 40 numbers
Test #7:
score: -100
Wrong Answer
time: 242ms
memory: 37220kb
input:
2 447 447 790583748 764745604 779691526 67598288 308196334 738524513 685610494 336125979 294155123 651917356 898366384 420012139 529304950 133567869 630219750 62853597 606184670 383809162 43962071 826608376 652871696 860138865 675639996 444122802 823442992 841633845 125418467 211407031 726738308 984...
output:
506347658 0
result:
wrong answer 2nd numbers differ - expected: '891054810', found: '0'