为什么只有45分

P3941 入阵曲

TLE了吧?
by 小粉兔 @ 2017-11-02 22:34:11


@[小粉兔](/space/show?uid=10703) RE比较多
by Have_a_nice_day @ 2017-11-02 22:59:55


@[小粉兔](/space/show?uid=10703) 正解是怎么样?谢谢大佬
by Have_a_nice_day @ 2017-11-02 23:00:31


```cpp #include<cstdio> #include<cstring> #include<algorithm> #include<cctype> #define int long long using namespace std; int read() { int sum;char c;bool neg=0; while(!isdigit(c=getchar()))if(c=='-')neg=1;sum=c-'0'; while(isdigit(c=getchar())){sum*=10;sum+=c-'0';} return neg?-sum:sum; } int map[410][410],mod,cnt[1000010][2]; signed main() { int i,j,k,n,m,ans=0,sum,mark=0; n=read();m=read();mod=read(); for(i=1;i<=n;i++)for(j=1;j<=m;j++)map[i][j]=(map[i][j-1]+read())%mod; for(i=1;i<=m;i++) { for(j=i;j<=m;j++) { sum=0; mark=i*m+j; cnt[0][0]=1;cnt[0][1]=mark; for(k=1;k<=n;k++) { (sum+=map[k][j]-map[k][i-1]+mod)%=mod; if(cnt[sum][1]==mark) { ans+=cnt[sum][0]; cnt[sum][0]++; } else { cnt[sum][1]=mark; cnt[sum][0]=1; } } } } printf("%lld\n",ans); return 0; } ```
by feng_chengjie @ 2017-11-02 23:42:26


@[feng\_chengjie](/space/show?uid=36294) 谢谢。请问cnt[sum][0]和cnt[sum][1]分别是什么意思啊
by Have_a_nice_day @ 2017-11-03 09:46:37


```cpp #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #include<map> #define LL long long using namespace std; LL n,m,k,l,a[550][550],f[550][550],cnt[1000100],num[1000100]; bool mp[1000100]; LL ans,tot; int main(){ scanf("%lld%lld%lld",&n,&m,&k); for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) scanf("%lld",&a[i][j]); for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) f[i][j]=(f[i][j-1]+f[i-1][j]-f[i-1][j-1]+a[i][j])%k; for (int l=1;l<=m;l++) for (int r=l;r<=m;r++){ for (int j=1;j<=tot;j++) cnt[num[j]]=0; tot=0; for (int j=1;j<=n;j++){ LL t=(f[j][r]-f[j][l-1]+2*k)%k; num[++tot]=t; ans+=cnt[t]; cnt[t]++; } ans+=cnt[0]; } printf("%lld\n",ans); } ```
by Have_a_nice_day @ 2017-11-03 11:12:50


优化一下能过的
by Have_a_nice_day @ 2017-11-03 11:32:53


|