Submission #123093


Source Code Expand

Copy
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include<cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include<bitset>

#define REP(i,b,n) for(int i=b;i<(int)n;i++)
#define rep(i,n)   REP(i,0,n)
#define ALL(C)     (C).begin(),(C).end()
#define FOR(it,o)  for(__typeof((o).begin()) it=(o).begin(); it!=(o).end(); ++it)
#define dbg(x) cout << __LINE__ << ' ' << #x << " = " << (x) << endl


typedef long long ll;

using namespace std;

//ハマったらチェックリスト見ろ!!

const int N = 30;
// (basho) * (left) * (right) * (top) * bottom

//重複組合せの総数
//a[i]個あるn種類のものからm個選ぶときの組み合わせの数

ll MOD = 1000000007;


ll comb[N*N+1][N*N+1];

void makeComb(){
  rep(i, N*N+1)rep(j, N*N+1)comb[i][j] = 0;
  rep(i, N*N+1){
    comb[i][0] = 1;
  }
  REP(i, 1, N*N+1){
    REP(j, 1, N*N+1){
      comb[i][j] = (comb[i-1][j-1] + comb[i-1][j])%MOD;
    }
  }
}

ll solve1(ll space, ll d, ll l){
  if(min(space, min(d, l)) < 0)return 0;
  ll ret = comb[space][d+l];
  ret *= comb[d+l][l];
  ret %=MOD;
  return ret;
}


int main(){
  int R, C;
  makeComb();
  while(cin >> R >> C){

    int X, Y, D, L;
    cin >> X >> Y;
    cin >> D >> L;
    swap(X, Y);
    if(X == 1 && Y == 1){
      if(D + L == 1){
	cout << R*C << endl;
      }
      else cout << 0 <<endl;
      continue;
    }
    // y, x, 

    ll ans = 0;
    rep(x1, C){
      rep(y1, R){
	int x2 = x1 + X-1;
	int y2 = y1 + Y -1;
	if(x2 >= C || y2 >= R)continue;
	ans += solve1(X*Y, D, L);
	ans %=MOD;
	rep(xx1, 2){
	  rep(xx2, 2){
	    rep(yy1, 2){
	      rep(yy2, 2){
		if(xx1 + xx2 + yy1 + yy2 == 0)continue;
		//plus
		if((xx1  + xx2 + yy1 + yy2)% 2){
		  ll hoge = X*Y;
		  hoge -= (xx1+xx2)*Y + (yy1+yy2)*X;
		  if(xx1 == 1)hoge += (yy1 + yy2);
		  if(xx2 == 1)hoge += (yy1 + yy2);
		  ans -= solve1(hoge, D, L);
		  ans = (ans + MOD)%MOD;
		}else{
		  //minus
		  ll hoge = X*Y;
		  hoge -= (xx1+xx2)*Y + (yy1+yy2)*X;
		  if(xx1 == 1)hoge += (yy1 + yy2);
		  if(xx2 == 1)hoge += (yy1 + yy2);
		  ans += solve1(hoge, D, L);
		  ans = (ans + MOD)%MOD;
		}
	      }
	    }
	  }
	}
      }
    }
    cout << ans <<endl;
  }
  return 0;
}

Submission Info

Submission Time
Task D - AtCoder社の冬
User shioshiota
Language C++ (G++ 4.6.4)
Score 101
Code Size 2523 Byte
Status AC
Exec Time 47 ms
Memory 7256 KB

Judge Result

Set Name sub All
Score / Max Score 100 / 100 1 / 1
Status
AC × 25
AC × 52
Set Name Test Cases
sub 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 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 AC 43 ms 7032 KB
00_sample_02E.txt AC 42 ms 7084 KB
00_sample_03E.txt AC 41 ms 7076 KB
00_sample_04.txt AC 42 ms 7076 KB
test_01.txt AC 42 ms 7076 KB
test_02.txt AC 41 ms 7032 KB
test_03E.txt AC 44 ms 7072 KB
test_04E.txt AC 42 ms 7076 KB
test_05.txt AC 43 ms 7072 KB
test_06.txt AC 43 ms 7256 KB
test_07E.txt AC 42 ms 7076 KB
test_08E.txt AC 42 ms 7072 KB
test_09.txt AC 41 ms 7080 KB
test_10.txt AC 42 ms 7084 KB
test_11E.txt AC 42 ms 7084 KB
test_12E.txt AC 41 ms 7196 KB
test_13.txt AC 42 ms 7072 KB
test_14.txt AC 43 ms 7076 KB
test_15E.txt AC 42 ms 7204 KB
test_16E.txt AC 41 ms 7076 KB
test_17.txt AC 41 ms 7076 KB
test_18.txt AC 44 ms 7048 KB
test_19E.txt AC 44 ms 7084 KB
test_20E.txt AC 47 ms 7072 KB
test_21.txt AC 42 ms 7076 KB
test_22.txt AC 42 ms 7072 KB
test_23E.txt AC 42 ms 7076 KB
test_24E.txt AC 42 ms 7084 KB
test_25.txt AC 41 ms 7076 KB
test_26.txt AC 42 ms 7080 KB
test_27E.txt AC 42 ms 7076 KB
test_28E.txt AC 42 ms 7084 KB
test_29.txt AC 41 ms 7072 KB
test_30.txt AC 41 ms 7068 KB
test_31E.txt AC 43 ms 7144 KB
test_32E.txt AC 42 ms 7084 KB
test_33.txt AC 42 ms 7076 KB
test_34.txt AC 42 ms 7080 KB
test_35.txt AC 43 ms 7080 KB
test_36E.txt AC 42 ms 7192 KB
test_37E.txt AC 42 ms 7072 KB
test_38E.txt AC 42 ms 7084 KB
test_39E.txt AC 41 ms 7076 KB
test_40.txt AC 41 ms 7072 KB
test_41.txt AC 43 ms 7084 KB
test_42.txt AC 42 ms 7076 KB
test_43.txt AC 41 ms 7076 KB
test_44.txt AC 42 ms 7076 KB
test_45E.txt AC 42 ms 7076 KB
test_46.txt AC 42 ms 7080 KB
test_47E.txt AC 42 ms 7084 KB
test_48.txt AC 41 ms 7072 KB