AtCoder Beginner Contest 003

Submission #1501247

Source codeソースコード

#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

#ifndef _DEBUG
#define main_ main
#endif
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<bool> vb;
typedef vector<string> vs;

template <typename T>
using keyVal = pair<string, T>;
template<typename T>
bool val_greater(const keyVal<T>& left, const keyVal<T>& right) {
	return left.second > right.second;
}

vs split(string str, char sep) {
	vs v; stringstream ss(str); string t;
	while (getline(ss, t, sep)) v.push_back(t);
	return v;
}

void init_global() {}

const ll MOD = 1e9 + 7;
const int RCMAX = 30 * 30;
ll dp[RCMAX + 4][RCMAX + 4];

ll combi(int n, int k) {
	if (n < 0 || k < 0 || n < k) return 0;
	return dp[n][k];
}

int main_() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int R, C; cin >> R >> C;
	int X, Y; cin >> X >> Y;
	int D, L; cin >> D >> L;

	dp[0][0] = 1;
	FOR(i, 1, X*Y + 1) {
		dp[i][0] = 1;
		dp[i][1] = i%MOD;
		dp[i][i] = 1;
	}

	FOR(i, 1, X*Y + 1) {
		FOR(j, 0, i+1) {
			dp[i + 1][j + 1] = dp[i][j] + dp[i][j + 1];
			dp[i + 1][j + 1] %= MOD;
		}
	}

	//	ll ans = (R - X + 1) * (C - Y + 1);

	ll all = combi(X*Y, D + L);
	ll l_r = combi((X - 1)*Y, D + L) * 2; // l_r : l+r
	ll t_b = combi(X*(Y - 1), D + L) * 2;
	ll lt_lb_rt_rb = combi((X - 1)*(Y - 1), D + L) * 4;
	ll lr = combi((X - 2)*Y, D + L);
	ll tb = combi(X*(Y - 2), D + L);
	ll lr_t_b = combi((X - 2)*(Y - 1), D + L) * 2;
	ll l_r_tb = combi((X - 1)*(Y - 2), D + L) * 2;
	ll lrtb = combi((X - 2)*(Y - 2), D + L);

	/* all - l_r_t_b
	   = all - (l + r + t + b
				- lr - lt - lb - rt -rb - tb
				+ lrt + lrb + ltb + rtb
				- lrtb)
	   = all - (l_r + t_b
				- lt_lb_rt_rb - lr -tb
				+ lr_t_b + l_r_tb
				- lrtb)
	*/
	ll ans = all;

	ans -= l_r;
	ans %= MOD;
	ans -= t_b;
	ans %= MOD;

	ans += lt_lb_rt_rb;
	ans %= MOD;
	ans += lr;
	ans %= MOD;
	ans += tb;
	ans %= MOD;

	ans -= lr_t_b;
	ans %= MOD;
	ans -= l_r_tb;
	ans %= MOD;

	ans += lrtb;
	ans %= MOD;

	ll num = combi(D + L, L);
	ans *= num;
	ans %= MOD;

	ans *= (R - X + 1) * (C - Y + 1);
	ans %= MOD;

	cout << ans << endl;
	return 0;
}

Submission

Task問題 D - AtCoder社の冬
User nameユーザ名 apprec
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 WA
Score得点 0
Source lengthソースコード長 2551 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 AC 1 ms 256 KB
00_sample_02E.txt AC 1 ms 256 KB
00_sample_03E.txt AC 1 ms 1152 KB
00_sample_04.txt AC 2 ms 3712 KB
test_01.txt AC 1 ms 384 KB
test_02.txt AC 1 ms 256 KB
test_03E.txt AC 1 ms 256 KB
test_04E.txt AC 2 ms 3712 KB
test_05.txt AC 1 ms 256 KB
test_06.txt AC 3 ms 5760 KB
test_07E.txt AC 1 ms 640 KB
test_08E.txt AC 1 ms 1280 KB
test_09.txt AC 1 ms 1536 KB
test_10.txt WA
test_11E.txt AC 1 ms 1152 KB
test_12E.txt AC 2 ms 3712 KB
test_13.txt AC 1 ms 640 KB
test_14.txt AC 3 ms 6016 KB
test_15E.txt AC 2 ms 3712 KB
test_16E.txt AC 3 ms 6016 KB
test_17.txt AC 1 ms 384 KB
test_18.txt WA
test_19E.txt AC 1 ms 256 KB
test_20E.txt AC 1 ms 512 KB
test_21.txt AC 1 ms 640 KB
test_22.txt WA
test_23E.txt AC 1 ms 256 KB
test_24E.txt AC 3 ms 5760 KB
test_25.txt AC 1 ms 896 KB
test_26.txt AC 1 ms 512 KB
test_27E.txt AC 2 ms 3712 KB
test_28E.txt AC 2 ms 3712 KB
test_29.txt AC 3 ms 5760 KB
test_30.txt AC 3 ms 6016 KB
test_31E.txt AC 1 ms 1280 KB
test_32E.txt AC 3 ms 6016 KB
test_33.txt AC 1 ms 256 KB
test_34.txt AC 1 ms 768 KB
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 AC 1 ms 256 KB
test_39E.txt WA
test_40.txt WA
test_41.txt AC 1 ms 256 KB
test_42.txt WA
test_43.txt AC 1 ms 384 KB
test_44.txt AC 1 ms 768 KB
test_45E.txt AC 1 ms 256 KB
test_46.txt AC 1 ms 384 KB
test_47E.txt AC 1 ms 384 KB
test_48.txt AC 1 ms 256 KB