結果

問題 No.1001 注文の多い順列
コンテスト
ユーザー vjudge1
提出日時 2026-10-09 12:07:24
言語 C++17(gcc12)
(gcc 12.4.0 + boost 1.92.0 + ACL)
コンパイル:
g++-12 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 877 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,717 ms
コンパイル使用メモリ 206,320 KB
実行使用メモリ 9,928 KB
最終ジャッジ日時 2026-10-09 12:07:38
合計ジャッジ時間 2,764 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 3
other WA * 31
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:15:16: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   15 |         freopen(".in", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~
main.cpp:16:16: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   16 |         freopen(".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#define int long long
#define pb push_back
using namespace std;

const int N = 3e3 + 5, mod = 1e9 + 7;
int n, f[N][N];
int a, b, C[2][N];
vector <int> S[2]; 

signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	freopen(".in", "r", stdin);
	freopen(".out", "w", stdout);
	
	int i, j, t, x;
	cin >> n;
	
	for(i = 1; i <= n; i++)
	{
		cin >> t >> x;
		S[t].pb(x);
	}
	
	a = S[0].size(), b = S[1].size();
	
	for(i = 1; i <= n; i++)
	{
		for(auto p : S[0]) C[0][i] += (int)(i <= p);
		for(auto p : S[1]) C[1][i] += (int)(i >= p);
	}
	
	f[0][0] = 1;
	
	for(i = 0; i <= a; i++)
	{
		for(j = 0; j <= b; j++)
		{
			int tmp = i + j + 1;
			if(i < a) f[i + 1][j] = (f[i + 1][j] + f[i][j] * (C[0][tmp] - (a - (i + 1)))) % mod;
			if(j < b) f[i][j + 1] = (f[i][j + 1] + f[i][j] * (C[1][tmp] - j)) % mod;
		}
	}
	
	cout << f[a][b];
	return 0;
}
0