Summing sums (accepted on coding blocks but error on spoj)

#include
#include
using namespace std;

define int long long

#define mod 98765431
int t,n;
vector<vector> mul(vector<vector>a,vector<vector>b)
{
vector<vector>c(n+1,vector(n+1));
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
for(int x=0;x<n;x++)
c[i][j]=c[i][j]+a[i][x]*b[x][j];
c[i][j]=c[i][j]%mod;
}
}
return c;
}

vector<vector> pow(vector<vector>a,int t)
{
if(t==1)
return a;
if(t&1)
return mul(pow(a,t-1),a);
else
{vector<vector>q=pow(a,t/2);
return mul(q,q);
}
}
int32_t main() {

    cin>>n;
    cin>>t;
    vector<int>c(n+1);
for(int i=0;i<n;i++)
    cin>>c[i];
vector<vector<int>>a(n+1,vector<int>(n+1));
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
if(i!=j)
{
    a[i][j]=1;
}
else{
a[i][j]=0;
}    
a=pow(a,t);

for(int i=0;i<n;i++)
{ int t=0;
    for(int j=0;j<n;j++)
    {
        t=(t+(a[i][j]*c[j])%mod)%mod;

    }
    cout<<t<<endl;
}


return 0;

}

1 Like

time limit exceeded why??

time limit exceeded why??]

You can read the editorial there.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

Same my code got accepted in Blocks but not on SPOJ
link to code https://ide.codingblocks.com/s/256604
do tell me if you change something and it got accepted in SPOJ