/ tabris /

记录详情

Time Exceeded

/in/foo.cc: In function 'int main()':
/in/foo.cc:76:37: warning: format '%d' expects argument of type 'int', but argument 2 has type 'll {aka long long int}' [-Wformat=]
             printf("%d ",ans.s[0][i]);
                                     ^
# 状态 耗时 内存占用
#1 Time Exceeded ≥10005ms ≥2.5 MiB
#2 Time Exceeded ≥10003ms ≥2.625 MiB
#3 Wrong Answer 197ms 2.613 MiB
#4 Wrong Answer 186ms 2.461 MiB
#5 Wrong Answer 197ms 2.461 MiB

代码

#include<bits/stdc++.h>
const int maxn = 2e2+5;
const int mod = 1e9+7;
using namespace std;
typedef long long ll;
typedef struct
{
    ll s[maxn][maxn];
}matrix;
ll n,k,m,a[maxn];
matrix mul(matrix A,matrix B)
{      matrix ans;
     memset(ans.s,0,sizeof(ans.s));
      for(int i = 0 ;i < n;i++)
       for(int j =0;j < n;j++)
       {

            for(int k = 0; k < n;k++)
             ans.s[i][k]=(ans.s[i][k]+A.s[i][j]*B.s[j][k] % mod + mod)%mod;
	   }
	   return ans;
}
matrix quickpow(matrix A,ll x)
{
	 matrix E;
     for(int i = 0;i < n;i++)
       for(int j = 0;j < n;j++)
       {  if(i == j)
           E.s[i][j] = 1;
           else
           E.s[i][j] = 0;
	   }//初始化,数初始化为1,矩阵应该初始化为单位矩阵;
	 while(x){
	 	 if(x&1)
	 	  {
		   E=mul(E,A);
	      }
	 	 A=mul(A,A);
	 	 x /= 2;
	 }
	 return E;
}
int main()
{
    int _;
    cin >> _;
    while(_--)
    {
        scanf("%lld %lld %lld",&n,&m,&k);
        for(int i = 0;i < n;++i)
        scanf("%lld",&a[i]);
        matrix mid ;
        memset(mid.s,0,sizeof mid.s);
        for(int i =0;i < n;++i)
        {
            for(int j = 0;j < n;++j)
            {
                if(i == j) mid.s[i][j] = 0;
                else
                    mid.s[i][j] = k - min(n - abs(j - i),(ll)abs(i - j));
            }
        }
       /* for(int i = 0;i < n;++i)
            for(int j = 0;j < n;++j)
            {
                printf("%d%c",mid.s[i][j],j == n-1 ? '\n' :' ');
            }*/

        mid = quickpow(mid,m-1);
        matrix ans;
        memset(ans.s,0,sizeof ans.s);
        for(int i = 0;i < n;++i)
            ans.s[0][i] = a[i];
        ans = mul(ans,mid);
        for(int i = 0;i < n;++i)
            printf("%d ",ans.s[0][i]);
        puts("");
    }
    return 0;
}

信息

递交者
类型
递交
题目
tabris is SirBat 2
语言
C++
递交时间
2017-11-26 17:14:28
评测时间
2017-11-26 17:14:28
评测机
分数
0
总耗时
≥20590ms
峰值内存
≥2.625 MiB