結果

問題 No.398 ハーフパイプ(2)
ユーザー furafura
提出日時 2020-08-07 01:54:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 1,080 bytes
コンパイル時間 2,292 ms
コンパイル使用メモリ 207,504 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-22 05:24:52
合計ジャッジ時間 3,308 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 22 ms
4,348 KB
testcase_03 AC 22 ms
4,348 KB
testcase_04 AC 23 ms
4,348 KB
testcase_05 AC 4 ms
4,348 KB
testcase_06 AC 4 ms
4,348 KB
testcase_07 AC 12 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 7 ms
4,348 KB
testcase_10 AC 6 ms
4,348 KB
testcase_11 AC 5 ms
4,348 KB
testcase_12 AC 14 ms
4,348 KB
testcase_13 AC 13 ms
4,348 KB
testcase_14 AC 14 ms
4,348 KB
testcase_15 AC 3 ms
4,348 KB
testcase_16 AC 13 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

template<class T>
vector<pair<T,int>> run_length_encoding(const vector<T>& a){
	vector<pair<T,int>> res;
	int n=a.size(),pre=0;
	rep(i,n) if(i==n-1 || a[i]!=a[i+1]) res.emplace_back(a[i],i-pre+1), pre=i+1;
	return res;
}

int fact[]={1,1,2,6,24,120,720};

int f(const vector<int> A){ // multinomial coefficient
	int res=fact[6];
	for(auto p:run_length_encoding(A)) res/=fact[p.second];
	return res;
}

int main(){
	int x;
	{
		int x1,x2; scanf("%d.%d",&x1,&x2);
		x=4*x1+4*x2/100;
	}

	lint ans=0;
	rep(a2,101) for(int a3=a2;a3<=100;a3++) for(int a4=a3;a4<=100;a4++) {
		int a5=x-(a2+a3+a4);
		if(!(a4<=a5 && a5<=100)) continue;

		vector<int> A={0,a2,a3,a4,a5,0};
		// a1 = a2 and a5 = a6
		A[0]=a2; A[5]=a5;
		ans+=f(A);
		// a1 = a2 and a5 < a6
		A[0]=a2; A[5]=a5+1;
		ans+=f(A)*(100-a5);
		// a1 < a2 and a5 = a6
		A[0]=a2-1; A[5]=a5;
		ans+=f(A)*a2;
		// a1 < a2 and a5 < a6
		A[0]=a2-1; A[5]=a5+1;
		ans+=f(A)*a2*(100-a5);
	}
	printf("%lld\n",ans);

	return 0;
}
0