SOL:
那个,其实这道题爆搜能过。正解好像是建模后求欧拉回路。
#pragma GCC optimize("-Ofast") #include<bits/stdc++.h> using namespace std; int len,c,l; int no; char ch[29]; bool usd[11001009]; unsigned char dla[11001009],now[11001009]; #define sight(c) (‘0‘<=c&&c<=‘9‘) inline void read(int &x){ static char c; for (c=getchar();!sight(c);c=getchar()); for (x=0;sight(c);c=getchar())x=x*10+c-48; } int ple,pl,pll; inline bool tr(int x){ if (x==c) return 0; return usd[no+x]; } void sol(int c,int l){ len=pow(c,l)+l-1; ple=pow(c,l); pl=pow(c,l-1); usd[0]=1; //q[0]++; qq[0]++; qqq[0]++; for (int i=l+1;i<=len;i++,no=no*c-ple*now[i-l]) { now[i]=now[i]+dla[i]; dla[i]=0; while (tr(now[i])) now[i]++; if (now[i]>=c) { now[i]=0; no=(no+ple*now[i-l])/c; i--; no=(no+ple*now[i-l])/c; i--; // no=(no+ple*now[i-l]*c+ple*now[i-l-1])/(c*c); i-=2; usd[no*c-ple*now[i-l+1]+now[i+1]]=0; dla[i+1]++; } else { no+=now[i]; usd[no]=1; } } } signed main () { freopen("life.in","r",stdin); freopen("life.out","w",stdout); read(c); read(l); sol(c,l); scanf("%s",ch); printf("%d\n",len); for (int i=1;i<=len;i++) putchar(ch[now[i]]); return 0; }