AtCoder Beginner Contest 003

Submission #1227903

Source codeソースコード

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)


int mod = 1000000007;
int add(int x, int y) { return (x += y) >= mod ? x - mod : x; }
template<class... T> int add(int x, T... y) { return add(x, add(y...)); }
int mul(int x, int y) { return 1LL * x * y % mod; }
template<class... T> int mul(int x, T... y) { return mul(x, mul(y...)); }
int sub(int x, int y) { return add(x, mod - y); }
int modpow(int a, long long b) { int ret = 1; while (b > 0) { if (b & 1) ret = 1LL * ret * a % mod; a = 1LL * a * a % mod; b >>= 1; } return ret; }
int modinv(int a) { return modpow(a, mod - 2); }
int fac[201010], ifac[201010];
void initfac() {
    fac[0] = ifac[0] = 1;
    rep(i, 1, 201010) fac[i] = 1LL * i * fac[i - 1] % mod;
    rep(i, 1, 201010) ifac[i] = modinv(fac[i]);
}
int aCb(int a, int b) {
    if (b < 0 || a < b) return 0;
    return (1LL * fac[a] * ifac[a - b] % mod) * ifac[b] % mod;
}
//-----------------------------------------------------------------------------------
int R, C, X, Y, D, L;
int cnt(int x, int y) {
    if (x < 0 || y < 0) return 0;
    if (x * y < D + L) return 0;

    return mul(aCb(x * y, D), aCb(x * y - D, L));
}
//-----------------------------------------------------------------------------------
int main() {
    cin >> R >> C >> X >> Y >> D >> L;
    initfac();

    int ans = cnt(X, Y);
    ans = sub(ans, add(mul(cnt(X - 1, Y), 2), mul(cnt(X, Y - 1), 2)));
    ans = add(ans, add(mul(cnt(X - 1, Y - 1), 4), cnt(X - 2, Y), cnt(X, Y - 2)));
    ans = sub(ans, add(mul(cnt(X - 2, Y - 1), 2), mul(cnt(X - 1, Y - 2), 2)));
    ans = add(ans, cnt(X - 2, Y - 2));
        
    ans = mul(ans, (R - X + 1), (C - Y + 1));
    cout << ans << endl;
}

Submission

Task問題 D - AtCoder社の冬
User nameユーザ名 はまやんはまやん
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 AC
Score得点 101
Source lengthソースコード長 1753 Byte
File nameファイル名
Exec time実行時間 115 ms
Memory usageメモリ使用量 1792 KB

Test case

Set

Set name Score得点 / Max score 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 1 / 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

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
00_sample_01E.txt AC 115 ms 1792 KB
00_sample_02E.txt AC 115 ms 1792 KB
00_sample_03E.txt AC 115 ms 1792 KB
00_sample_04.txt AC 115 ms 1792 KB
test_01.txt AC 115 ms 1792 KB
test_02.txt AC 115 ms 1792 KB
test_03E.txt AC 115 ms 1792 KB
test_04E.txt AC 115 ms 1792 KB
test_05.txt AC 115 ms 1792 KB
test_06.txt AC 114 ms 1792 KB
test_07E.txt AC 115 ms 1792 KB
test_08E.txt AC 115 ms 1792 KB
test_09.txt AC 115 ms 1792 KB
test_10.txt AC 115 ms 1792 KB
test_11E.txt AC 115 ms 1792 KB
test_12E.txt AC 115 ms 1792 KB
test_13.txt AC 115 ms 1792 KB
test_14.txt AC 115 ms 1792 KB
test_15E.txt AC 115 ms 1792 KB
test_16E.txt AC 115 ms 1792 KB
test_17.txt AC 115 ms 1792 KB
test_18.txt AC 115 ms 1792 KB
test_19E.txt AC 115 ms 1792 KB
test_20E.txt AC 115 ms 1792 KB
test_21.txt AC 115 ms 1792 KB
test_22.txt AC 115 ms 1792 KB
test_23E.txt AC 115 ms 1792 KB
test_24E.txt AC 115 ms 1792 KB
test_25.txt AC 115 ms 1792 KB
test_26.txt AC 115 ms 1792 KB
test_27E.txt AC 115 ms 1792 KB
test_28E.txt AC 115 ms 1792 KB
test_29.txt AC 115 ms 1792 KB
test_30.txt AC 115 ms 1792 KB
test_31E.txt AC 115 ms 1792 KB
test_32E.txt AC 115 ms 1792 KB
test_33.txt AC 115 ms 1792 KB
test_34.txt AC 115 ms 1792 KB
test_35.txt AC 115 ms 1792 KB
test_36E.txt AC 115 ms 1792 KB
test_37E.txt AC 115 ms 1792 KB
test_38E.txt AC 115 ms 1792 KB
test_39E.txt AC 115 ms 1792 KB
test_40.txt AC 115 ms 1792 KB
test_41.txt AC 115 ms 1792 KB
test_42.txt AC 115 ms 1792 KB
test_43.txt AC 115 ms 1792 KB
test_44.txt AC 115 ms 1792 KB
test_45E.txt AC 115 ms 1792 KB
test_46.txt AC 115 ms 1792 KB
test_47E.txt AC 115 ms 1792 KB
test_48.txt AC 115 ms 1792 KB