結果

問題 No.118 門松列(2)
ユーザー hanbei_dayohanbei_dayo
提出日時 2020-08-05 21:12:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 24 ms / 5,000 ms
コード長 1,134 bytes
コンパイル時間 1,704 ms
コンパイル使用メモリ 112,432 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 14:25:18
合計ジャッジ時間 3,999 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,348 KB
testcase_01 AC 23 ms
4,348 KB
testcase_02 AC 23 ms
4,348 KB
testcase_03 AC 24 ms
4,348 KB
testcase_04 AC 24 ms
4,348 KB
testcase_05 AC 23 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 22 ms
4,348 KB
testcase_10 AC 7 ms
4,348 KB
testcase_11 AC 8 ms
4,348 KB
testcase_12 AC 5 ms
4,348 KB
testcase_13 AC 4 ms
4,348 KB
testcase_14 AC 20 ms
4,348 KB
testcase_15 AC 3 ms
4,348 KB
testcase_16 AC 13 ms
4,348 KB
testcase_17 AC 4 ms
4,348 KB
testcase_18 AC 8 ms
4,348 KB
testcase_19 AC 12 ms
4,348 KB
testcase_20 AC 13 ms
4,348 KB
testcase_21 AC 18 ms
4,348 KB
testcase_22 AC 7 ms
4,348 KB
testcase_23 AC 17 ms
4,348 KB
testcase_24 AC 8 ms
4,348 KB
testcase_25 AC 12 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:48:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   48 |         for(auto [x,y]:mp){
      |                  ^

ソースコード

diff #

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
#include<random>
#include <bitset>
using namespace std;
#define N (1000000000+7)
//#define N 998244353
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> Q;
 
const int inf = (int)1e9; 
 
ll gcd(ll a, ll b) {
	if (b > a) {
		ll tmp = b;
		b = a;
		a = tmp;
	}
	if (a%b == 0)return b;
	else return gcd(b, a%b);
}

ll dp[100010][105][4];

int main(void){
	int n;
	cin>>n;
	map<int,ll>mp;
	for(int i=0;i<n;i++){
		int a;
		cin>>a;
		mp[a]++;
	}
	int m = mp.size();
	vector<int>a;
	for(auto [x,y]:mp){
		a.push_back(x);
	}
	dp[0][0][0]=1;
	sort(a.begin(),a.end());
	ll ans = 0;
	for(int i=0;i<m;i++){
		int lim = a[i];
		for(int j=0;j<lim;j++){
			for(int k=0;k<=3;k++){
				if(k<3)dp[i+1][a[i]][k+1] = (dp[i+1][a[i]][k+1]+mp[lim]*dp[i][j][k])%N;
				dp[i+1][j][k] = (dp[i+1][j][k]+dp[i][j][k])%N;
			}
		}
	}
	for(int j=0;j<=100;j++){
		ans = (ans+dp[m][j][3])%N;
	}
	cout<<ans<<endl;
	return 0;
}
0