結果

問題 No.1929 Exponential Sequence
ユーザー kotatsugamekotatsugame
提出日時 2022-05-07 02:38:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 96 ms / 2,000 ms
コード長 942 bytes
コンパイル時間 820 ms
コンパイル使用メモリ 81,640 KB
実行使用メモリ 8,012 KB
最終ジャッジ日時 2023-10-12 04:23:59
合計ジャッジ時間 2,522 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 95 ms
8,012 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 1 ms
4,352 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 1 ms
4,352 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,352 KB
testcase_15 AC 2 ms
4,352 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 1 ms
4,352 KB
testcase_21 AC 95 ms
7,724 KB
testcase_22 AC 61 ms
5,956 KB
testcase_23 AC 94 ms
7,960 KB
testcase_24 AC 40 ms
5,120 KB
testcase_25 AC 92 ms
7,996 KB
testcase_26 AC 96 ms
7,144 KB
testcase_27 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:37:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   37 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int N,S;
vector<int>A;
vector<int>ret;
void dfs(int id,int now)
{
	if(id==A.size())ret.push_back(now);
	else
	{
		long t=A[id];
		while(now+t<=S)
		{
			dfs(id+1,now+t);
			t*=A[id];
		}
	}
}
vector<pair<int,long> >f(vector<int>A_)
{
	A=A_;
	dfs(0,0);
	vector<pair<int,long> >cnt;
	sort(ret.begin(),ret.end());
	for(int i=0;i<ret.size();)
	{
		int j=i;
		while(j<ret.size()&&ret[i]==ret[j])j++;
		cnt.push_back(make_pair(ret[i],j-i));
		i=j;
	}
	ret.clear();
	return cnt;
}
main()
{
	cin>>N>>S;
	vector<int>Ai(N);
	for(int i=0;i<N;i++)cin>>Ai[i];
	vector<pair<int,long> >L=f(vector<int>(Ai.begin(),Ai.begin()+N/2));
	vector<pair<int,long> >R=f(vector<int>(Ai.begin()+N/2,Ai.end()));
	int r=0;
	long ans=0,sum=0;
	for(int l=L.size();l--;)
	{
		while(r<R.size()&&R[r].first+L[l].first<=S)
		{
			sum+=R[r++].second;
		}
		ans+=sum*L[l].second;
	}
	cout<<ans<<endl;
}
0