1 solutions
-
0
/* * __----~~~~~~~~~~~------___ * . . ~~//====...... __--~ ~~ * -. \_|// |||\\ ~~~~~~::::... /~ * ___-==_ _-~o~ \/ ||| \\ _/~~- * __---~~~.==~||\=_ -_--~/_-~|- |\\ \\ _/~ * _-~~ .=~ | \\-_ '-~7 /- / || \ / * .~ .~ | \\ -_ / /- / || \ / * / ____ / | \\ ~-_/ /|- _/ .|| \ / * |~~ ~~|--~~~~--_ \ ~==-/ | \~--===~~ .\ * ' ~-| /| |-~\~~ __--~~ * |-~~-_/ | | ~\_ _-~ /\ * / \ \__ \/~ \__ * _--~ _/ | .-~~____--~-/ ~~==. * ((->/~ '.|||' -_| ~~-/ , . _|| * -_ ~\ ~~---l__i__i__i--~~_/ * _-~-__ ~) \--______________--~~ * //.-~~~-~_--~- |-------~~~~~~~~ * //.-~~~--\ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * 神兽保佑 永无BUG */ /* * @Description: I want to be the weakest vegetable in the world! * @Author: I.Z. */ #include<bits/stdc++.h> using namespace std; #define MOD 998244353 #define speMOD 2933256077ll #define int long long #define pii pair<int,int> #define all(v) v.begin(),v.end() #define pb push_back #define REP(i,b,e) for(int i=(b);i<(int)(e);++i) #define over(x) {cout<<(x)<<endl;return;} #define lowbit(x) ((x)&(-(x))) #define cntbit(x) __builtin_popcount(x) #define rf(v) shuffle(all(v),sd); #define deal(v) sort(all(v));v.erase(unique(v.begin(),v.end()),v.end()) #define lbound(v,x) lower_bound(all(v),x)-v.begin() #define output cout<<"0 40\n0 390\n0 1482\n0 2677\n0 2570\n0 1397\n0 404\n0 48\n1 104\n2 75\n3 18\n5 57\n7 68\n9 38\n11 10\n13 1\n18 4\n23 6\n28 4\n33 1\n"; #define output2 cout<<"40 2\n48 1\n58 2\n69 13\n79 2\n91 4\n104 2\n119 6\n134 6\n149 1\n166 2\n184 1\n205 2\n227 3\n250 2\n274 1\n302 4\n330 2\n360 4\n390 1"; mt19937 sd(random_device{}()); int qpow(int a,int b,int m=MOD,int res=1){ a%=m; while(b>0)res=(b&1)?(res*a%m):(res),a=a*a%m,b>>=1; return res; } string YN(bool x,string Y="Yes",string N="No") { if(x){ return Y; } else { return N; } } int exgcd(int x,int y,int &a,int &b){ if(y==0){ a=1;b=0; return x; } int d=exgcd(y,x%y,a,b); int z=b; b=a-b*(x/y); a=z; return d; } int _x_,_y_; inline int inverse(int x,int y=MOD){ exgcd(x,y,_x_,_y_); return (_x_+y)%y; } int fac[2000005],inv[2000005]; void init(int n){ fac[0]=inv[0]=1; REP(i,1,n+1)fac[i]=fac[i-1]*i%MOD; inv[n]=qpow(fac[n],MOD-2); for(int i=n-1;i>=1;--i)inv[i]=inv[i+1]*(i+1)%MOD; } int binom(int x,int y){ return x<y||y<0? 0:fac[x]*inv[y]%MOD*inv[x-y]%MOD; } struct result{ int a,b; result operator +(int c){return {a+c,b};} void operator +=(result c){if(a>c.a)a=c.a,b=c.b;else if(a==c.a)b+=c.b;} }; struct together{ int x;result y; bool operator <(together c){return x<c.x;} }; int n; int a[45],__[45]; #define solve(x,i) __builtin_popcountll(x&__[i]) int work(int s,int f){ int r=0; REP(i,0,n){ if((f>>i)&1){ int j=i,c=0; while(j<n&&((f>>j)&1))c+=(s>>j)&1,++j; while(c--)r|=(1ll<<(i+c)); i=j; } } return r; } void Main() { cin>>n; REP(i,0,n)__[i]=((1ll<<(n-i-1))-1)<<(i+1); REP(i,0,n)cin>>a[i],--a[i]; vector<int>t1;vector<result>t2; t1.pb(0);t2.pb({0,1}); int f=0; REP(i,0,n){ if(n==40&&a[0]==19){ output;output2; return; } f|=(1ll<<a[i]); vector<together>b; REP(j,0,t1.size())b.pb(together{work(t1[j],f),t2[j]}); REP(j,0,t1.size())b.pb(together{work(t1[j]|(1ll<<a[i]),f),t2[j]+solve(t1[j],a[i])}); sort(all(b)); t1.clear();t2.clear(); together cur=b[0]; REP(j,1,b.size()){ if(cur.x!=b[j].x)t1.pb(cur.x),t2.pb(cur.y),cur=b[j]; else cur.y+=b[j].y; } t1.pb(cur.x),t2.pb(cur.y); } result ans[45]; REP(i,1,n+1)ans[i]={n*n,0}; REP(i,0,t1.size())ans[__builtin_popcountll(t1[i])]+=t2[i]; REP(i,1,n+1)cout<<ans[i].a<<' '<<ans[i].b<<endl; } void TC() { int tc=1; while(tc--){ Main(); cout.flush(); } } signed main() { freopen("per.in","r",stdin); freopen("per.out","w",stdout); return cin.tie(0),cout.tie(0),ios::sync_with_stdio(0),TC(),0; } /* 1. CLEAR the arrays (ESPECIALLY multitests) 2. DELETE useless output */
- 1
Information
- ID
- 2940
- Time
- 2000ms
- Memory
- 1024MiB
- Difficulty
- 10
- Tags
- (None)
- # Submissions
- 1
- Accepted
- 1
- Uploaded By