Submission #17177505


Source Code Expand

#include <bits/stdc++.h>

using namespace std;

#define FOE(i, s, t) for (int i = s; i <= t; i++)
#define FOR(i, s, t) for (int i = s; i < t; i++)
#define FOD(i, s, t) for (int i = s; i >= t; i--)

#define LL long long
#define mp make_pair
#define pb push_back

#define K 601
#define M 1000000007

int n;

int a[K];

int b[14], exi[14], rv[14];

LL bigmod(LL a, LL p) {
	if (!p) return 1;
	LL t = bigmod(a, p >> 1);
	
	t = t * t % M;
	if (p & 1) t = t * a % M;
	
	return t;	
}

int l[K], r[K];

vector<pair<int, pair<int, int > > > E;

LL C(LL n, int k) {
	LL ret = 1;
	for (int i = 1; i <= k; i++) {
		ret = ret * (n - i + 1) % M;
		ret = ret * rv[i] % M;
	}
	
	return ret;
}

LL cnt() {
//	if (b[1] != 2 || b[2] != 1 || b[3] != 3) return 0;
	E.clear();
	FOE(i, 1, n) {
		l[i] = l[i - 1];
		
		if (i > 1 && b[i - 1] <= b[i]) l[i]++;
	}
	
//	FOE(i, 1, n) printf("l[%d] = %d\n", i, l[i]);

	FOD(i, n, 1) {
		int u = b[i];
		r[i] = a[u] - l[i];

		if (i != n) r[i] = min(r[i], r[i + 1]);
		E.pb(mp(r[i], mp(-1, i)));
	}
	
	FOE(i, 1, n) if (r[i] <= 0) return 0;
	
	LL cnt[9];
	FOE(i, 1, n + 1) cnt[i] = 1;
	int last = 1;
	
	sort(E.begin(), E.end());
	
	for (auto event : E) {
		int time = event.first;
		int dir = event.second.first;
		int row = event.second.second;
		
		LL cnt2[9];
		FOE(i, 1, n + 1) cnt2[i] = 0;
		
		if (time == last) FOE(i, 1, n + 1) cnt2[i] = cnt[i];
		else {
			FOE(i, 1, n + 1) FOE(j, i, n + 1) {
				LL way = C(time - last - 1 + (j - i), j - i);
				cnt2[j] = (cnt2[j] + cnt[i] * way % M) % M;
			}
		}
		
		cnt2[row] = 0;	
		
	//	FOE(i, 1, n + 1) printf("cnt[%d] = %lld at step %d\n", i, cnt2[i], row);
		
		FOE(i, 1, n + 1) cnt[i] = cnt2[i];
		last = time;
	}
	
	return cnt[n + 1];
}

LL ret = 0;

int dp[14];

void check() {
	FOE(i, 1, n) dp[i] = 0;
	FOE(i, 1, n) {
		int u = b[i];
		dp[u] = 1;
		
		FOE(j, 1, u - 1) {
			dp[u] = max(dp[u], dp[j] + 1);	
		}
	}
	
	int ma = dp[1];
	FOE(i, 1, n) ma = max(ma, dp[i]);
	LL tot = cnt();
	
/*	printf("PERM: ");
	FOE(i, 1, n) printf("%d ", b[i]);
	puts("");
	printf("= %d\n", ma);
*/
//	printf("%lld * %lld\n", tot, ma);
	ret = (ret + tot * ma % M) % M;
}

void gen(int u, int tar) {
	if (u == tar) {
		check();
		return;
	}
	
	FOE(i, 1, n) if (!exi[i]) {
		exi[i] = 1;
		b[u + 1] = i;
		
		gen(u + 1, tar);
		exi[i] = 0;
	//	return;
	}
}

int main() {
	scanf("%d", &n);
	
	FOE(i, 1, n) scanf("%d", &a[i]);
	FOE(i, 1, n + 1) rv[i] = bigmod(i, M - 2);
	
	gen(0, n);
	LL rev = 1;
	FOE(i, 1, n) rev = (rev * bigmod(a[i], M - 2)) % M;
	
//	printf("%lld\n", ret);
	printf("%lld\n", ret * rev % M);
}

Submission Info

Submission Time
Task E - Random LIS
User Theogry
Language C++ (GCC 9.2.1)
Score 700
Code Size 2718 Byte
Status AC
Exec Time 10 ms
Memory 3824 KiB

Compile Error

./Main.cpp: In function ‘long long int cnt()’:
./Main.cpp:75:7: warning: unused variable ‘dir’ [-Wunused-variable]
   75 |   int dir = event.second.first;
      |       ^~~
./Main.cpp: In function ‘int main()’:
./Main.cpp:145:7: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  145 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
./Main.cpp:147:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  147 |  FOE(i, 1, n) scanf("%d", &a[i]);
      |               ~~~~~^~~~~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 700 / 700
Status
AC × 3
AC × 34
Set Name Test Cases
Sample s1.txt, s2.txt, s3.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
01.txt AC 10 ms 3596 KiB
02.txt AC 4 ms 3752 KiB
03.txt AC 4 ms 3712 KiB
04.txt AC 2 ms 3820 KiB
05.txt AC 2 ms 3596 KiB
06.txt AC 5 ms 3748 KiB
07.txt AC 3 ms 3824 KiB
08.txt AC 4 ms 3676 KiB
09.txt AC 4 ms 3820 KiB
10.txt AC 3 ms 3672 KiB
11.txt AC 3 ms 3684 KiB
12.txt AC 3 ms 3720 KiB
13.txt AC 3 ms 3820 KiB
14.txt AC 2 ms 3772 KiB
15.txt AC 2 ms 3688 KiB
16.txt AC 3 ms 3644 KiB
17.txt AC 4 ms 3680 KiB
18.txt AC 2 ms 3716 KiB
19.txt AC 4 ms 3684 KiB
20.txt AC 4 ms 3660 KiB
21.txt AC 5 ms 3680 KiB
22.txt AC 4 ms 3600 KiB
23.txt AC 10 ms 3652 KiB
24.txt AC 6 ms 3772 KiB
25.txt AC 5 ms 3652 KiB
26.txt AC 7 ms 3600 KiB
27.txt AC 4 ms 3592 KiB
28.txt AC 7 ms 3676 KiB
29.txt AC 5 ms 3612 KiB
30.txt AC 4 ms 3680 KiB
31.txt AC 3 ms 3716 KiB
s1.txt AC 2 ms 3684 KiB
s2.txt AC 6 ms 3640 KiB
s3.txt AC 5 ms 3712 KiB