"Randomization algorithm" Codeforces Matrix God

Source: Internet
Author: User

http://codeforces.com/gym/101341

Test instructions

    • Given three square a,b,c, Q Ab=c is it set up?
    • The scale of the square is up to 1000.

Ideas

    • The time complexity for AB is n*n*n and will time out
    • Left multiply by one row n column vector, time complexity reduced to n*n

"Accepted"

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <string>5#include <algorithm>6#include <cmath>7#include <queue>8 9 using namespacestd;TentypedefLong Longll; One Const intinf=0x3f3f3f3f; A Const intmaxn=1e3+2; - Constll mod=1e9+7; -ll a[maxn][maxn],b[maxn][maxn],c[maxn][maxn],r[2][maxn],ra[2][maxn],rab[2][maxn],rc[2][MAXN]; the intn,m; -  - intMain () - { +      while(~SCANF ("%d",&N)) -     { +          for(intI=1; i<=n;i++) A         { at              for(intk=1; k<=n;k++) -             { -scanf"%lld",&a[i][k]); -             } -          }  -          for(intI=1; i<=n;i++) in         { -              for(intk=1; k<=n;k++) to             { +scanf"%lld",&b[i][k]); -             } the          }  *          for(intI=1; i<=n;i++) $         {Panax Notoginseng              for(intk=1; k<=n;k++) -             { thescanf"%lld",&c[i][k]); +             } A          }  the          for(intI=1; i<=n;i++) +         { -r[1][i]=rand ()% -+1; $         } $memset (RA,0,sizeof(RA)); -Memset (Rab,0,sizeof(RAB)); -          for(intI=1; i<=n;i++) the         { -              for(intk=1; k<=n;k++)Wuyi             { thera[1][i]= (ra[1][i]+r[1][K]*A[K][I]%MOD)%MoD; -             } Wu         } -          for(intI=1; i<=n;i++) About         { $              for(intk=1; k<=n;k++) -             { -rab[1][i]= (rab[1][i]+ra[1][K]*B[K][I]%MOD)%MoD; -             } A         } +          for(intI=1; i<=n;i++) the         { -              for(intk=1; k<=n;k++) $             { therc[1][i]= (rc[1][i]+r[1][K]*C[K][I]%MOD)%MoD; the             } the         } the         intflag=1; -          for(intI=1; i<=n;i++) in         { the             if(rab[1][i]!=rc[1][i]) the             {     Aboutflag=0; the                  Break; the             } the         } +         if(flag) -         { thePuts"YES");Bayi         } the         Else the         { -Puts"NO"); -         } the          the     }     the     return 0; the}
View Code

"Randomization algorithm" Codeforces Matrix God

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.