时间复杂度求助
  • 板块P9391 红草莓
  • 楼主Light_az
  • 当前回复0
  • 已保存回复0
  • 发布时间2023/6/9 09:40
  • 上次更新2023/10/23 13:36:49
查看原帖
时间复杂度求助
654958
Light_az楼主2023/6/9 09:40

有人分析一下程序最坏情况下时间复杂度大概多少吗 qwq

#include<bits/stdc++.h>
#define ll int
#define F(i,j,n) for(int i=j;i<=n;i++)
#define B(i,j,n) for(int i=j;i>=n;i--)
#define Tr(v,e) for(int v:e)
#define D double
#define ps push_back
#define Test ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
using namespace std;
const int N=5e5+10,NN=1e4+10;
ll n,m,k,x,y,u,v,w,cnt=0,ans=0,t=0,l,r,len,T;
ll mn=INT_MAX,mx=0,Mod,id=1;
string s1,s2;
ll a[N],b[N],Can[N];
ll read(){
    ll s=0,w=1;
    char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-')w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') {s=s*10+ch-'0';ch=getchar();}
    return s*w;
}
inline void dfs(ll id,ll step){
	if(!a[id]) ans++,cnt++;
	a[id]=1;
	if(b[id]) return ;
	b[id]=1;
	dfs((id+x)%n,step+1);
	b[id]=0;
}
inline void write(ll x){
    if(x<0) {putchar('-');x=-x;}
    if(x>9) write(x/10);
    putchar(x%10+'0');
} 

inline void print(ll n){
	F(i,1,n) write(0),putchar(' ');
	return ;
}
int main(){
    n=read(),m=read();
	F(i,1,m){
		ans=0;
		x=read();
		if(!Can[x]){
			dfs(1,0);
			F(i,1,n/x) Can[x*i]=1;
			write(ans);
			putchar(' ');
		}	
		else write(0),putchar(' ');
		if(cnt==n){
			print(m-i);
			return 0;
		}
	}
	return 0;
}
2023/6/9 09:40
加载中...