Submission #26354945


Source Code Expand

#pragma GCC optimize (3, "Ofast", "inline")
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace std;

typedef long long ll;
typedef pair <int, int> pii;

#define fi first
#define se second
#define rez resize
#define pb push_back
#define mkp make_pair
#define eb emplace_back
#define debug(...) fprintf (stderr, __VA_ARGS__)

#define Lep(i, l, r) for (int i = l; i < r; ++ i)
#define Rep(i, r, l) for (int i = r; i > l; -- i)
#define lep(i, l, r) for (int i = l; i <= r; ++ i)
#define rep(i, r, l) for (int i = r; i >= l; -- i)

const int mod = 1e9 + 7;

inline int mul (int x, int y) { return 1ll * x * y % mod; }
inline void sub (int &x, int y) { x -= y; if (x < 0) x += mod; }
inline void pls (int &x, int y) { x += y; if (x >= mod) x -= mod; }
inline int dec (int x, int y) { x -= y; if (x < 0) x += mod; return x; }
inline int add (int x, int y) { x += y; if (x >= mod) x -= mod; return x; }
inline int modpow (int x, ll y, int res = 1) {
	for (y = (y + mod - 1) % (mod - 1); y; y >>= 1, x = mul (x, x)) if (y & 1) res = mul (x, res);
	return res;
}

char _c; bool _f; template <class T> inline void IN (T & x) {
	x = 0, _f = 0; while (_c = getchar (), ! isdigit (_c)) if (_c == '-') _f = 1;
	while (isdigit (_c)) x = x * 10 + _c - '0', _c = getchar (); if (_f) x = -x;
}

template <class T> inline void chkmin (T & x, T y) { if (x > y) x = y; }
template <class T> inline void chkmax (T & x, T y) { if (x < y) x = y; }

const int N = 6e2 + 5;

int n, a[N], tag[N], f[N][N], g[N][N];

int main () {
	IN (n), n <<= 1;
	lep (i, 1, n) IN (a[i]);

	lep (i, 1, n) if (~ a[i]) tag[a[i]] = 1;
	for (int i = 1; i < n; i += 2)
		if (~ a[i] && ~ a[i + 1]) tag[a[i]] = tag[a[i + 1]] = 2;

	int tn = 0, ts = 0;
	f[0][0] = 1;

	rep (i, n, 1) if (tag[i] < 2) {
		lep (j, 0, tn) lep (k, 0, ts) {
			pls (g[j + (tag[i] == 0)][k + (tag[i] == 1)], f[j][k]);

			if (j) pls (g[j - 1][k], f[j][k]);
			if (tag[i] == 0 && k) pls (g[j][k - 1], mul (f[j][k], k));
		}

		tn += (tag[i] == 0), ts += (tag[i] == 1);
		lep (j, 0, tn) lep (k, 0, ts) f[j][k] = g[j][k], g[j][k] = 0;
	}

	int ans = f[0][0];
	rep (i, (tn - ts) >> 1, 1) ans = mul (ans, i);
	printf ("%d\n", ans);
	return 0;
}

Submission Info

Submission Time
Task F - Permutation and Minimum
User Qiuly
Language C++ (GCC 9.2.1)
Score 1600
Code Size 2250 Byte
Status AC
Exec Time 61 ms
Memory 6488 KiB

Compile Error

./Main.cpp: In function ‘void IN(T&)’:
./Main.cpp:36:2: warning: this ‘while’ clause does not guard... [-Wmisleading-indentation]
   36 |  while (isdigit (_c)) x = x * 10 + _c - '0', _c = getchar (); if (_f) x = -x;
      |  ^~~~~
./Main.cpp:36:63: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘while’
   36 |  while (isdigit (_c)) x = x * 10 + _c - '0', _c = getchar (); if (_f) x = -x;
      |                                                               ^~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 1600 / 1600
Status
AC × 4
AC × 33
Set Name Test Cases
Sample sample1.txt, sample2.txt, sample3.txt, sample4.txt
All sample1.txt, sample2.txt, sample3.txt, sample4.txt, 1.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 2.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 3.txt, 4.txt, 5.txt, 6.txt, 7.txt, 8.txt, 9.txt, sample1.txt, sample2.txt, sample3.txt, sample4.txt
Case Name Status Exec Time Memory
1.txt AC 9 ms 3668 KiB
10.txt AC 44 ms 5736 KiB
11.txt AC 39 ms 6132 KiB
12.txt AC 43 ms 6152 KiB
13.txt AC 31 ms 6236 KiB
14.txt AC 2 ms 3844 KiB
15.txt AC 34 ms 5032 KiB
16.txt AC 38 ms 5672 KiB
17.txt AC 43 ms 5884 KiB
18.txt AC 16 ms 6352 KiB
19.txt AC 52 ms 5064 KiB
2.txt AC 7 ms 6452 KiB
20.txt AC 52 ms 5932 KiB
21.txt AC 48 ms 5972 KiB
22.txt AC 41 ms 5996 KiB
23.txt AC 38 ms 6152 KiB
24.txt AC 2 ms 3640 KiB
25.txt AC 61 ms 5156 KiB
3.txt AC 12 ms 6488 KiB
4.txt AC 2 ms 3692 KiB
5.txt AC 30 ms 5044 KiB
6.txt AC 36 ms 6152 KiB
7.txt AC 30 ms 6280 KiB
8.txt AC 22 ms 6352 KiB
9.txt AC 44 ms 5216 KiB
sample1.txt AC 2 ms 3536 KiB
sample2.txt AC 2 ms 3680 KiB
sample3.txt AC 2 ms 3800 KiB
sample4.txt AC 2 ms 3844 KiB