結果

問題 No.645 Count Permutation
ユーザー 👑 kmjpkmjp
提出日時 2018-02-02 23:28:42
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 148 ms / 2,000 ms
コード長 1,940 bytes
コンパイル時間 1,238 ms
コンパイル使用メモリ 146,160 KB
実行使用メモリ 4,424 KB
最終ジャッジ日時 2023-08-30 02:29:55
合計ジャッジ時間 4,311 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,420 KB
testcase_01 AC 4 ms
4,376 KB
testcase_02 AC 5 ms
4,376 KB
testcase_03 AC 4 ms
4,380 KB
testcase_04 AC 4 ms
4,380 KB
testcase_05 AC 4 ms
4,380 KB
testcase_06 AC 4 ms
4,376 KB
testcase_07 AC 4 ms
4,380 KB
testcase_08 AC 4 ms
4,376 KB
testcase_09 AC 5 ms
4,424 KB
testcase_10 AC 4 ms
4,380 KB
testcase_11 AC 18 ms
4,380 KB
testcase_12 AC 12 ms
4,380 KB
testcase_13 AC 16 ms
4,380 KB
testcase_14 AC 6 ms
4,376 KB
testcase_15 AC 70 ms
4,380 KB
testcase_16 AC 59 ms
4,376 KB
testcase_17 AC 142 ms
4,376 KB
testcase_18 AC 49 ms
4,376 KB
testcase_19 AC 148 ms
4,376 KB
testcase_20 AC 148 ms
4,380 KB
testcase_21 AC 117 ms
4,376 KB
testcase_22 AC 4 ms
4,380 KB
testcase_23 AC 4 ms
4,376 KB
testcase_24 AC 148 ms
4,376 KB
testcase_25 AC 80 ms
4,380 KB
testcase_26 AC 123 ms
4,376 KB
testcase_27 AC 69 ms
4,380 KB
testcase_28 AC 48 ms
4,376 KB
testcase_29 AC 113 ms
4,380 KB
testcase_30 AC 114 ms
4,380 KB
testcase_31 AC 125 ms
4,380 KB
testcase_32 AC 40 ms
4,380 KB
testcase_33 AC 39 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#undef _P
#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 ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

ll N,L,R;
ll mo=1000000007;

ll fact[101010];
ll modpow(ll a, ll n = mo-2) {
	ll r=1;
	while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;
	return r;
}


int LIS(vector<int> v) {
	int pre=0,len=0;
	FORR(a,v) {
		if(a>pre) pre=a,len++;
	}
	return len;
}

ll dp[70];


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	fact[0]=1;
	for(i=1;i<=100100;i++) fact[i]=fact[i-1]*i%mo;
	
	cin>>N>>L>>R;
	dp[1]=1;
	for(i=2;i<=N-1;i++) {
		for(j=65;j>=1;j--) {
			(dp[j+1]+=dp[j])%=mo;
			(dp[j]*=i-1)%=mo;
		}
	}
	ll ret=0;
	for(i=1;i<=61;i++) if(L<=(1LL<<i) && (1LL<<i)<=R) ret+=dp[i];
	if(L==0) ret+=mo+fact[N]-fact[N-1];
	cout<<ret%mo<<endl;
#if 0
	
	map<vector<int>,vector<vector<int>>> M;
	vector<int> A;
	FOR(i,N) A.push_back(i+1);
	do {
		vector<int> B=A;
		FOR(i,N-1) if(B[i]>B[i+1]) swap(B[i],B[i+1]);
		M[B].push_back(A);
		/*
		FORR(v,A) cout<<v;
		cout<<" ";
		FORR(v,B) cout<<v;
		cout<<endl;
		*/
	} while(next_permutation(ALL(A)));
	
	map<int,int> R;
	FORR(b,M) {
		FORR(v,b.first) cout<<v;
		cout<<" "<<b.second.size()<<"    "<<(b.second.size()-(1<<(LIS(b.first)-1)))<<endl;
		R[b.second.size()]++;
		/*
		FORR(v,b.second) {
			cout<<"  ";
			FORR(vv,v) cout<<vv;
			cout<<endl;
		}
		*/
	}
	FORR(r,R) cout<<r.first<<" "<<r.second<<"   "<<r.first*r.second<<endl;
#endif

}


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