Submission #41444618
Source Code Expand
#include<bits/stdc++.h>
#define ld long double
#define ui unsigned int
#define ull unsigned long long
#define int long long
#define eb emplace_back
#define pb pop_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
using namespace std;
template<typename T=int> inline T read()
{
T s=0,w=1; char c=getchar();
while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();}
while(isdigit(c)) s=(s<<1)+(s<<3)+(c^48),c=getchar();
return s*w;
}
template<typename T=long long> inline void write(T x,char ch)
{
if(x<0) x=-x,putchar('-');
static char stk[25]; int top=0;
do {stk[top++]=x%10+'0',x/=10;} while(x);
while(top) putchar(stk[--top]);
putchar(ch);
return;
}
namespace MyTool
{
static const int Mod=998244353;
template<typename T> inline void Swp(T &a,T &b) {T t=a;a=b;b=t;}
template<typename T> inline void cmax(T &a,T b) {a=a>b?a:b;}
template<typename T> inline void cmin(T &a,T b) {a=a<b?a:b;}
inline void Madd(int &a,int b) {a=a+b>Mod?a+b-Mod:a+b;}
inline void Mdel(int &a,int b) {a=a-b<0?a-b+Mod:a-b;}
inline void Mmul(int &a,int b) {a=1ll*a*b%Mod;}
inline void Mmod(int &a) {a=(a%Mod+Mod)%Mod;}
inline int Cadd(int a,int b) {return a+b>=Mod?a+b-Mod:a+b;}
inline int Cdel(int a,int b) {return a-b<0?a-b+Mod:a-b;}
inline int Cmul(int a,int b) {return a*b%Mod;}
inline int Cmod(int a) {return (a%Mod+Mod)%Mod;}
inline int gcd(int a,int b) {return b?gcd(b,a%b):a;}
inline int qpow(int a,int b) {int res=1; while(b) {if(b&1) Mmul(res,a); Mmul(a,a); b>>=1;} return res;}
inline int qmul(int a,int b) {int res=0; while(b) {if(b&1) Madd(res,a); Madd(a,a); b>>=1;} return res;}
template<typename T> inline T power(T x) {return x*x;}
}
using namespace MyTool;
inline void file()
{
freopen(".in","r",stdin);
freopen(".out","w",stdout);
return;
}
bool Mbe;
namespace LgxTpre
{
static const int MAX=210;
static const int inf=2147483647;
static const int INF=4557430888798830399;
static const int mod=1e9+7;
static const int bas=131;
int n,ans,a[MAX];
int all=1,num12=1,pw=1;
int flag1,flag2,flag3;
int mix1=INF,mix2=-INF,top;
int f[MAX][1<<17],g[1<<17];
bool dfs(int S)
{
if(!S) return 1;
if(g[S]!=-1) return g[S];
int mix=(64-__builtin_clzll(S))*12;
for(int i=1;i<=mix;++i)
{
set<int> s;
for(int j=0;j<top;++j) if((S>>j&1)&&(12*(j+1)%i)) s.insert(12*(j+1)%i);
if(((int)s.size()==1&&*s.begin()<=2)||((int)s.size()==2&&*s.begin()==4&&*s.rbegin()==8)) return g[S]=1,1;
int T=0,flag=1;
for(auto it:s)
{
if(it%12) {flag=0; break;}
T|=(1<<((it/12)-1));
}
if(flag&&!dfs(T)) return g[S]=1,1;
}
return g[S]=0,0;
}
inline void mian()
{
n=read();
for(int i=1;i<=n;++i)
{
a[i]=read(),cmin(mix1,a[i]),cmax(mix2,a[i]),cmax(top,a[i]/12);
Mmul(all,a[i]),Mmul(num12,a[i]/12);
if(a[i]<2) flag1=1;
if(a[i]<4) flag2=1;
else if(a[i]<8) flag3=1;
else Mmul(pw,2ll);
}
ans=Cdel(all,Cadd(num12,1ll));
if(!flag1) Mdel(ans,1ll);
if(!flag2) Mdel(ans,Cdel(pw,!flag3+1));
if(mix1<12) return write(ans,'\n');
f[0][0]=1,memset(g,-1,sizeof g);
for(int i=1;i<=n;++i) for(int S=0;S<(1<<top);++S)
if(f[i-1][S]) for(int now=0,T=S|(1<<now);(now+1)*12<=a[i];++now,T=S|(1<<now))
Madd(f[i][T],f[i-1][S]);
for(int S=0;S<(1<<top);++S) if(dfs(S)) Madd(ans,f[n][S]);
write(ans,'\n');
return;
}
}
bool Med;
signed main()
{
// file();
fprintf(stderr,"%.3lf MB\n",(&Med-&Mbe)/1048576.0);
LgxTpre::mian();
cerr<<1e3*clock()/CLOCKS_PER_SEC<<" ms\n";
return (0-0);
}
Submission Info
| Submission Time |
|
| Task |
E - Modulo Nim |
| User |
MyYouthsoSTRONG |
| Language |
C++ (GCC 9.2.1) |
| Score |
900 |
| Code Size |
3649 Byte |
| Status |
AC |
| Exec Time |
1158 ms |
| Memory |
106532 KiB |
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
900 / 900 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
sample_01.txt, sample_02.txt, sample_03.txt |
| All |
hand2_01.txt, hand2_02.txt, hand2_03.txt, hand2_04.txt, hand2_05.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, sample_01.txt, sample_02.txt, sample_03.txt |
| Case Name |
Status |
Exec Time |
Memory |
| hand2_01.txt |
AC |
3 ms |
3724 KiB |
| hand2_02.txt |
AC |
2 ms |
3616 KiB |
| hand2_03.txt |
AC |
736 ms |
4692 KiB |
| hand2_04.txt |
AC |
4 ms |
4576 KiB |
| hand2_05.txt |
AC |
24 ms |
4764 KiB |
| hand_01.txt |
AC |
2 ms |
3556 KiB |
| hand_02.txt |
AC |
1 ms |
3628 KiB |
| hand_03.txt |
AC |
1158 ms |
106532 KiB |
| hand_04.txt |
AC |
1067 ms |
104608 KiB |
| hand_05.txt |
AC |
1051 ms |
103704 KiB |
| random_01.txt |
AC |
3 ms |
3736 KiB |
| random_02.txt |
AC |
2 ms |
3720 KiB |
| random_03.txt |
AC |
2 ms |
3700 KiB |
| random_04.txt |
AC |
2 ms |
3540 KiB |
| random_05.txt |
AC |
2 ms |
3696 KiB |
| random_06.txt |
AC |
735 ms |
6248 KiB |
| random_07.txt |
AC |
1048 ms |
96680 KiB |
| random_08.txt |
AC |
820 ms |
31808 KiB |
| random_09.txt |
AC |
963 ms |
73104 KiB |
| random_10.txt |
AC |
737 ms |
7552 KiB |
| random_11.txt |
AC |
1054 ms |
98820 KiB |
| random_12.txt |
AC |
922 ms |
85952 KiB |
| random_13.txt |
AC |
784 ms |
19440 KiB |
| random_14.txt |
AC |
741 ms |
7764 KiB |
| random_15.txt |
AC |
856 ms |
39812 KiB |
| sample_01.txt |
AC |
4 ms |
3624 KiB |
| sample_02.txt |
AC |
6 ms |
3732 KiB |
| sample_03.txt |
AC |
763 ms |
13716 KiB |