結果

問題 No.389 ロジックパズルの組み合わせ
ユーザー kotamanegi
提出日時 2016-07-08 22:42:06
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,194 bytes
コンパイル時間 1,036 ms
コンパイル使用メモリ 87,084 KB
実行使用メモリ 21,248 KB
最終ジャッジ日時 2024-10-13 06:09:59
合計ジャッジ時間 4,890 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 7 WA * 2 TLE * 1 -- * 89
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include<map>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <iomanip>
using namespace std;
#define MAX_MOD 1000000007
#define REP(i,n) for(int i = 0;i < n;++i)
long long dp[1000100][2] = {};
int main() {
	int m;
	cin >> m;
	int a = 1;
	vector<int> hints;
	while (cin >> a){
		hints.push_back(a);
	}
	if (hints[0] == 0) {
		cout << "1" << endl;
		return 0;
	}
	dp[0][1] = 1;
	for (int i = 0;i < hints.size();++i) {
		for (int q = 0;q < m;++q) {
			if (q + hints[i] <= m) {
				dp[q + hints[i] + 1][i % 2] += dp[q][(i + 1) % 2];
			}
			dp[q + hints[i] + 1][i % 2] %= MAX_MOD;
			dp[q + 1][(i + 1) % 2] += dp[q][(i + 1) % 2];
			dp[q][(i + 1) % 2] = 0;
		}
	}
	long long ans = 0;
	for (int i = 0;i <= m;++i) {
		ans += dp[i][hints.size() % 2];
		ans %= MAX_MOD;
	}
	if (ans != 0) {
		cout << ans%MAX_MOD << endl;
	}
	else {
		cout << "NA" << endl;
	}
}
0