Submission #70054733
Source Code Expand
#include<bits/stdc++.h>
#include<bits/extc++.h>
//bool Mst;
using namespace std;
namespace wyzfastio
{
const char bool_str[2][6]={"false","true"};const int double_mx=12;
//#define usefio
#ifdef usefio
namespace __getchar{const int bufsize=1<<22;char buf[bufsize],*p1=buf,*p2=buf;inline char getchar(){return (p1==p2&&(p2=(p1=buf)+fread(buf,1,bufsize,stdin),p1==p2))?EOF:(*p1++);}}using __getchar::getchar;
namespace __putchar{const int bufsize=1<<22;char buf[bufsize],*p=buf;inline void putchar(const char ch){if(p-buf==bufsize) fwrite(buf,1,bufsize,stdout),p=buf;*p++=ch;}inline void flush(){fwrite(buf,1,p-buf,stdout);}}using __putchar::putchar;using __putchar::flush;
namespace __flusher{struct Flusher{Flusher(){}~Flusher(){flush();}}flusher;}
#endif
struct istream{void tie([[maybe_unused]]int x){}};struct ostream{void tie([[maybe_unused]]int x){}};struct estream{};istream in;ostream out;
#ifdef LOCAL
ostream err;
#else
estream err;
#endif
istream &operator>>(istream &in,char &s){s=getchar();while(s==' '||s=='\n'||s=='\r')s=getchar();return in;}
istream &operator>>(istream &in,std::string &s){char ch=getchar();s.clear();while(ch==' '||ch=='\n'||ch=='\r')ch=getchar();while(!(ch==' '||ch=='\n'||ch=='\r'||ch==EOF))s+=ch,ch=getchar();return in;}
istream &operator>>(istream &in,__int128 &x){char ch=getchar();int o=0;__int128 r=0;while(ch<'0'||ch>'9'){if(ch=='-')o^=1;ch=getchar();}while(ch>='0'&&ch<='9')r=(r<<3)+(r<<1)+ch-'0',ch=getchar();x=o?-r:r;return in;}
istream &operator>>(istream &in,unsigned __int128 &x){char ch=getchar();__int128 r=0;while(ch>='0'&&ch<='9')r=(r<<3)+(r<<1)+ch-'0',ch=getchar();x=r;return in;}
template<typename _Tp>inline typename std::enable_if<std::is_integral<_Tp>::value&&!std::is_same<_Tp,bool>::value,istream &>::type operator>>(istream &in,_Tp &x){char ch=getchar();int o=0;_Tp r=0;while(ch<'0'||ch>'9'){if(ch=='-')o^=1;ch=getchar();}while(ch>='0'&&ch<='9')r=(r<<3)+(r<<1)+ch-'0',ch=getchar();x=o?-r:r;return in;}
template<typename _Tp>inline typename std::enable_if<std::is_same<_Tp,bool>::value,istream &>::type operator>>(istream &in,_Tp &x){int r;in>>r;x=r;return in;}
template<typename _Tp>inline typename std::enable_if<std::is_floating_point<_Tp>::value,istream &>::type operator>>(istream &in,_Tp &x){_Tp r=0,p=1;int op=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')op=-op;ch=getchar();}while(ch>='0'&&ch<='9'){r=r*10+ch-'0';ch=getchar();}if(ch=='.'){ch=getchar();while(ch>='0'&&ch<='9')r+=(p*=0.1)*(ch-'0'),ch=getchar();}x=r*op;return in;}
ostream &operator<<(ostream &out,const char x){putchar(x);return out;}
ostream &operator<<(ostream &out,const char *s){while(*s!='\0'&&*s!=EOF)putchar(*s),s++;return out;}
ostream &operator<<(ostream &out,std::string s){for(char ch:s)putchar(ch);return out;}
ostream &operator<<(ostream &out,__int128 x){static int __stk[66];int top=0,op=1-((x<0)<<1);if(x==0)__stk[top++]=0;else while(x)__stk[top++]=(x%10)*op,x/=10;if(op==-1)putchar('-');while(top)putchar(__stk[--top]+'0');return out;}
ostream &operator<<(ostream &out,unsigned __int128 x){static int __stk[66];int top=0;if(x==0)__stk[top++]=0;else while(x)__stk[top++]=(x%10),x/=10;while(top)putchar(__stk[--top]+'0');return out;}
template<typename _Tp>inline typename std::enable_if<std::is_integral<_Tp>::value&&!std::is_same<_Tp,bool>::value,ostream &>::type operator<<(ostream &out,_Tp x){static int __stk[33];int top=0,op=1-((x<0)<<1);if(x==0)__stk[top++]=0;else while(x)__stk[top++]=(x%10)*op,x/=10;if(op==-1)putchar('-');while(top)putchar(__stk[--top]+'0');return out;}
template<typename _Tp>inline typename std::enable_if<std::is_same<_Tp,bool>::value,ostream &>::type operator<<(ostream &out,_Tp x){out<<bool_str[x];return out;}
template<typename _Tp>inline typename std::enable_if<std::is_floating_point<_Tp>::value,ostream &>::type operator<<(ostream &out,_Tp x){if(x<0)putchar('-'),x=-x;static int __stk[233];int top=0;for(int i=0;i<double_mx;i++)x*=10;x=std::floor(x+0.5);for(_Tp y;x>=1;)y=std::floor(x/10),__stk[top++]=x-y*10,x=y;while(top<=double_mx)__stk[top++]=0;while(top>double_mx)putchar(__stk[--top]+'0');putchar('.');while(top)putchar(__stk[--top]+'0');return out;}
template<typename _Tp>inline estream &operator<<(estream &err,[[maybe_unused]]_Tp x){return err;}
#define cin wyzfastio::in
#define cout wyzfastio::out
#define cerr wyzfastio::err
}
using ll=long long;
using ld=long double;
//#define int ll
using pii=pair<int,int>;
int n,m,pos;ll ans=0;
int a[65];
__gnu_pbds::gp_hash_table<int,int> mp[2];
void dfs1(int u,int s,int f,int c)
{
if(u>pos) return mp[f][s]++,void();
dfs1(u+1,s,f,0);
if(!c) dfs1(u+1,(s+a[u])%m,f|(u==pos),1);
}
void dfs2(int u,int s,int f,int c)
{
if(u>n)
{
ans+=mp[0][(m-s)%m];
if(!f) ans+=mp[1][(m-s)%m];
return;
}
dfs2(u+1,s,f,0);
if(!c) dfs2(u+1,(s+a[u])%m,f|(u==pos+1),1);
}
//bool Med;
signed main()
{
// cerr<<"Memory Size: "<<abs((&Med)-(&Mst))/1024.0/1024<<" MB\n";
// ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
// freopen("in.in","r",stdin);
// freopen("out.out","w",stdout);
cin>>n>>m;
pos=n/2;
for(int i=1;i<=n;i++) cin>>a[i];
dfs1(1,0,0,0);
dfs2(pos+1,0,0,0);
cout<<ans<<"\n";
return 0;
}
Submission Info
| Submission Time |
|
| Task |
F - Not Adjacent |
| User |
wangyizhi |
| Language |
C++ 20 (gcc 12.2) |
| Score |
525 |
| Code Size |
5236 Byte |
| Status |
AC |
| Exec Time |
691 ms |
| Memory |
249196 KiB |
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
525 / 525 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt |
| All |
00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt, 01_random_40.txt, 01_random_41.txt, 01_random_42.txt, 01_random_43.txt, 01_random_44.txt, 01_random_45.txt, 01_random_46.txt, 01_random_47.txt, 01_random_48.txt, 01_random_49.txt, 01_random_50.txt, 01_random_51.txt, 01_random_52.txt |
| Case Name |
Status |
Exec Time |
Memory |
| 00_sample_00.txt |
AC |
1 ms |
3516 KiB |
| 00_sample_01.txt |
AC |
1 ms |
3580 KiB |
| 00_sample_02.txt |
AC |
1 ms |
3516 KiB |
| 01_random_03.txt |
AC |
691 ms |
249096 KiB |
| 01_random_04.txt |
AC |
686 ms |
249132 KiB |
| 01_random_05.txt |
AC |
685 ms |
248988 KiB |
| 01_random_06.txt |
AC |
682 ms |
249092 KiB |
| 01_random_07.txt |
AC |
686 ms |
249080 KiB |
| 01_random_08.txt |
AC |
590 ms |
199792 KiB |
| 01_random_09.txt |
AC |
690 ms |
249044 KiB |
| 01_random_10.txt |
AC |
686 ms |
249052 KiB |
| 01_random_11.txt |
AC |
1 ms |
3516 KiB |
| 01_random_12.txt |
AC |
4 ms |
4636 KiB |
| 01_random_13.txt |
AC |
2 ms |
3644 KiB |
| 01_random_14.txt |
AC |
26 ms |
15596 KiB |
| 01_random_15.txt |
AC |
6 ms |
6140 KiB |
| 01_random_16.txt |
AC |
585 ms |
199932 KiB |
| 01_random_17.txt |
AC |
689 ms |
249056 KiB |
| 01_random_18.txt |
AC |
689 ms |
249040 KiB |
| 01_random_19.txt |
AC |
684 ms |
249104 KiB |
| 01_random_20.txt |
AC |
81 ms |
10992 KiB |
| 01_random_21.txt |
AC |
592 ms |
199788 KiB |
| 01_random_22.txt |
AC |
684 ms |
249196 KiB |
| 01_random_23.txt |
AC |
533 ms |
199904 KiB |
| 01_random_24.txt |
AC |
1 ms |
3600 KiB |
| 01_random_25.txt |
AC |
2 ms |
3892 KiB |
| 01_random_26.txt |
AC |
3 ms |
4624 KiB |
| 01_random_27.txt |
AC |
1 ms |
3576 KiB |
| 01_random_28.txt |
AC |
7 ms |
6140 KiB |
| 01_random_29.txt |
AC |
414 ms |
126084 KiB |
| 01_random_30.txt |
AC |
553 ms |
199852 KiB |
| 01_random_31.txt |
AC |
436 ms |
126216 KiB |
| 01_random_32.txt |
AC |
356 ms |
101740 KiB |
| 01_random_33.txt |
AC |
431 ms |
126208 KiB |
| 01_random_34.txt |
AC |
418 ms |
126160 KiB |
| 01_random_35.txt |
AC |
547 ms |
199860 KiB |
| 01_random_36.txt |
AC |
422 ms |
126228 KiB |
| 01_random_37.txt |
AC |
1 ms |
3608 KiB |
| 01_random_38.txt |
AC |
1 ms |
3448 KiB |
| 01_random_39.txt |
AC |
1 ms |
3516 KiB |
| 01_random_40.txt |
AC |
1 ms |
3476 KiB |
| 01_random_41.txt |
AC |
13 ms |
9224 KiB |
| 01_random_42.txt |
AC |
36 ms |
3444 KiB |
| 01_random_43.txt |
AC |
37 ms |
3472 KiB |
| 01_random_44.txt |
AC |
36 ms |
3476 KiB |
| 01_random_45.txt |
AC |
36 ms |
3512 KiB |
| 01_random_46.txt |
AC |
57 ms |
3584 KiB |
| 01_random_47.txt |
AC |
37 ms |
3472 KiB |
| 01_random_48.txt |
AC |
36 ms |
3448 KiB |
| 01_random_49.txt |
AC |
1 ms |
3664 KiB |
| 01_random_50.txt |
AC |
1 ms |
3476 KiB |
| 01_random_51.txt |
AC |
1 ms |
3480 KiB |
| 01_random_52.txt |
AC |
1 ms |
3512 KiB |