結果
問題 | No.645 Count Permutation |
ユーザー |
![]() |
提出日時 | 2018-02-02 23:28:42 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 147 ms / 2,000 ms |
コード長 | 1,940 bytes |
コンパイル時間 | 1,287 ms |
コンパイル使用メモリ | 161,340 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-12-31 08:15:02 |
合計ジャッジ時間 | 3,991 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 34 |
ソースコード
#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; }