結果
| 問題 |
No.1001 注文の多い順列
|
| コンテスト | |
| ユーザー |
kyort0n
|
| 提出日時 | 2020-02-28 21:53:27 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 161 ms / 2,000 ms |
| コード長 | 1,915 bytes |
| コンパイル時間 | 1,562 ms |
| コンパイル使用メモリ | 170,532 KB |
| 実行使用メモリ | 73,856 KB |
| 最終ジャッジ日時 | 2024-10-13 17:19:10 |
| 合計ジャッジ時間 | 4,534 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 31 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
if(a < b) {
a = b;
return true;
}
return false;
}
template<class T>
inline bool chmin(T &a, T b) {
if(a > b) {
a = b;
return true;
}
return false;
}
const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
const ll mod = 1000000007;
ll N;
vector<ll> t, X;
ll dp[3002][3002];
int main() {
//cout.precision(10);
cin.tie(0);
ios::sync_with_stdio(false);
cin >> N;
t.resize(N);
X.resize(N);
for(int i = 0; i < N; i++) {
cin >> t[i] >> X[i];
X[i]--;
}
dp[0][0] = 1;
ll Up = 0;
ll Down = 0;
for(ll val = 0; val < N; val++) {
for(int i = 0; i < N; i++) {
if(t[i] == 1 and X[i] == val) Up++;
}
for(int before = 0; before <= N; before++) {
ll delta = Up - before;
chmax(delta, 0LL);
dp[val+1][before+1] += dp[val][before] * delta;
dp[val+1][before+1] %= mod;
dp[val+1][before] += dp[val][before];
dp[val+1][before] %= mod;
}
for(int i = 0; i < N; i++) {
if(t[i] == 0 and X[i] == val) {
for(ll before = 0; before <= N; before++) {
ll delta = val + 1 - before - Down;
if(delta <= 0) dp[val+1][before] = 0;
else dp[val+1][before] *= delta;
dp[val+1][before] %= mod;
}
Down++;
}
}
}
ll ans = dp[N][Up];
/*
for(int i = 0; i <= N; i++) {
for(int j = 0; j <= N; j++) {
cerr << dp[i][j] << " ";
}
cerr << endl;
}
*/
cout << ans << endl;
return 0;
}
kyort0n