結果

問題 No.473 和と積の和
ユーザー antaanta
提出日時 2016-12-23 00:12:57
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 76 ms / 3,000 ms
コード長 1,629 bytes
コンパイル時間 2,024 ms
コンパイル使用メモリ 182,428 KB
実行使用メモリ 19,144 KB
最終ジャッジ日時 2023-08-22 08:23:03
合計ジャッジ時間 4,478 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 27 ms
10,636 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,384 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 76 ms
19,144 KB
testcase_26 AC 21 ms
9,280 KB
testcase_27 AC 26 ms
10,168 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 45 ms
11,624 KB
testcase_35 AC 42 ms
11,696 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 41 ms
11,576 KB
testcase_39 AC 22 ms
7,420 KB
testcase_40 AC 24 ms
7,420 KB
testcase_41 AC 56 ms
7,556 KB
testcase_42 AC 30 ms
17,040 KB
testcase_43 AC 34 ms
17,028 KB
testcase_44 AC 39 ms
16,984 KB
testcase_45 AC 2 ms
4,380 KB
testcase_46 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if (x < y) x = y; }

int main() {
	int N; int X;
	while (~scanf("%d%d", &N, &X)) {
		++X;
		vector<int> divs;
		for (int d = 1; d * d <= X; ++d) if (X % d == 0) {
			divs.push_back(d);
			if(d * d != X)
				divs.push_back(X / d);
		}
		sort(divs.begin(), divs.end());
		auto getID = [&](int x) {
			return (int)(lower_bound(divs.begin(), divs.end(), x) - divs.begin());
		};
		int D = (int)divs.size();
		vector<vector<pair<int,int>>> edges(D);
		rep(prod, D) {
			reu(k, 1, D) {
				if ((ll)divs[prod] * divs[k] > X) break;
				if (X % (divs[prod] * divs[k]) != 0) continue;
				edges[prod].emplace_back(k, getID(divs[prod] * divs[k]));
			}
		}
		vector<vector<int>> dp, ndp(D, vector<int>(D));
		ndp[0][1] = 1;
		rep(i, N) {
			dp.swap(ndp);
			ndp.assign(D, vector<int>(D, 0));
			rep(prod, D) rep(last, D) {
				int x = dp[prod][last];
				if (x == 0) continue;
				for(auto &&e : edges[prod]) if(last <= e.first)
					ndp[e.second][e.first] += x;
			}
		}
		int ans = accumulate(ndp[D - 1].begin(), ndp[D - 1].end(), 0);
		printf("%d\n", ans);
	}
	return 0;
}
0