CodeChef submission 737718 (PAS fpc) plaintext list. Status: AC, problem COLCHAIN, contest . By giongto35 (giongto35), 2011-11-22 12:46:47.

uses math; const maxn=100002; cmod = 1000000007; var f1,f2:text; F:array[0..maxn*2] of longint; G:array[0..maxn*2] of longint; n,m:longint; T:longint; GT:array[0..maxn] of longint; res,i:longint; Procedure DP; var i,j:longint; begin Fillchar(F,sizeof(F),0); Fillchar(g,sizeof(G),0); For j:=1 to m do Begin if j<=n-m-1 then Begin G[j]:=(G[j-1]+G[j]) mod CMod; F[j]:=((int64((m+1)-j)*(m*int64(GT[m-1]) mod cmod) mod Cmod) mod CMod+G[j]) mod Cmod; G[j+1]:=(G[j+1]+F[j]) mod CMod; G[j+m]:=(G[j+m]-F[j]) Mod Cmod; ENd else Begin F[j]:=(int64((m+1)-j)*(m*int64(GT[m-1]) mod cmod) mod Cmod) mod CMod; End; F[j+m]:=F[j]; End; For j:=m+1 to n-m-1 do Begin G[j]:=(G[j-1]+G[j]) mod Cmod; F[j]:=(F[j]+G[j]) mod CMod; if j<n-m then Begin G[j+1]:=(G[j+1]+F[j]) mod CMod; G[j+m]:=(G[j+m]-F[j]) mod Cmod; End; F[j+m]:=F[j]; End; res:=0; for j:=max(1,n-m) to n-1 do Begin G[j]:=(G[j-1]+G[j]) mod CMod; F[j]:=(F[j]+G[j]) mod Cmod; End; For j:=max(1,n-m) to n-1 do res:=(res+F[j]) mod Cmod; While res<0 do res:=res+cmod; writeln(f2,res); end; Begin assign(f1,'');reset(f1); assign(F2,'');rewrite(F2); readln(f1,T); GT[0]:=1; for i:=1 to maxn do GT[i]:=(int64(Gt[i-1])*i) mod CMod; While T>0 do Begin readln(f1,n,m); DP; Dec(T); End; close(f1); close(F2); End.

## Comments

**Please login at the top to post a comment.**