AtCoder Beginner Contest 003

Submission #6902477

Source codeソースコード

#include<bits/stdc++.h>
using namespace std;

int mod = 1'000'000'007;

long long modpow(long long x, long long y){
    if (y == 0) return 1;
    if (y % 2) return x * modpow(x, y - 1) % mod;
    return modpow(x, y / 2) * modpow(x, y / 2) % mod;
}

int cmb(int x, int y){
    long long acc = 1;
    long long div = 1;
    for (int i = 0; i < y; i++){
        acc *= x - i;
        acc %= mod;
        div *= i + 1;
        div %= mod;
    }
    int res = acc * modpow(div, mod - 2) % mod;
    if (res == 0) return 1;
    else return res;
}

int main(){
    int r, c, x, y, d, l;
    cin >> r >> c >> x >> y >> d >> l;
    long long ans = 0;
    if (x == 1 && y == 1){
        ans = 1;
    }
    else if (x == 1 || y == 1){
        vector<int> dd = {0, 1, 1, 2};
        vector<int> dl = {2, 1, 1, 0};
        for (int i = 0; i < 4; i++){
            if (dd[i] > d || dl[i] > l) continue;
            long long tmp = 1;
            tmp *= cmb(x * y - dd[i] - dl[i], d - dd[i]);
            tmp %= mod;
            tmp *= cmb(x * y - d - dl[i], l - dl[i]);
            tmp %= mod;
            ans += tmp;
            ans %= mod;
        }
    }
    else {
        vector<int> dd = {0, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 0, 3, 2, 2, 2, 1, 1, 1, 0, 3, 2, 2, 2, 1, 1, 1, 0, 3, 2, 2, 2, 1, 1, 1, 0, 3, 2, 2, 2, 1, 1, 1, 0, 2, 1, 1, 0, 2, 1, 1, 0, 2, 1, 1, 0, 2, 1, 1, 0, 2, 1, 1, 0, 2, 1, 1, 0};
        vector<int> dl = {4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 0, 1, 1, 1, 2, 2, 2, 3, 0, 1, 1, 1, 2, 2, 2, 3, 0, 1, 1, 1, 2, 2, 2, 3, 0, 1, 1, 1, 2, 2, 2, 3, 0, 1, 1, 2, 0, 1, 1, 2, 0, 1, 1, 2, 0, 1, 1, 2, 0, 1, 1, 2, 0, 1, 1, 2};
        for (int i = 0; i < 72; i++){
            if (dd[i] > d || dl[i] > l) continue;
            long long tmp = 1;
            tmp *= cmb(x * y - dd[i] - dl[i], d - dd[i]);
            tmp %= mod;
            tmp *= cmb(x * y - d - dl[i], l - dl[i]);
            tmp %= mod;
            ans += tmp;
            ans %= mod;
        }
    }
    ans *= r - x + 1;
    ans %= mod;
    ans *= c - y + 1;
    ans %= mod;
    cout << ans << endl;
}

Submission

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

Test case

Set

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

Test case

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