結果

問題 No.612 Move on grid
ユーザー snrnsidysnrnsidy
提出日時 2021-05-27 03:05:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 114 ms / 2,500 ms
コード長 1,099 bytes
コンパイル時間 2,772 ms
コンパイル使用メモリ 205,160 KB
実行使用メモリ 44,672 KB
最終ジャッジ日時 2024-04-23 19:21:08
合計ジャッジ時間 4,506 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 9 ms
5,376 KB
testcase_04 AC 61 ms
44,672 KB
testcase_05 AC 114 ms
44,544 KB
testcase_06 AC 113 ms
44,672 KB
testcase_07 AC 59 ms
44,544 KB
testcase_08 AC 114 ms
44,672 KB
testcase_09 AC 60 ms
22,912 KB
testcase_10 AC 43 ms
17,664 KB
testcase_11 AC 14 ms
7,168 KB
testcase_12 AC 66 ms
26,624 KB
testcase_13 AC 25 ms
11,264 KB
testcase_14 AC 88 ms
34,432 KB
testcase_15 AC 16 ms
7,808 KB
testcase_16 AC 100 ms
39,680 KB
testcase_17 AC 21 ms
11,392 KB
testcase_18 AC 83 ms
32,768 KB
testcase_19 AC 39 ms
20,608 KB
testcase_20 AC 56 ms
28,032 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("O3")
#include <bits/stdc++.h>
 
using namespace std;

const long long int MOD = 1e9 + 7;
long long int dp[501][20001];

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

	int n,a,b,c,d,e;

	cin >> n;
	cin >> a >> b >> c >> d >> e;
	d+=10000;
	e+=10000;

	dp[0][10000] = 1;

	for(int i=0;i<n;i++)
	{
		for(int j=0;j<=20000;j++)
		{
			if(dp[i][j]==0)
			{
				continue;
			}
			if(a+j>=0 && a+j<=20000)
			{	
				dp[i+1][a+j] += dp[i][j];
				dp[i+1][a+j]%=MOD;
			}
			if(j-a>=0 && j-a<=20000)
			{	
				dp[i+1][j-a] += dp[i][j];
				dp[i+1][j-a]%=MOD;
			}			
			if(b+j>=0 && b+j<=20000)
			{	
				dp[i+1][b+j] += dp[i][j];
				dp[i+1][b+j]%=MOD;
			}
			if(j-b>=0 && j-b<=20000)
			{	
				dp[i+1][j-b] += dp[i][j];
				dp[i+1][j-b]%=MOD;
			}	
			if(c+j>=0 && c+j<=20000)
			{	
				dp[i+1][c+j] += dp[i][j];
				dp[i+1][c+j]%=MOD;
			}
			if(j-c>=0 && j-c<=20000)
			{	
				dp[i+1][j-c] += dp[i][j];
				dp[i+1][j-c]%=MOD;
			}						
		}
	}

	long long int res = 0;

	for(int i=d;i<=e;i++)
	{
		res += dp[n][i];
		res%=MOD;
	}

	cout << res << '\n';

	return 0;
}
0