题解:CF2194C Secret message
rerecloudy · · 题解
题意:
给出
做法:
枚举循环节,bitset 作值域合并,由于循环节为
复杂度:
代码:
/*
雲璃猫猫が好きです
すべての生命よ,歌のように輝いています
截剣式、斬、断、破です!
*/
#include<bits/stdc++.h>
#include<bits/extc++.h>
#define int long long
#define INF 1e18
#define lb long double
#define ls (id<<1)
#define rs (id<<1|1)
#define rep(i,l,r,k) for(int i=(l);i<=(r);i+=(k))
#define dep(i,r,l,k) for(int i=(r);i>=(l);i-=(k))
#define tep(ch,cr) for(auto ch:cr)
#define mk make_pair
#define me(a,b) memset(a,b,sizeof(a))
#define pb push_back
#define pr putchar
#define fi first
#define se second
#define wl while
#define max(a,b)((a)>(b)?(a):(b))
#define min(a,b)((a)<(b)?(a):(b))
#define debug puts("____________________________________________________________________________")
#define ce continue
#define bk break
#define sr sort
using namespace std;
random_device rd;
unsigned int seed=rd();
mt19937 Rand(seed);
typedef pair<int,int> pii;
const int M=1e5+110,mod=1e9+7,Mod=998244353;
__gnu_pbds::gp_hash_table<string,int>ml;
inline int read(){int sum=0,k=1;char c=getchar();
while(c>'9'||c<'0'){if(c=='-')k=-1;c=getchar();
}while(c>='0'&&c<='9'){sum=sum*10+c-48;c=getchar();
}return sum*k;
}inline void wr(int x){if(x<0) putchar('-'),x=-x;
if(x>9) wr(x/10);return void(putchar(x%10+'0'));}
int n,k;
bitset<30>s[M];
inline void work(){
n=read();k=read();
rep(i,1,n,1) s[i]=0;
rep(i,1,k,1){
string t;
cin>>t;
rep(j,1,n,1) s[j][(int)(t[j-1]-'a')]=1;
}
rep(i,1,n,1){
if(n%i) continue;
// cout<<"i:"<<i<<'\n';
bool ok=0;
bitset<30>oop[i+1];
for(int j=1;j<=i;j++) oop[j]=s[j];
for(int j=1;j<=n;j+=i){
for(int K=j;K<=j+i-1;K++){
oop[K-j+1]&=s[K];
// cout<<"j:"<<j<<" k:"<<K<<" oop[k-j+1]:"<<oop[K-j+1]<<" s[k]:"<<s[K]<<'\n';
if(oop[K-j+1]==0){
ok=1;bk;
}
}
}
if(ok==0){
string res="",ans="";
rep(j,1,i,1){
// cout<<"j:"<<j<<'\n';
rep(K,0,26,1) if(oop[j][K]==1){
// cout<<"K:"<<K<<'\n';
res+=(char)('a'+K);
bk;
}
}
rep(j,1,n/i,1) ans+=res;
cout<<ans<<'\n';
return void();
}
}
}
inline void test(int T){wl(T--) work();}
signed main(){
test(read());
return 0;
}
/*
*/