답안 #634162

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
634162 2022-08-23T23:20:59 Z inksamurai Klavir (COCI17_klavir) C++17
96 / 160
64 ms 65536 KB
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rng(i,c,n) for(int i=c;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define vec(...) vector<__VA_ARGS__>
#define _3PGDklf ios::sync_with_stdio(0),cin.tie(0)
typedef long long ll;
using pii=pair<int,int>;
using vi=vector<int>;
void print(){cout<<'\n';}
template<class h,class...t>
void print(const h&v,const t&...u){cout<<v<<' ',print(u...);}
// e

//snuke's mod int
template <ll mod>
struct modint{
	ll x; // typedef long long ll;
	modint(ll x=0):x((x%mod+mod)%mod){}
	modint operator-()const{return modint(-x);}
	modint& operator+=(const modint a){if((x+=a.x)>=mod) x-=mod; return *this;}
	modint& operator-=(const modint a){if((x+=mod-a.x)>=mod) x-=mod; return *this;}
	modint& operator*=(const modint a){(x*=a.x)%=mod; return *this;}
	modint operator+(const modint a)const{modint res(*this); return res+=a;}
	modint operator-(const modint a)const{modint res(*this); return res-=a;}
	modint operator*(const modint a)const{modint res(*this); return res*=a;}
	modint pow(ll n)const{
		modint res=1,x(*this);
		while(n){
			if(n&1)res*=x;
			x*=x;
			n>>=1;
		}
		return res;
	}
	modint inv()const{return pow(mod-2);}
};

using mint=modint<1000000007>;

const int _n=1000001;

int a[_n],pi[_n];

std::map<int,int> link[_n];

using pmi=pair<mint,mint>;
pmi e[_n];

signed main(){
_3PGDklf;
	int n,m;
	cin>>n>>m;
	rep(i,m){
		cin>>a[i];
		a[i]-=1;
	}
	// e(0)*p.fi+p.se
	e[0]={1,0};
	auto find_link=[&](int i,int ch)->int{
		if(!i){
			return ch==a[0];
		}
		int j=pi[i-1],pj=pi[i-1];
		if(link[j].find(ch)!=link[j].end()) return link[j][ch];
		while(j and a[j]!=ch){
			j=pi[j-1];
		}
		j+=a[j]==ch;
		return link[pj][ch]=j;
	};
	pmi now={0,0},ad={0,0};
	rep(i,m){
		int u=a[i];
		ad={0,0};
		rep(v,n){
			if(v==u) continue;
			// suppose i had matching with length i and pushed character v
			// find length of the lcsuff
			int nj=find_link(i,v);
			ad.fi+=e[nj].fi;
			ad.se+=e[nj].se+1;
		}
		now.fi=mint(n)*e[i].fi-ad.fi;
		now.se=mint(n)*e[i].se-ad.se-mint(1);
		e[i+1]=now;
		// now.fi*e[0]+now.se=0
		// now.fi*e[0]=-now.se
		mint x=-now.se*now.fi.inv();
		cout<<x.x<<" ";
		if(i>0){
			int nj=find_link(i,u);
			pi[i]=nj;
		}
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 62924 KB Output is correct
2 Correct 30 ms 62932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 62856 KB Output is correct
2 Correct 30 ms 62900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 62924 KB Output is correct
2 Correct 30 ms 62932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 62828 KB Output is correct
2 Correct 30 ms 62920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 62908 KB Output is correct
2 Correct 31 ms 62932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 62872 KB Output is correct
2 Correct 31 ms 62920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 64848 KB Output is correct
2 Runtime error 61 ms 65536 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 61 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 60 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 62 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -