結果
| 問題 |
No.1001 注文の多い順列
|
| コンテスト | |
| ユーザー |
kotamanegi
|
| 提出日時 | 2020-02-28 21:58:43 |
| 言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 88 ms / 2,000 ms |
| コード長 | 1,823 bytes |
| コンパイル時間 | 1,927 ms |
| コンパイル使用メモリ | 164,236 KB |
| 実行使用メモリ | 49,536 KB |
| 最終ジャッジ日時 | 2024-11-30 16:34:56 |
| 合計ジャッジ時間 | 3,574 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 31 |
コンパイルメッセージ
main.cpp:2:18: warning: '#pragma comment linker' ignored [-Wignored-pragmas]
2 | #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();
}
kotamanegi