結果
問題 | No.1001 注文の多い順列 |
ユーザー | kotamanegi |
提出日時 | 2020-02-28 21:58:43 |
言語 | C++17(clang) (17.0.6 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 84 ms / 2,000 ms |
コード長 | 1,823 bytes |
コンパイル時間 | 1,577 ms |
コンパイル使用メモリ | 134,340 KB |
実行使用メモリ | 49,568 KB |
最終ジャッジ日時 | 2023-08-20 14:04:25 |
合計ジャッジ時間 | 3,884 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,376 KB |
testcase_01 | AC | 2 ms
4,380 KB |
testcase_02 | AC | 2 ms
4,380 KB |
testcase_03 | AC | 2 ms
4,380 KB |
testcase_04 | AC | 2 ms
4,376 KB |
testcase_05 | AC | 1 ms
4,376 KB |
testcase_06 | AC | 2 ms
4,376 KB |
testcase_07 | AC | 2 ms
4,376 KB |
testcase_08 | AC | 1 ms
4,376 KB |
testcase_09 | AC | 2 ms
4,380 KB |
testcase_10 | AC | 2 ms
4,380 KB |
testcase_11 | AC | 2 ms
4,380 KB |
testcase_12 | AC | 2 ms
4,380 KB |
testcase_13 | AC | 1 ms
4,380 KB |
testcase_14 | AC | 2 ms
4,472 KB |
testcase_15 | AC | 3 ms
4,844 KB |
testcase_16 | AC | 3 ms
4,380 KB |
testcase_17 | AC | 2 ms
4,380 KB |
testcase_18 | AC | 41 ms
28,532 KB |
testcase_19 | AC | 39 ms
27,212 KB |
testcase_20 | AC | 28 ms
19,856 KB |
testcase_21 | AC | 25 ms
18,804 KB |
testcase_22 | AC | 50 ms
33,332 KB |
testcase_23 | AC | 50 ms
32,560 KB |
testcase_24 | AC | 6 ms
4,380 KB |
testcase_25 | AC | 47 ms
31,776 KB |
testcase_26 | AC | 81 ms
47,952 KB |
testcase_27 | AC | 81 ms
46,864 KB |
testcase_28 | AC | 81 ms
45,108 KB |
testcase_29 | AC | 18 ms
16,644 KB |
testcase_30 | AC | 18 ms
16,640 KB |
testcase_31 | AC | 21 ms
17,400 KB |
testcase_32 | AC | 15 ms
15,512 KB |
testcase_33 | AC | 84 ms
49,568 KB |
コンパイルメッセージ
main.cpp:2:18: warning: '#pragma comment linker' ignored [-Wignored-pragmas] #pragma comment (linker, "/STACK:526000000") ^ 1 warning generated.
ソースコード
#define _CRT_SECURE_NO_WARNINGS #pragma comment (linker, "/STACK:526000000") #include "bits/stdc++.h" using namespace std; typedef string::const_iterator State; #define eps 1e-11L #define MAX_MOD 1000000007LL #define GYAKU 500000004LL #define MOD 998244353LL #define seg_size 262144 #define pb push_back #define mp make_pair typedef long long ll; #define REP(a,b) for(long long (a) = 0;(a) < (b);++(a)) #define ALL(x) (x).begin(),(x).end() unsigned long xor128() { static unsigned long x = 123456789, y = 362436069, z = 521288629, w = time(NULL); unsigned long t = (x ^ (x << 11)); x = y; y = z; z = w; return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8))); } void init() { iostream::sync_with_stdio(false); cout << fixed << setprecision(20); } #define int ll int dp[3001][3001] = {}; int limit_lower[3002]; int limit_higher[3002]; void solve() { int n; cin >> n; REP(i, n) { int a, b; cin >> a >> b; if (a == 0) { limit_lower[b]++; } else { limit_higher[b]++; } } for (int i = 0; i < 3001; ++i) { limit_higher[i + 1] += limit_higher[i]; limit_lower[i + 1] += limit_lower[i]; } dp[0][0] = 1; for (int i = 1; i <= n; ++i) { for (int q = 0; q <= limit_higher[i-1]; ++q) { if (dp[i-1][q] == 0) continue; //no take dp[i][q] += dp[i - 1][q]; dp[i][q] %= MAX_MOD; //take right dp[i][q + 1] += (dp[i - 1][q] * (limit_higher[i] - q)) % MAX_MOD; dp[i][q + 1] %= MAX_MOD; } for (int q = 0; q <= limit_higher[i]; ++q) { if (dp[i][q] == 0) continue; int now_have = i - q; now_have -= limit_lower[i - 1]; for (int j = 0; j < limit_lower[i] - limit_lower[i-1]; ++j) { dp[i][q] *= now_have; dp[i][q] %= MAX_MOD; now_have--; } dp[i][q] %= MAX_MOD; } } cout << dp[n][limit_higher[n]] << endl; } #undef int int main() { init(); solve(); }