QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#89248 | #5368. 异世界的文章分割者 | fengyuyue | 0 | 0ms | 0kb | C++14 | 4.6kb | 2023-03-19 13:43:38 | 2023-03-19 13:43:41 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define fi first
#define se second
#define mkp make_pair
#define pb push_back
#define gc getchar
#define pc putchar
#define pii pair<int,int>
#define pil pair<int,long long>
#define pli pair<long long,int>
#define pll pair<long long,long long>
#define For(i,l,r) for(int i=(l);i<=(r);i++)
#define IFor(i,r,l) for(int i=(r);i>=(l);i--)
#define for_son(u) for(int e=head[u];e;e=nxt[e])
#define eps (1e-8)
#define INF 0x3f3f3f3f
using namespace std;
char aa;
namespace ljh
{
namespace IO
{
// const int SIZ=1<<20;
// char ibuf[SIZ],*p1,*p2,obuf[SIZ],*p3=obuf;
// #define gc() (p1==p2&&(p2=(p1=ibuf)+fread(ibuf,1,SIZ,stdin),p1==p2)?EOF:*p1++)
// void pc(const char &c)
// {
// if(p3-obuf==SIZ) fwrite(obuf,1,SIZ,stdout),p3=obuf;
// *p3++=c;
// }
int rd()
{
int x=0,f=1;
char ch=gc();
while(!isdigit(ch)){
if(ch=='-') f=-1;
ch=gc();
}
while(isdigit(ch)){
x=x*10+ch-'0';
ch=gc();
}
return x*f;
}
void wr(int x,char ch)
{
if(x<0) x=-x,pc('-');
static char st[12];
int top=0;
do{
st[top++]=x%10+'0',x/=10;
}while(x);
while(top) pc(st[--top]);
pc(ch);
}
ll ll_rd()
{
ll x=0;
int f=1;
char ch=gc();
while(!isdigit(ch)){
if(ch=='-') f=-1;
ch=gc();
}
while(isdigit(ch)){
x=x*10+ch-'0';
ch=gc();
}
return x*f;
}
void ll_wr(ll x,char ch)
{
if(x<0) x=-x,pc('-');
static char st[22];
int top=0;
do{
st[top++]=x%10+'0',x/=10;
}while(x);
while(top) pc(st[--top]);
pc(ch);
}
}
using namespace IO;
const int N=5e4+5,mod=0;
namespace tem
{
int qpow(int a,int b,int p)
{
a%=p;
int res=1;
while(b){
if(b&1) res=1ll*res*a%p;
a=1ll*a*a%p;
b>>=1;
}
return res;
}
int get_inv(int x){return qpow(x,mod-2,mod);}
int lowbit(int x){return x&(-x);}
void add(int &x,const int y){ x=(x+y>=mod?x+y-mod:x+y); }
// int get(int x) {return fa[x]==x?x:fa[x]=get(fa[x])};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
}
using namespace tem;
struct Node{
int fa,len,nxt[2];
#define fa(p) node[p].fa
#define len(p) node[p].len
#define nxt(p,c) node[p].nxt[c]
}node[N<<1];
int lst=1,idx=1,siz[N<<1];
int cnt=1,head[N<<1],nxt[N<<1],to[N<<1];
int n,k,f[N];
ll now=0;
char s[N];
void add_edge(int u,int v){nxt[++cnt]=head[u],to[cnt]=v,head[u]=cnt;}
void ext(int c)
{
int p=lst,np=lst=++idx;
len(np)=len(p)+1;
for(;p&&!nxt(p,c);p=fa(p)) nxt(p,c)=np;
if(!p) fa(np)=1;
else{
int q=nxt(p,c);
if(len(q)==len(p)+1) fa(np)=q;
else{
int nq=++idx;
node[nq]=node[q],len(nq)=len(p)+1;
fa(q)=fa(np)=nq;
for(;p&&nxt(p,c)==q;p=fa(p)) nxt(p,c)=nq;
}
}
}
void dfs(int u)
{
// cerr<<u<<endl;
for_son(u){
int v=to[e];
dfs(v);
siz[u]+=siz[v];
}
now+=1ll*(len(u)-len(fa(u)))*f[siz[u]];
}
ll calc(int l,int r)
{
// cerr<<"calc "<<l<<" "<<r;
cnt=1;
For(i,1,idx) node[i]={0,0,{0,0}},siz[i]=head[i]=0;
now=0;
lst=idx=1;
For(i,l,r) ext(s[i]-'0'),siz[lst]=1;
For(i,2,idx) add_edge(fa(i),i);
dfs(1);
// cerr<<" = "<<now<<endl;
return now;
}
bool check(ll lim)
{
int res=0;
for(int i=1,j=0;i<=n;i=j+1){
if(k>5){
int stp=1;
j=i-1;
while(stp){
if(j+stp<=n){
if(calc(i,j+stp)<=lim) j+=stp,stp<<=1;
else stp>>=1;
}
else stp>>=1;
}
}
else{
int l=i,r=n;
while(l<r){
int mid=(l+r+1)>>1;
if(calc(i,mid)<=lim) l=mid;
else r=mid-1;
}
j=l;
}
if(j<i) return false;
++res;
if(res>k) return false;
}
return res<=k;
}
void main()
{
n=rd(),k=rd();
scanf("%s",s+1);
For(i,1,n) f[i]=rd();
ll l=0,r=1ll*n*f[n];
while(l<r){
ll mid=(l+r)>>1;
if(check(mid)) r=mid;
else l=mid+1;
// cerr<<"check "<<mid<<" = "<<check(mid)<<endl;
}
ll_wr(r,'\n');
// fwrite(obuf,1,p3-obuf,stdout);
}
/*
*/
}
char bb;
signed main()
{
// freopen("1.in","r",stdin);
// freopen("ex_separate4.out","w",stdout);
// int st=clock();
ljh::main();
// int ed=clock();
// cerr<<ed-st<<"ms"<<endl;
// cerr<<(&bb-&aa)/1024/1024<<"MB"<<endl;
// fclose(stdin);
// fclose(stdout);
return 0;
}
详细
Subtask #1:
score: 0
Time Limit Exceeded
Test #1:
score: 0
Time Limit Exceeded
input:
10 3 aaaaaaaaaa
output:
result:
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
0%
Subtask #5:
score: 0
Skipped
Dependency #1:
0%