QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#129810#4542. Cyber Painterbatrr#AC ✓2916ms34304kbC++172.5kb2023-07-23 00:57:282023-07-23 00:57:30

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-23 00:57:30]
  • Judged
  • Verdict: AC
  • Time: 2916ms
  • Memory: 34304kb
  • [2023-07-23 00:57:28]
  • Submitted

answer

#include <bits/stdc++.h>

#define f first
#define s second
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const int N = 300500, inf = 1e9, mod = 1000000007;
const ll INF = 1e18;

int sum(int a, int b) {
    a += b;
    if (a >= mod)
        a -= mod;
    return a;
}

int sub(int a, int b) {
    a -= b;
    if (a < 0)
        a += mod;
    return a;
}

int mult(int a, int b) {
    return 1ll * a * b % mod;
}

int bp(int a, int b) {
    int res = 1;
    while (b) {
        if (b & 1)
            res = mult(res, a);
        a = mult(a, a);
        b >>= 1;
    }
    return res;
}

int inv(int x) {
    return bp(x, mod - 2);
}

vector<ll> f, f2;

void prec()
{
    ll mx = 2000000;
    f.resize(mx+1), f2.resize(mx+1);
    f[0] = f2[0] = 1;
    for (ll i=1;i<=mx;i++) f[i] = f[i-1]*i%mod;
    f2[mx] = bp(f[mx],mod-2);
    for (ll i=mx;i>0;i--) f2[i-1] = f2[i]*i%mod;
}


vector<ll> M = {3,6,12,9};
ll n, m;
vector<ll> a(16);
ll A = 0;

void calc(ll S)
{
    ll Q1 = 0, Q2 = 0, Q = a[15];
    for (ll b=0;b<15;b++)
    {
        if ((b&5)==5) Q1 += a[b];
        if ((b&10)==10) Q2 += a[b];
    }
    ll mn = min(n,m);
    for (ll L2=0;L2+1<mn;L2++)
    {
        ll L = L2*2;
        ll W = 0;
        for (ll p=0;p<=L and p<=Q;p++)
        {
            if (Q1<L-p) continue;
            ll P = f[Q]*f2[p]%mod*f2[Q-p]%mod*f[Q1]%mod*f2[L-p]%mod*f2[Q1-L+p]%mod;
            ll d = Q-p+Q2;
            if (d<L) continue;
            P = P*f[d]%mod*f2[d-L]%mod*f2[L]%mod;
            P = P*f[L]%mod*f[L]%mod;
            W = (W+P)%mod;
        }
        A = (A+W*S%mod*f[n*m-2*L-4]%mod*(n-L2-1)*(m-L2-1))%mod;
    }
}

void rec(ll p, ll S)
{
    if (p==4)
    {
        calc(S);
        return;
    }
    for (ll x=0;x<16;x++)
    {
        if (a[x]<=0) continue;
        if ((x&M[p])!=M[p]) continue;
        a[x]--;
        rec(p+1,S*(a[x]+1)%mod);
        a[x]++;
    }
}

void solve() {
    A = 0;
    cin >> n >> m;
    for (ll i=0;i<16;i++) cin >> a[i];
    rec(0,1);
    A = A*f2[n*m]%mod;
    cout << A << "\n";
}

int main() {
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
#endif
    prec();
    ios_base::sync_with_stdio(false);
    int t = 1;
    cin >> t;
    for (int i = 1; i <= t; i++) {
//        cout << "Case #" << i << endl;
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2916ms
memory: 34304kb

input:

10000
2 1
0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0
3 1
1 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0
1 1
0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0
1 1
0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0
1 1
0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
1 3
0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0
1 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 3
0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0
1 2
1 ...

output:

0
0
0
0
0
0
0
0
0
0
0
0
597798962
194245930
834284364
543970328
906286314
479624062
0
0
0
466666670
604761909
0
496428575
0
0
384954093
0
942128054
0
57644305
0
407142860
0
0
0
903001318
0
0
611739135
303696306
189542485
0
38720539
0
0
0
708377124
0
0
205555557
0
0
296078035
0
380854853
0
0
0
146969...

result:

ok 10000 lines