結果

問題 No.2136 Dice Calendar?
ユーザー 👑 kmjpkmjp
提出日時 2022-11-27 22:15:23
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,681 bytes
コンパイル時間 2,250 ms
コンパイル使用メモリ 202,172 KB
実行使用メモリ 252,928 KB
最終ジャッジ日時 2024-04-15 03:32:47
合計ジャッジ時間 19,586 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
12,816 KB
testcase_01 AC 16 ms
12,832 KB
testcase_02 AC 34 ms
14,708 KB
testcase_03 AC 16 ms
12,696 KB
testcase_04 AC 15 ms
12,848 KB
testcase_05 AC 17 ms
12,976 KB
testcase_06 AC 18 ms
13,084 KB
testcase_07 AC 19 ms
13,124 KB
testcase_08 AC 20 ms
13,388 KB
testcase_09 AC 28 ms
14,236 KB
testcase_10 AC 34 ms
14,760 KB
testcase_11 AC 85 ms
19,044 KB
testcase_12 AC 122 ms
22,344 KB
testcase_13 AC 83 ms
19,108 KB
testcase_14 AC 152 ms
23,900 KB
testcase_15 AC 960 ms
65,416 KB
testcase_16 AC 1,459 ms
80,072 KB
testcase_17 AC 960 ms
64,764 KB
testcase_18 AC 4,394 ms
172,292 KB
testcase_19 TLE -
testcase_20 TLE -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N;
const ll mo=998244353;
const int NUM_=400001;
static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];

unordered_set<int> M[21];
int add(int mask,int v) {
	int i;
	FOR(i,31) if(mask&(1<<i)) {
		if(v==0) {
			int a=mask&((1<<i)-1);
			return ((mask^a)<<1)^a;
		}
		v--;
	}
	assert(0);
}

void solve() {
	int i,j,k,l,r,x,y; string s;

	inv[1]=fact[0]=factr[0]=1;
	for (int i=2;i<=NUM_;++i) inv[i] = inv[mo % i] * (mo - mo / i) % mo;
	for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%mo, factr[i]=factr[i-1]*inv[i]%mo;
	
	cin>>N;
	
	M[0].insert((1<<9)-1);
	FOR(i,N) {
		int C[6];
		FOR(j,6) {
			cin>>C[j];
			C[j]--;
		}
		FORR(a,M[i]) {
			FOR(j,6) M[i+1].insert(add(a,C[j]));
		}
	}
	
	ll ret=0;
	FORR(m,M[N]) {
		ll v=fact[N];
		int cur=0;
		FOR(i,31) {
			if(m&(1<<i)) {
				v=v*factr[cur]%mo;
				cur=0;
			}
			else {
				cur++;
			}
		}
		ret+=v;
	}
	cout<<ret%mo<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0