版本比较
题解 P4776 【[NOI2018]多边形】
正文
增加 24 行删除 24 行
20 行未改动2122232425252627282931 行未改动61626364656566676869101 行未改动全部展开17117217317417517517617717817918018118218318418518518618718818919019119219319319419519619719819920020120220320320420520620714 行未改动2222232242252262272262272282292302312322322332342352364 行未改动2412422432442452452462472482492502502512522532549 行未改动26426526626726826826927027127289 行未改动3623633643653663663673683693706 行未改动37737837938038138138238338438538638738738838939039139239039139239339439539639739839940040140240140240340440540615 行未改动42242342442542642642742842943018 行未改动44945045145245345345445545545645745845946046146246346446546546646746846912 行未改动20 行未改动#include<map>#include<cstring>#define ll long long#define maxn 1005#define p 998244353 #define p 998244353#define re(i,a,b) for(int i=a;i<=b;i++)using namespace std;inline int read(){char c=getchar();int f=1;int ans = 0;while(c>'9'||c<'0'){if(c=='-')f=-f;c=getchar();}while(c<='9'&&c>='0'){ans =ans*10+c-'0';c=getchar();}return ans*f;}//_____________________________________________________________________________________________________31 行未改动 leaf[++n] = leaf[y]; __a[_x][n] = __a[n][y] = 1; } } return _x; return _x;}inline void build(){ re(i,1,_n)101 行未改动全部展开 node1.s [j] = cnt+1; dfs2(i+1,cnt+1); node1.s [j] = 0; } node1.s [i] = 0; node1.s [i] = 0; }}struct turn{ int x,y,to; turn(int x=0,int y=0,int to=0) :x(x),y(y),to(to){};}f[7][7][210000];int tot_f[7][7];#define pr pair<int,int> #define pr pair<int,int>int st1[maxn*200],_st2;pr st2[maxn*200];inline void check(node x,int cnt){ re(i,k+1,x.len-k) if(x.s [i]) return; node1.clear(); node1.clear(); if(x.len>2*k) { node1.root = x.root ; node1.len = 2*k; re(i,1,k) node1.s [i] = x.s[i]; re(i,x.len -k+1,x.len ) node1.s [i- x.len + 2*k] = x.s[i] ; } else node1 = x; else node1 = x; node1.sort(cnt); if( mp[node1]!=0 ) st1[++st1[0]] = mp[node1];}14 行未改动 { node1 = x; re(t,1,x.len ) if( x.s [t] == x.s [i] || x.s [t]==x.s [j] ) node1.s[t] = n_col; node1.s [i] = node1.s [j] = 0; node1.s[t] = n_col; node1.s [i] = node1.s [j] = 0; dfs3(i+1,lim,node1,cnt+1); } if(x.s [j]==-1) { node1 = x; node1 = x; node1.s [j] = node1.s [i]; node1.s [i] = 0; dfs3(i+1,lim,node1,cnt+1); }4 行未改动 { node1 = x; if(x.s [j]==-1) node1.s [i] = node1.s [j] = cnt+1; else else node1.s [i] = node1.s [j], node1.s [j] = 0; dfs3(i+1,lim,node1,cnt+1); re(t,j+1,min(x.len,i+k)) if(x.s[t]==-1 ||(x.s[t]>0&&(x.s[t]!=x.s[j] || x.s[t]==1))) if(x.s[t]==-1 ||(x.s[t]>0&&(x.s[t]!=x.s[j] || x.s[t]==1))) { node1 = x; node1.s [i] = 0; if( x.s[j]==-1 && x.s[t] ==-1 )9 行未改动 if(x.s[_t]==x.s[j]|| x.s[_t] == x.s[t] ) node1.s [_t] = n_col ; node1.s [j] = node1.s [t] = 0; } dfs3(i+1,lim,node1,cnt+1); dfs3(i+1,lim,node1,cnt+1); } }}inline void Turn(node l,node r)89 行未改动 } } } } return cnt; return cnt;}void dfs4(int x){ int bo = 0,cnt_leaf=0;6 行未改动 memcpy(dp[x],dp[y],sizeof(dp[x])); bo = 1; cnt_leaf = leaf[y]; } else else { memcpy(_dp,dp[x],sizeof(_dp)); memset(dp[x],0,sizeof(dp[x])); re(t,1,tot_f[ cnt_leaf ][ leaf[y] ]) { turn _ = f[ cnt_leaf ][ leaf[y] ][t] ; turn _ = f[ cnt_leaf ][ leaf[y] ][t] ; ( dp[x][ _.to ] += _dp[ _.x ] * dp[y][ _.y ])%=p; } cnt_leaf = min( cnt_leaf + leaf[y] , 2*k); cnt_leaf = min( cnt_leaf + leaf[y] , 2*k);
} } if(!bo) { dp[x][1] = dp[x][2] = 1; return ; } if(x!=1) { {
memcpy(_dp,dp[x],sizeof(_dp)); memset(dp[x],0,sizeof(dp[x])); re(t,1,_tot_f) ( dp[x][ _f[t].second ] += _dp[ _f[t].first ] )%=p ;15 行未改动 re(i,1,n) leaf[i] = min( leaf[i],2*k ); if(n<=21) { solve1(); solve1(); return 0; } re(i,1,2*k) {18 行未改动 dfs2(1,1); node1.s[k] = 0; } node1.s[j]=0; } } } } } node1.clear(); node1.root = 2; node1.len = k*2; a[++tot] = node1; mp[node1] = tot; re(i,1,tot) re(j,1,tot) { st1[0] = 0; Turn(a[i],a[j]); Turn(a[i],a[j]); if(st1[0]) re(t,1,st1[0]) f[ a[i].len ][ a[j].len ][ ++tot_f[a[i].len ][a[j].len ]] = turn(i,j,st1[t]); }12 行未改动