洛谷-P10102:萌新刚学oi,被卡常拼全无胜,玄关
  • 板块题目总版
  • 楼主Jeff_赵
  • 当前回复4
  • 已保存回复4
  • 发布时间2025/7/26 17:31
  • 上次更新2025/7/26 23:21:01
查看原帖
洛谷-P10102:萌新刚学oi,被卡常拼全无胜,玄关
476081
Jeff_赵楼主2025/7/26 17:31

P10102 code:

#include<bits/stdc++.h> 
#define int long long 
using namespace std ; 

#ifdef __linux__
#define gc getchar_unlocked
#define pc putchar_unlocked
#else
#define gc _getchar_nolock
#define pc _putchar_nolock
#endif
inline bool blank(const char x) {return !(x^32)||!(x^10)||!(x^13)||!(x^9);}
template<typename Tp> inline void read(Tp &x) {x=0; register bool z=true; register char a=gc(); for(;!isdigit(a);a=gc()) if(a=='-') z=false; for(;isdigit(a);a=gc()) x=(x<<1)+(x<<3)+(a^48); x=(z?x:~x+1);}
inline void read(double &x) {x=0.0; register bool z=true; register double y=0.1; register char a=gc(); for(;!isdigit(a);a=gc()) if(a=='-') z=false; for(;isdigit(a);a=gc()) x=x*10+(a^48); if(a!='.') return x=z?x:-x,void(); for(a=gc();isdigit(a);a=gc(),y/=10) x+=y*(a^48); x=(z?x:-x);}
inline void read(char &x) {for(x=gc();blank(x)&&(x^-1);x=gc());}
inline void read(char *x) {register char a=gc(); for(;blank(a)&&(a^-1);a=gc()); for(;!blank(a)&&(a^-1);a=gc()) *x++=a; *x=0;}
inline void read(string &x) {x=""; register char a=gc(); for(;blank(a)&&(a^-1);a=gc()); for(;!blank(a)&&(a^-1);a=gc()) x+=a;}
template<typename T,typename ...Tp> inline void read(T &x,Tp &...y) {read(x),read(y...);}
template<typename Tp> inline void write(Tp x) {if(!x) return pc(48),void(); if(x<0) pc('-'),x=~x+1; register int len=0; register char tmp[64]; for(;x;x/=10) tmp[++len]=x%10+48; while(len) pc(tmp[len--]);}
inline void write(const double x) {register int a=6; register double b=x,c=b; if(b<0) pc('-'),b=-b,c=-c; register double y=5*powl(10,-a-1); b+=y,c+=y; register int len=0; register char tmp[64]; if(b<1) pc(48); else for(;b>=1;b/=10) tmp[++len]=floor(b)-floor(b/10)*10+48; while(len) pc(tmp[len--]); pc('.'); for(c*=10;a;a--,c*=10) pc(floor(c)-floor(c/10)*10+48);}
inline void write(const pair<int,double>x) {register int a=x.first; if(a<7) {register double b=x.second,c=b; if(b<0) pc('-'),b=-b,c=-c; register double y=5*powl(10,-a-1); b+=y,c+=y; register int len=0; register char tmp[64]; if(b<1) pc(48); else for(;b>=1;b/=10) tmp[++len]=floor(b)-floor(b/10)*10+48; while(len) pc(tmp[len--]); a&&(pc('.')); for(c*=10;a;a--,c*=10) pc(floor(c)-floor(c/10)*10+48);} else cout<<fixed<<setprecision(a)<<x.second;}
inline void write(const char x) {pc(x);}
inline void write(const bool x) {pc(x?49:48);}
inline void write(char *x) {fputs(x,stdout);}
inline void write(const char *x) {fputs(x,stdout);}
inline void write(const string &x) {fputs(x.c_str(),stdout);}
template<typename T,typename ...Tp> inline void write(T x,Tp ...y) {write(x),write(y...);}


const int N = 3010 , Mod = 998244353 ; 
int n ; 
struct Matrix
{
    array< array< int , N > , N > a ; 
    array< int , N > & operator [] ( const int i ) { return a[ i ] ; }
    void init( ) {for( auto &x : a ) x.fill( 0 ) ; }
    array< int , N > operator * ( array< int , N >& input_a ) 
    {
        array< int , N > ans ; 
        for( int i = 0 ; i < n ; i ++ ) 
        {
            ans[ i ] = 0 ; 
            for( int j = 0 ; j < n ; j ++ ) 
            {
                ans[ i ] = ( input_a[ j ] * a[ j ][ i ] % Mod + ans[ i ] ) % Mod ;  
            }
        }
        return ans ; 
    }
}input_A , input_B , try_C ; 

std::mt19937 rng(std::chrono::steady_clock::now().time_since_epoch().count());  

void slove( ) 
{
    read( n ) ;   
    input_A.init( ) ; 
    input_B.init( ) ; 
    try_C.init( ) ; 
    for( int i = 0 ; i < n ; i ++ ) 
        for( int j = 0 ; j < n ; j ++ ) read( input_A[ i ][ j ] ) ;  
    for( int i = 0 ; i < n ; i ++ ) 
        for( int j = 0 ; j < n ; j ++ ) read( input_B[ i ][ j ]  ) ;  
    for( int i = 0 ; i < n ; i ++ ) 
        for( int j = 0 ; j < n ; j ++ ) read( try_C[ i ][ j ] ) ; 
    array< int , N > mid_Matrix ; 
    for( int i = 0 ; i < n ; i ++ ) 
        mid_Matrix[ i ] = rng() % Mod ;  
    array< int , N > ans1 = input_A * mid_Matrix ;
    ans1 = input_B * ans1 ; 
    array< int , N > ans2 = try_C * mid_Matrix ; 
 
    for( int i = 0 ; i < n ; i ++ ) 
    {
        if( ans1[ i ] == ans2[ i ] ) continue ; 
        write( "No" ) ; 
        puts( "" ) ; 
        return ; 
    }
    write( "Yes" ) ; 
    puts( "" ) ; 
    return ;  
}

signed main( ) 
{
    // freopen( "Matrix.in" , "r" , stdin ) ;    
    // srand( ( unsigned ) time( NULL ) ) ; 
    int T ; 
    cin >> T ; 
    while( T -- ) 
        slove( ) ; 


    return 0 ; 
}
2025/7/26 17:31
加载中...