社区讨论
求hack
AT_abc416_g [ABC416G] Concat (1st)参与者 5已保存回复 5
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 4 条
- 当前快照
- 1 份
- 快照标识符
- @mdlo90iu
- 此快照首次捕获于
- 2025/07/27 20:45 7 个月前
- 此快照最后确认于
- 2025/11/04 03:38 4 个月前
不知道为何错了,手搓了半天没弄出来hack,求帮助
CPP/*
Luogu name: Symbolize
Luogu uid: 672793
*/
#include<bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define x first
#define y second
#define rep1(i,l,r) for(int i=l;i<=r;++i)
#define rep2(i,l,r) for(int i=l;i>=r;--i)
#define rep3(i,x,y,z) for(int i=x[y];~i;i=z[i])
#define rep4(i,x) for(auto i:x)
#define debug() puts("----------")
const int N=1e5+10;
const int inf=0x3f3f3f3f3f3f3f3f;
using namespace std;
int n,k;
string s[N],t[N];
int read()
{
int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9')
{
if(ch=='-') f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9')
{
x=(x<<1)+(x<<3)+(ch^48);
ch=getchar();
}
return f*x;
}
bool cmp(string s1,string s2)
{
int l1=s1.length(),l2=s2.length();
// cout<<s1<<' '<<s2<<"\n";
rep1(i,0,min(l1,l2)-1)
{
// cout<<s1[i]<<' '<<s2[i]<<"\n";
if(s1[i]>s2[i]) return 1;
if(s1[i]<s2[i]) return 0;
}
if(l1>l2) return 1;
return 0;
}
signed main()
{
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
n=read();
k=read();
rep1(i,1,n) cin>>s[i];
string now=s[1];
rep1(i,2,n)
{
int l1=now.size(),l2=s[i].size();
int len=l1*l2/__gcd(l1,l2);
string s1="",s2="";
rep1(j,1,len/l1) s1+=now;
rep1(j,1,len/l2) s2+=s[i];
if(s1>s2||(s1==s2&&l1>l2)) now=s[i];
}
rep1(i,1,k-10) cout<<now;
k=min(k,10ll);
rep2(i,k,1)
{
int id=-1;
rep1(j,1,n)
{
t[j]="";
rep1(p,1,i) t[j]+=s[j];
if(id==-1||!cmp(t[j],t[id])) id=j;
}
cout<<s[id];
}
putchar('\n');
return 0;
}
/*
cbcbcbabcbcbc
3 4
cbcbcbab
cb
c
*/
回复
共 5 条回复,欢迎继续交流。
正在加载回复...