結果
| 問題 | No.1001 注文の多い順列 |
| コンテスト | |
| ユーザー |
vjudge1
|
| 提出日時 | 2026-10-04 15:59:38 |
| 言語 | C++23(gcc16) (gcc 16.1.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 27 ms / 2,000 ms |
| + 879µs | |
| コード長 | 1,601 bytes |
| 記録 | |
| コンパイル時間 | 4,447 ms |
| コンパイル使用メモリ | 361,948 KB |
| 実行使用メモリ | 20,992 KB |
| 最終ジャッジ日時 | 2026-10-04 15:59:46 |
| 合計ジャッジ時間 | 6,607 ms |
|
ジャッジサーバーID (参考情報) |
judge2_1 / judge4_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 31 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int main() {
int N;
cin >> N;
vector<int> V[2]; // V[0]: t=0, V[1]: t=1
for (int i = 0; i < N; i++) {
int t, x;
cin >> t >> x;
V[t].push_back(x - 1); // ?? 0-indexed
}
// ????????
sort(V[0].begin(), V[0].end());
sort(V[1].begin(), V[1].end());
int n0 = V[0].size(), n1 = V[1].size();
vector<vector<long long>> dp(n0 + 1, vector<long long>(n1 + 1, 0));
dp[0][0] = 1;
for (int i = 0; i < N; i++) { // i = ???????
// ??? cnt0, cnt1
int cnt0 = 0, cnt1 = 0;
for (int v : V[0]) cnt0 += (v >= i);
for (int v : V[1]) cnt1 += (i >= v);
for (int x = 0; x <= n0; x++) {
int y = i - x;
if (y < 0 || y > n1) continue;
if (dp[x][y] == 0) continue;
// ?? t=1 ???
if (y < n1) {
long long ways = cnt1 - y;
if (ways > 0) {
dp[x][y + 1] = (dp[x][y + 1] + dp[x][y] * ways) % MOD;
}
}
// ?? t=0 ???
if (x < n0) {
long long ways = cnt0 - (n0 - (x + 1));
if (ways > 0) {
dp[x + 1][y] = (dp[x + 1][y] + dp[x][y] * ways) % MOD;
}
}
}
}
long long ans = 0;
for (int x = 0; x <= n0; x++) {
int y = N - x;
if (y >= 0 && y <= n1) {
ans = (ans + dp[x][y]) % MOD;
}
}
cout << ans << endl;
return 0;
}
vjudge1