Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
33115 LYLAKIOIAKIOI 【S】T2 C++ 解答错误 10 2000 MS 15820 KB 2054 2024-10-04 14:36:31

Tests(2/20):


#include<bits/stdc++.h> using namespace std; #define ll long long const int mod=1e9+7,tim=2e6+10,B=300; int n,m,t; int tg[tim]; int e[80][80]; struct mat{ int h,w;int v[80][80]; mat operator*(const mat &b) const{ mat res;res.h=h;res.w=b.w; for(int i=1;i<=res.h;i++){ for(int j=1;j<=res.w;j++){ res.v[i][j]=0; for(int k=1;k<=w;k++){ res.v[i][j]+=1ll*v[i][k]*b.v[k][j]%mod; res.v[i][j]%=mod; } } }return res; } }; int get(mat a,mat b,int k){ int res=0; for(int i=1;i<=a.w;i++){ res+=1ll*a.v[1][i]*b.v[i][k]%mod; res%=mod; }return res; } int qp(int a,int b){ int x=1; while(b){ if(b&1) x=1ll*a*x%mod; b>>=1;a=1ll*a*a%mod; }return x; }int g(int x){ return qp(x,mod-2); }int du[80]; mat a[B+20]; int main(){ //freopen("citywalk.in","r",stdin); //freopen("citywalk.out","w",stdout); cin>>n>>m>>t; for(int i=1;i<=n;i++){ string s;cin>>s;s=' '+s; for(int j=1;j<=n;j++){ e[i][j]=s[j]-'0'; if(e[i][j]) du[i]++; } }for(int i=1;i<=m;i++){ int ti,vi;cin>>ti>>vi; tg[ti]=vi; }mat st,to,I;st.h=1,st.w=n;to.h=n,to.w=n;I.h=n,I.w=n; for(int i=1;i<=n;i++) st.v[1][i]=0; for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ if(e[i][j]) to.v[i][j]=g(du[i]); else to.v[i][j]=0; I.v[i][j]=(i==j); //cout<<i<<' '<<j<<' '<<I.v[i][j]<<endl; } }a[0]=I; a[1]=to; for(int i=2;i<=B;i++){ a[i]=a[i-1]*to; } int ans=0; int lp=1; while(lp<=t){ int dt=0;//cout<<lp<<' '; st=st*to; if(tg[lp]){ st.v[1][tg[lp]]++; ans^=st.v[1][n];lp++; continue; } while(dt<=B&&lp+dt<=t&&tg[lp+dt]==0){ ans^=get(st,a[dt],n);dt++; //cout<<get(st,a[0],n)<<' '; }st=st*a[dt];lp=lp+dt; } cout<<ans; return 0; }


测评信息: