39412023-03-06 00:53:37SleepyOverlordNegáló rendezés (55 pont)cpp17Time limit exceeded 16/55300ms30720 KiB
#include <vector>
#include <string> 
#include <set> 
#include <map> 
#include <unordered_set>
#include <unordered_map>
#include <queue> 
#include <bitset> 
#include <stack>
#include <list>

#include <numeric> 
#include <algorithm> 
#include <random>
#include <chrono>

#include <cstdio>
#include <fstream>
#include <iostream> 
#include <sstream> 
#include <iomanip>
#include <climits>

#include <cctype>
#include <cmath> 
#include <ctime>
#include <cassert>

using namespace std;

#define ULL unsigned long long
#define LL long long
#define PII pair <int, int>
#define VB vector <bool>
#define VI vector <int>
#define VLL vector <LL>
#define VD vector <double>
#define VS vector <string>
#define VPII vector <pair <int, int> >
#define VVI vector < VI >
#define VVB vector < VB >
#define SI set < int >
#define USI unordered_set <int>
#define MII map <int, int>
#define UMII unordered_map <int, int>
#define MS multiset
#define US unordered_set
#define UM unordered_map
#define UMS unordered_multiset
#define UMM unordered_multimap

#define FORN(i, n) for(int i = 0; i < (n); ++i)
#define FOR(i, a, b) for(int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)

#define SZ size()
#define BG begin() 
#define EN end() 
#define CL clear()
#define X first
#define Y second
#define RS resize
#define PB push_back
#define MP make_pair
#define ALL(x) x.begin(), x.end()
#define INS insert
#define ER erase
#define CNT count

#define IN_FILE "a.in"
#define OUT_FILE "a.out"

template <typename T>
void PR(T var1)
{
	cout << var1 <<endl;
}
template <typename T, typename... Types>
void PR(T var1, Types... var2)
{
	cout << var1;
	PR(var2...);
}

#define MOD 1000000007

int n;
VI a, pow2, cnt(100001), part;
map<PII, int> memo;

int go(int s, int k)
{
	if (memo.CNT({s, k})) return memo[{s, k}];
	if (k == 1) return memo[{s, k}] = (s <= part[1]);
	if (s == 0) return memo[{s, k}] = 1;
	int ans = go(s - 1, k);
	if (s > part[k]) ans -= go(s - part[k] - 1, k - 1);
	ans += go(s, k - 1);
	if (ans < MOD) ans += MOD;
	return memo[{s, k}] = ans % MOD;
}

int main()
{
 	cin >> n;
	a.RS(n + 1);
	FOR(i, 1, n) 
	{
		cin >> a[i];
		++cnt[a[i]];
	}
	FOR(i, 0, 100000)
		if (cnt[i]) part.PB(cnt[i]);

	int sum = 0;
	FOR(i, 0, (n - part[0])) 
	{
		sum += go(i, part.SZ - 1);
		sum %= MOD;
	}

	PR(sum);

	return 0;
}
SubtaskSumTestVerdictTimeMemory
base16/55
1Accepted0/03ms2508 KiB
2Time limit exceeded0/0300ms19928 KiB
3Accepted2/23ms2996 KiB
4Accepted2/23ms3192 KiB
5Accepted2/23ms3388 KiB
6Accepted2/23ms3484 KiB
7Accepted3/33ms3672 KiB
8Accepted2/23ms4004 KiB
9Time limit exceeded0/3300ms15472 KiB
10Time limit exceeded0/3268ms27828 KiB
11Time limit exceeded0/3268ms30720 KiB
12Accepted3/357ms11660 KiB
13Time limit exceeded0/3250ms17564 KiB
14Time limit exceeded0/3263ms18492 KiB
15Time limit exceeded0/3268ms15500 KiB
16Time limit exceeded0/3256ms21756 KiB
17Time limit exceeded0/3272ms21296 KiB
18Time limit exceeded0/3275ms17276 KiB
19Time limit exceeded0/3268ms20436 KiB
20Time limit exceeded0/3268ms18824 KiB
21Time limit exceeded0/3273ms17520 KiB
22Time limit exceeded0/3273ms15524 KiB