Submission #601504


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 <= 0) return 0;
  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) {
    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 %= MODN;
    }
    hen1 = (hen1*2)%MODN;
    for (ll i = 0; i <= x-3; i++) {
      hen2 += combi(x*y-5-i, d+l-3);
      hen2 %= MODN;
    }
    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 %= MODN;
      }
    }
    hen3 = (hen3*4)%MODN;
    for (ll v1 = 0; v1 <= x-3; v1++) {
      for (ll v2 = 0; v2 <= y-3; v2++) {
        for (ll v3 = 0; v3 <= x-3; v3++) {
          for (ll v4 = 0; v4 <= y-3; v4++) {
            hen4 += combi(x*y-8-v1-v2-v3-v4, d+l-4);
            hen4 %= MODN;
          }
        }
      }
    }
    return (kadoP+hen1+hen2+hen3+hen4)%MODN;
  }
  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);
}

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

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

Submission Info

Submission Time
Task D - AtCoder社の冬
User warm4C0
Language C++11 (GCC 4.8.1)
Score 100
Code Size 1976 Byte
Status
Exec Time 2035 ms
Memory 5812 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 28 ms 1008 KB
00_sample_02E.txt 25 ms 872 KB
00_sample_03E.txt 28 ms 1720 KB
00_sample_04.txt 36 ms 3512 KB
test_01.txt 2033 ms 1080 KB
test_02.txt 26 ms 928 KB
test_03E.txt 26 ms 928 KB
test_04E.txt 24 ms 928 KB
test_05.txt 28 ms 876 KB
test_06.txt 39 ms 3896 KB
test_07E.txt 26 ms 928 KB
test_08E.txt 26 ms 968 KB
test_09.txt 29 ms 1976 KB
test_10.txt 34 ms 3000 KB
test_11E.txt 25 ms 928 KB
test_12E.txt 24 ms 1016 KB
test_13.txt 25 ms 1312 KB
test_14.txt 2035 ms 4788 KB
test_15E.txt 25 ms 928 KB
test_16E.txt 26 ms 928 KB
test_17.txt 30 ms 952 KB
test_18.txt 25 ms 1308 KB
test_19E.txt 25 ms 928 KB
test_20E.txt 27 ms 928 KB
test_21.txt 2034 ms 1332 KB
test_22.txt 36 ms 3256 KB
test_23E.txt 27 ms 924 KB
test_24E.txt 31 ms 880 KB
test_25.txt 2033 ms 1588 KB
test_26.txt 27 ms 1120 KB
test_27E.txt 27 ms 924 KB
test_28E.txt 24 ms 924 KB
test_29.txt 46 ms 4920 KB
test_30.txt 50 ms 5812 KB
test_31E.txt 26 ms 860 KB
test_32E.txt 24 ms 868 KB
test_33.txt 26 ms 924 KB
test_34.txt 2032 ms 1332 KB
test_35.txt 26 ms 924 KB
test_36E.txt 27 ms 928 KB
test_37E.txt 25 ms 924 KB
test_38E.txt 28 ms 932 KB
test_39E.txt 25 ms 932 KB
test_40.txt 27 ms 1332 KB
test_41.txt 25 ms 928 KB
test_42.txt 28 ms 1312 KB
test_43.txt 25 ms 1048 KB
test_44.txt 27 ms 1332 KB
test_45E.txt 25 ms 928 KB
test_46.txt 24 ms 872 KB
test_47E.txt 26 ms 864 KB
test_48.txt 24 ms 992 KB