Contest Duration: ~ (local time) (120 minutes) Back to Home

Submission #601536

Source Code Expand

Copy
```#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define MODN 1000000007

ll memo[901][901];
ll combi(ll a, ll b) {
/* if (a < (b<<1)) b = a-b; */
if (a < b) return 0;
if (a <= 0) return 0;
if (a < b*2) b = a-b;
if (b == 0) return 1;
if (memo[a][b]) return memo[a][b];
if (b == 1) return a;
if (a == b) return 1;
return memo[a][b]=(combi(a-1, b-1)+combi(a-1, b))%MODN;
}

ll patternDL(ll d, ll l, ll x, ll y) {
if (d+l == x*y) return 1;
if (d+l == 1) return 1;
if (d+l == 2) {
if (x > 1 && y > 1) return 2;
return 1;
}
if (d+l == 3) {
while(1) {}
if (x > 1 && y > 1) return 2*combi(x*y-4, d+l-2)+4+((x-2)*(y-2))*4+(y-2)*2+(x-2)*2;
return combi(x*y-2, d+l-2);
}
if (x > 1 && y > 1) {
ll kadoP = (2*combi(x*y-4, d+l-2)+4*combi(x*y-4, d+l-3)+combi(x*y-4, d+l-4))%MODN;;
ll hen1 = 0, hen2 = 0, hen3 = 0, hen4 = 0;
for (ll i = 0; i <= y-3; i++) {
hen1 += combi(x*y-5-i, d+l-3);
}
hen1 = (hen1*2)%MODN;
for (ll i = 0; i <= x-3; i++) {
hen2 += combi(x*y-5-i, d+l-3);
}
hen2 = (hen2*2)%MODN;
for (ll i = 0; i <= x-3; i++) {
for (ll j = 0; j <= y-3; j++) {
hen3 += combi(x*y-6-i-j, d+l-3);
}
}
hen3 = (hen3*4)%MODN;
for (ll v1 = 0; v1 <= x-3; v1++) {
for (ll v2 = 0; v2 <= x-3; v2++) {
// for (ll v3 = 0; v3 <= y-3; v3++) {
//   for (ll v4 = 0; v4 <= y-3; v4++) {
//     hen4 += combi(x*y-8-v1-v2-v3-v4, d+l-4);
//     hen4 %= MODN;
//   }
// }
for (ll a = 1; a <= y-3+1; a++) {
hen4 += a*combi(x*y-8-v1-v2-(a-1), d+l-4);
}
for (ll a = y-3, b = y-3+1; a >= 1; a--, b++) {
hen4 += a*combi(x*y-8-v1-v2-b, d+l-4);
}
}
}
}
return combi(x*y-2, d+l-2);
}

ll patternXY(ll x, ll y, ll r, ll c) {
return (r-x+1)*(c-y+1);
}

ll solver(ll r, ll c, ll x, ll y, ll d, ll l) {
for (int i = 0; i <= 900; i++) {
for (int j = i; j <= 900; j++) {
combi(j, i);
}
}

ll ans = ((patternDL(d, l, x, y)*combi(d+l, d))%MODN)*patternXY(x, y, r, c);
return ans%MODN;
}

int main() {
ll r, c;
ll x, y;
ll d, l;
cin >> r >> c;
cin >> x >> y;
cin >> d >> l;

cout << solver(r, c, x, y, d, l) << endl;

return 0;
}
```

Submission Info

Submission Time 2015-12-29 00:48:36+0900 D - AtCoder社の冬 warm4C0 C++11 (GCC 4.8.1) 100 2435 Byte WA 53 ms 6068 KB

Test Cases

Set Name Score / Max Score Test Cases
sub 100 / 100 00_sample_01E.txt, 00_sample_02E.txt, 00_sample_03E.txt, test_03E.txt, test_04E.txt, test_07E.txt, test_08E.txt, test_11E.txt, test_12E.txt, test_15E.txt, test_16E.txt, test_19E.txt, test_20E.txt, test_23E.txt, test_24E.txt, test_27E.txt, test_28E.txt, test_31E.txt, test_32E.txt, test_36E.txt, test_37E.txt, test_38E.txt, test_39E.txt, test_45E.txt, test_47E.txt
All 0 / 1 00_sample_01E.txt, 00_sample_02E.txt, 00_sample_03E.txt, 00_sample_04.txt, test_01.txt, test_02.txt, test_03E.txt, test_04E.txt, test_05.txt, test_06.txt, test_07E.txt, test_08E.txt, test_09.txt, test_10.txt, test_11E.txt, test_12E.txt, test_13.txt, test_14.txt, test_15E.txt, test_16E.txt, test_17.txt, test_18.txt, test_19E.txt, test_20E.txt, test_21.txt, test_22.txt, test_23E.txt, test_24E.txt, test_25.txt, test_26.txt, test_27E.txt, test_28E.txt, test_29.txt, test_30.txt, test_31E.txt, test_32E.txt, test_33.txt, test_34.txt, test_35.txt, test_36E.txt, test_37E.txt, test_38E.txt, test_39E.txt, test_40.txt, test_41.txt, test_42.txt, test_43.txt, test_44.txt, test_45E.txt, test_46.txt, test_47E.txt, test_48.txt
Case Name Status Exec Time Memory
00_sample_01E.txt 53 ms 5976 KB
00_sample_02E.txt 48 ms 6056 KB
00_sample_03E.txt 49 ms 6060 KB
00_sample_04.txt 48 ms 6064 KB
test_01.txt 48 ms 6060 KB
test_02.txt 48 ms 6056 KB
test_03E.txt 50 ms 6056 KB
test_04E.txt 49 ms 6060 KB
test_05.txt 48 ms 6052 KB
test_06.txt 48 ms 6048 KB
test_07E.txt 48 ms 6064 KB
test_08E.txt 49 ms 6068 KB
test_09.txt 48 ms 6052 KB
test_10.txt 51 ms 5976 KB
test_11E.txt 50 ms 5976 KB
test_12E.txt 48 ms 6056 KB
test_13.txt 48 ms 6052 KB
test_14.txt 48 ms 6064 KB
test_15E.txt 48 ms 6056 KB
test_16E.txt 48 ms 6056 KB
test_17.txt 48 ms 6056 KB
test_18.txt 47 ms 6056 KB
test_19E.txt 46 ms 6056 KB
test_20E.txt 48 ms 6060 KB
test_21.txt 48 ms 6048 KB
test_22.txt 50 ms 6060 KB
test_23E.txt 50 ms 6056 KB
test_24E.txt 48 ms 6064 KB
test_25.txt 51 ms 5972 KB
test_26.txt 48 ms 6060 KB
test_27E.txt 48 ms 6060 KB
test_28E.txt 47 ms 6064 KB
test_29.txt 48 ms 6056 KB
test_30.txt 48 ms 6052 KB
test_31E.txt 48 ms 6060 KB
test_32E.txt 48 ms 6048 KB
test_33.txt 48 ms 6060 KB
test_34.txt 48 ms 6060 KB
test_35.txt 48 ms 6056 KB
test_36E.txt 48 ms 6056 KB
test_37E.txt 48 ms 6064 KB
test_38E.txt 48 ms 6056 KB
test_39E.txt 48 ms 6052 KB
test_40.txt 48 ms 6056 KB
test_41.txt 48 ms 6060 KB
test_42.txt 47 ms 6052 KB
test_43.txt 47 ms 6056 KB
test_44.txt 47 ms 6060 KB
test_45E.txt 47 ms 6056 KB
test_46.txt 47 ms 6056 KB
test_47E.txt 47 ms 6060 KB
test_48.txt 47 ms 6056 KB