# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
854973 |
2023-09-29T14:23:27 Z |
Tenis0206 |
W (RMI18_w) |
C++11 |
|
531 ms |
5132 KB |
#include <bits/stdc++.h>
using namespace std;
const int nmax = 3e5;
const int Mod = 1e9 + 7;
int n;
int v[nmax + 5];
pair<int,int> c[nmax + 5];
int inv[nmax + 5];
int dp[(1<<5) + 5], aux[(1<<5) + 5];
int lgput(int a, int b)
{
int p = 1;
while(b)
{
if(b%2==0)
{
b/=2;
a = 1LL * a * a % Mod;
}
else
{
--b;
p = 1LL * p * a % Mod;
}
}
return p;
}
int invmod(int x)
{
return lgput(x,Mod-2);
}
int comb(int n, int k)
{
int rez = 1;
for(int i=1; i<=n-k; i++)
{
rez = 1LL * rez * i % Mod;
}
for(int i=1; i<=n-k; i++)
{
rez = 1LL * rez * inv[i] % Mod;
}
return rez;
}
bool valid(int mask)
{
if((mask & 1) != 0 && (mask & 2) == 0)
{
return false;
}
if((mask & 4) != 0 && (mask & 2) == 0)
{
return false;
}
if((mask & 4) != 0 && (mask & 8) == 0)
{
return false;
}
if((mask & 16) != 0 && (mask & 8) == 0)
{
return false;
}
return true;
}
bool valid_last(int last_mask, int mask)
{
if((last_mask & 1) == 0 && (mask & 1) != 0 && (last_mask & 2) == 0 && (mask & 2) != 0)
{
return false;
}
if((last_mask & 2) == 0 && (mask & 2) != 0 && (last_mask & 4) == 0 && (mask & 4) != 0)
{
return false;
}
if((last_mask & 4) == 0 && (mask & 4) != 0 && (last_mask & 8) == 0 && (mask & 8) != 0)
{
return false;
}
if((last_mask & 8) == 0 && (mask & 8) != 0 && (last_mask & 16) == 0 && (mask & 16) != 0)
{
return false;
}
return true;
}
int get_opt(int last_mask, int mask)
{
int nr = 0;
if((mask & 2) != 0 && (last_mask & 1) == 0 && !((last_mask & 1) == 0 && (mask & 1) != 0) && !((last_mask & 2) == 0 && (mask & 2) != 0))
{
++nr;
}
if((mask & 2) != 0 && (last_mask & 4) == 0 && !((last_mask & 2) == 0 && (mask & 2) != 0) && !((last_mask & 4) == 0 && (mask & 4) != 0))
{
++nr;
}
if((mask & 8) != 0 && (last_mask & 4) == 0 && !((last_mask & 4) == 0 && (mask & 4) != 0) && !((last_mask & 8) == 0 && (mask & 8) != 0))
{
++nr;
}
if((mask & 8) != 0 && (last_mask & 16) == 0 && !((last_mask & 8) == 0 && (mask & 8) != 0) && !((last_mask & 16) == 0 && (mask & 16) != 0))
{
++nr;
}
if((last_mask & 1) == 0 && (mask & 1) != 0)
{
++nr;
}
if((last_mask & 2) == 0 && (mask & 2) != 0)
{
++nr;
}
if((last_mask & 4) == 0 && (mask & 4) != 0)
{
++nr;
}
if((last_mask & 8) == 0 && (mask & 8) != 0)
{
++nr;
}
if((last_mask & 16) == 0 && (mask & 16) != 0)
{
++nr;
}
return nr;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
#ifdef home
freopen("nr.in","r",stdin);
freopen("nr.out","w",stdout);
#endif // home
cin>>n;
for(int i=1; i<=n; i++)
{
cin>>v[i];
inv[i] = invmod(i);
}
sort(v+1,v+n+1);
int nr = 0;
for(int i=1; i<=n; i++)
{
if(v[i]!=v[i-1])
{
c[++nr].first = v[i];
}
++c[nr].second;
}
dp[0] = 1;
for(int i=1; i<=nr; i++)
{
for(int mask=0; mask<(1<<5); mask++)
{
if(!valid(mask))
{
continue;
}
for(int last_mask=0; last_mask<(1<<5); last_mask++)
{
if(!valid(last_mask))
{
continue;
}
if((mask & last_mask) != last_mask)
{
continue;
}
if(!valid_last(last_mask, mask))
{
continue;
}
int nr_free = c[i].second - (__builtin_popcount(mask) - __builtin_popcount(last_mask));
if(nr_free < 0)
{
continue;
}
int nropt = get_opt(last_mask, mask);
aux[mask] += 1LL * comb(nr_free + nropt - 1, nropt - 1) * dp[last_mask] % Mod;
aux[mask] %= Mod;
}
}
for(int mask=0; mask<(1<<5); mask++)
{
dp[mask] = aux[mask];
aux[mask] = 0;
}
}
cout<<dp[(1<<5) - 1]<<'\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
3 |
Incorrect |
32 ms |
4728 KB |
Output isn't correct |
4 |
Incorrect |
175 ms |
5132 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
4440 KB |
Output isn't correct |
2 |
Incorrect |
3 ms |
4444 KB |
Output isn't correct |
3 |
Incorrect |
52 ms |
4680 KB |
Output isn't correct |
4 |
Incorrect |
169 ms |
4724 KB |
Output isn't correct |
5 |
Incorrect |
339 ms |
4744 KB |
Output isn't correct |
6 |
Incorrect |
531 ms |
5132 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
4440 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
4 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
5 |
Incorrect |
2 ms |
4444 KB |
Output isn't correct |
6 |
Incorrect |
8 ms |
4444 KB |
Output isn't correct |
7 |
Incorrect |
11 ms |
4444 KB |
Output isn't correct |
8 |
Incorrect |
63 ms |
4652 KB |
Output isn't correct |
9 |
Incorrect |
127 ms |
4748 KB |
Output isn't correct |
10 |
Incorrect |
492 ms |
4996 KB |
Output isn't correct |