結果
問題 | No.1001 注文の多い順列 |
ユーザー | Enjapma_kyopro |
提出日時 | 2020-02-29 22:34:11 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 268 ms / 2,000 ms |
コード長 | 4,199 bytes |
コンパイル時間 | 1,806 ms |
コンパイル使用メモリ | 176,248 KB |
実行使用メモリ | 50,688 KB |
最終ジャッジ日時 | 2024-10-13 20:20:44 |
合計ジャッジ時間 | 6,093 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 2 ms
5,248 KB |
testcase_04 | AC | 2 ms
5,248 KB |
testcase_05 | AC | 2 ms
5,248 KB |
testcase_06 | AC | 2 ms
5,248 KB |
testcase_07 | AC | 2 ms
5,248 KB |
testcase_08 | AC | 2 ms
5,248 KB |
testcase_09 | AC | 2 ms
5,248 KB |
testcase_10 | AC | 2 ms
5,248 KB |
testcase_11 | AC | 2 ms
5,248 KB |
testcase_12 | AC | 2 ms
5,248 KB |
testcase_13 | AC | 3 ms
5,248 KB |
testcase_14 | AC | 4 ms
5,248 KB |
testcase_15 | AC | 5 ms
5,248 KB |
testcase_16 | AC | 4 ms
5,248 KB |
testcase_17 | AC | 4 ms
5,248 KB |
testcase_18 | AC | 188 ms
43,392 KB |
testcase_19 | AC | 169 ms
39,936 KB |
testcase_20 | AC | 112 ms
28,800 KB |
testcase_21 | AC | 102 ms
26,368 KB |
testcase_22 | AC | 226 ms
50,688 KB |
testcase_23 | AC | 227 ms
50,432 KB |
testcase_24 | AC | 223 ms
50,304 KB |
testcase_25 | AC | 220 ms
49,664 KB |
testcase_26 | AC | 194 ms
49,024 KB |
testcase_27 | AC | 198 ms
49,536 KB |
testcase_28 | AC | 198 ms
49,920 KB |
testcase_29 | AC | 267 ms
50,176 KB |
testcase_30 | AC | 255 ms
48,384 KB |
testcase_31 | AC | 268 ms
50,432 KB |
testcase_32 | AC | 203 ms
50,688 KB |
testcase_33 | AC | 204 ms
50,560 KB |
ソースコード
#include <bits/stdc++.h> #include <unistd.h> #include <sys/time.h> #include <stdlib.h> using namespace std; typedef long long ll; typedef pair<ll,ll> P; typedef pair<P, ll> T; long long int INF = 1e18; const ll fact_table = 800008; double Pi = 3.1415926535897932384626; priority_queue <ll> pql; priority_queue <P> pqp; priority_queue <P> bag; //big priority queue priority_queue <ll,vector<ll>,greater<ll> > pqls; priority_queue <P,vector<P>,greater<P> > pqps; //small priority queue //top pop ll dx[8]={1,0,-1,0,1,1,-1,-1}; ll dy[8]={0,1,0,-1,1,-1,-1,1}; char dir[] = "DRUL"; //↓,→,↑,← #define p(x) cout<<x<<"\n"; #define el cout<<endl; #define pe(x) cout<<(x)<<" "; #define ps(x) cout<<fixed<<setprecision(25)<<x<<endl; #define pu(x) cout<<(x); #define pb push_back // #define lb lower_bound #define ub upper_bound #define CLEAR(a) a = decltype(a)(); #define pc(x) cout << x << ","; // ll mod = 998244353; ll mod = 1000000007; ll mypow(ll number1,ll number2, ll mod){ if(number2 == 0){ return 1; }else{ ll number3 = mypow(number1,number2 / 2, mod); number3 *= number3; number3 %= mod; if(number2%2==1){ number3 *= number1; number3 %= mod; } return number3; } } ll rui(ll number1,ll number2){ if(number2 == 0){ return 1; }else{ ll number3 = rui(number1,number2 / 2); number3 *= number3; number3 %= mod; if(number2%2==1){ number3 *= number1; number3 %= mod; } return number3; } } ll gcd(ll number1,ll number2){ if(number1 > number2){ swap(number1,number2); } if(number1 == 0 || number1 == number2){ return number2; }else{ return gcd(number2 % number1,number1); } } void YES(bool condition){ if(condition){ p("YES"); }else{ p("NO"); } return; } void Yes(bool condition){ if(condition){ p("Yes"); }else{ p("No"); } return; } /* ll fact[fact_table + 5],rfact[fact_table + 5]; void c3_init(){ fact[0] = rfact[0] = 1; for(ll i=1; i<=fact_table; i++){ fact[i] = (fact[i-1]*i) % mod; } rfact[fact_table] = rui(fact[fact_table],mod - 2); for(ll i=fact_table; i>=1; i--){ rfact[i-1] = rfact[i] * i; rfact[i-1] %= mod; } return;} ll c3(ll n,ll r){ return (((fact[n] * rfact[r]) % mod ) * rfact[n-r]) % mod;} */ bool multicase = false; ll n,m,num,sum,a,b,c,d,e,h,q; ll w, ans; ll k; char s[500005], t[500005]; ll x[500005], y[500005]; bool cond[5005]; ll dp[5005][4005]; void init(){ struct timeval _time; gettimeofday(&_time, NULL); ll usec = _time.tv_usec * 1000000; srand(usec); return; } void solve(){ cin >> n; vector<ll> right, left; for(ll i=0;i<n;i++){ cin >> a >> x[i]; if(a == 1){ left.pb(x[i]); }else{ right.pb(x[i]); } } sort(left.begin(), left.end()); sort(right.begin(), right.end()); dp[0][0] = 1; ll cand = 0, waste = 0; ll idx1 = 0, idx2 = 0; for(ll i=1;i<=n;i++){ while(idx1 < left.size() && left[idx1] <= i){ idx1 ++; cand ++; } for(ll j=0;j<=i;j++){ // dp[i][j] ? // 捨てる場合 if(j > 0)dp[i][j] += dp[i-1][j-1]; dp[i][j] %= mod; // 捨てない場合 if(i != j)dp[i][j] += dp[i-1][j] * (cand - (i - 1 - j)) % mod; dp[i][j] %= mod; } while(idx2 < right.size() && right[idx2] == i){ for(ll j=0;j<=i;j++){ if(j < waste){ dp[i][j] = 0; }else{ dp[i][j] *= (j - waste) % mod; dp[i][j] %= mod; } } idx2 ++; waste ++; } } ll ans = dp[n][right.size()]; p(ans); return; } int main(){ // init(); ll q; if(multicase){ cin >> q; }else{ q = 1; } while(q--){ solve(); } return 0; }