为啥这个代码多测不清空 c 数组会 WA 啊
查看原帖
为啥这个代码多测不清空 c 数组会 WA 啊
422684
M1saka16I72楼主2024/9/24 21:35

rt,不 memset 只有 12 分/ll,但我觉得清空并没有影响啊。

#include <bits/stdc++.h>
#define pii pair<int,int>
#define pil pair<int,long long>
#define pll pair<long long,long long>
#define mp_ make_pair
#define pb_ push_back
#define pob_ pop_back
#define fst first
#define snd second
#define debug cout<<"********\n";
#define reset(x,y) memset(x,y,sizeof(x))
#define fi(x) freopen(x,"r",stdin)
#define fo(x) freopen(x,"w",stdout)
#define iosf ios::sync_with_stdio(0);cin.tie(0);
#define prec(x) cout<<setprecision(x);
#define prec0(x) cout<<fixed<<setprecision(x);
#define Misaka16172 sb
#define kamisako femboy

using ll = long long;
using ld = long double;
using db = double;
using ull = unsigned long long;
using uint = unsigned int;

constexpr int inf = 0x3f3f3f3f;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ull mod1 = 1e9+7,mod9 = 998244353;

using namespace std;

template <class T>
inline void read(T &x){
    x = 0;T w = 1;
    char c = 0;
    while(!isdigit(c)){
        if(c=='-')  w = -1;
        c = getchar();
    }
    while(isdigit(c)){
        x = ((x<<3)+(x<<1))+c-'0';
        c = getchar();
    }
    x = x*w;
}
template<class T,typename ...Args>
inline void read(T &x,Args &...rest){read(x);read(rest...);}

template<class T>
inline void write(T x){
    if(!x)  return putchar('0'),void();
    else if(x<0) putchar('-'),x*=-1;
    int st[40],t = 0;
    while(x){st[++t] = x%10,x/=10;}
    while(t){putchar(st[t--]+'0');}
}

template <class T>
inline string bin(T x,int d = 0){return (((d>1)||(x>>1))?bin(x>>1,d-1):"")+to_string(x&1);}

int Test = 1,Case = 1;

template<const uint mod>
class modInt{
	int v;
private:
	inline int qpow(int x,int y){
		int res = 1;
		while(y){
			if(y&1)	res = 1ll*res*x%mod;
			x = 1ll*x*x%mod,y>>=1;
		}
		return res;
	}
	inline int fix(ll x){return x>=mod?(x%mod):(x<0?(mod+x%mod):x);}
public:
	modInt(){v = 0;}
	modInt(ll x){v = fix(x);}
	inline modInt operator +(const modInt &x)const{return modInt((ll)v+x.v);}
	inline modInt operator +(const ll &x)const{return *this+modInt(x);}
    inline modInt operator -()const{return modInt(mod-v);}
	inline modInt operator -(const modInt &x)const{return modInt(v-x.v>=0?(v-x.v):(v-x.v+mod));}
	inline modInt operator -(const ll &x)const{return *this-modInt(x);}
	inline modInt operator *(const modInt &x)const{return modInt(1ll*v*x.v);}
	inline modInt operator *(const ll &x)const{return *this*modInt(x);}
	inline modInt operator /(const modInt x){return modInt(1ll*v*qpow(x.v,mod-2));}	//can only be used when mod is a prime
	inline modInt operator /(const ll &x)const{return modInt(v/x);}
	inline modInt operator %(const modInt &x)const{return modInt(v%x.v);}
	inline modInt operator %(const ll &x)const{return modInt(v%x);}
	inline modInt operator <<(const modInt &x)const{return modInt((ll)v<<x.v);}
	inline modInt operator <<(const int &x)const{return modInt((ll)v<<x);}
	inline modInt operator >>(const modInt &x)const{return modInt(v>>x.v);}
	inline modInt operator >>(const int &x)const{return modInt((ll)v>>x);}
	inline void operator +=(modInt x){v = fix((ll)v+x.v);}
	inline void operator +=(ll x){v = fix((ll)v+x);}
	inline void operator -=(modInt x){v = fix((ll)v-x.v);}
	inline void operator -=(ll x){v = fix((ll)v-x);}
	inline void operator *=(modInt x){v = 1ll*v*x.v%mod;}
	inline void operator *=(ll x){x = fix(x),v = 1ll*v*x%mod;}
	inline void operator /=(modInt x){v = 1ll*v*qpow(x.v,mod-2)%mod;}
	inline void operator /=(ll x){v/=x;}
	inline void operator %=(modInt x){v%=x.v;}
	inline void operator %=(ll x){v%=x;}
	inline void operator <<=(modInt x){v = fix((ll)v<<x.v);}
	inline void operator <<=(int x){v = fix((ll)v<<x);}
	inline void operator >>=(modInt x){v>>=x.v;}
	inline void operator >>=(int x){v>>=x;}
	inline bool operator ==(const modInt &x)const{return v==x.v;}
	inline bool operator !=(const modInt &x)const{return v!=x.v;}
	explicit operator int()const{return v;}
};

using mint = modInt<mod9>;

constexpr int N = 1005;

int n,m,a[N][N],u[N][N],d[N][N],l[N][N],r[N][N],sumr[N][N];
mint c[N][N];

void solve(){
	int C,F;
    cin>>n>>m>>C>>F;
    reset(c,0);
    for(int y=1;y<=n;y++){
    	for(int x=1;x<=m;x++){
    		char c;cin>>c;
    		a[x][y] = c!='1';
    		u[x][y] = d[x][y] = l[x][y] = r[x][y] = 0;
    	}
    }
    for(int y=1;y<=n;y++){
    	for(int x=1;x<=m;x++){
    		if(!a[x][y])	continue;
    		l[x][y] = (a[x-1][y]?l[x-1][y]:x);
    	}
    	a[m+1][y] = 0;
    	for(int x=m;x>=1;x--){
    		if(!a[x][y])	continue;
    		r[x][y] = (a[x+1][y]?r[x+1][y]:x);
    	}
    	for(int x=1;x<=m;x++)	sumr[x][y] = sumr[x][y-1]+(r[x][y]-x);
    }
    for(int x=1;x<=m;x++){
    	for(int y=1;y<=n;y++){
    		if(!a[x][y])	continue;
    		u[x][y] = (a[x][y-1]?u[x][y-1]:y);
    	}
    	a[x][n+1] = 0;
    	for(int y=n;y>=1;y--){
    		if(!a[x][y])	continue;
    		d[x][y] = (a[x][y+1]?d[x][y+1]:y);
    	}
    }
    mint ansc = 0;
    for(int y=3;y<=n;y++){
    	for(int x=1;x<=m;x++){
    		if(!a[x][y] || u[x][y]>=y-1)	continue;
    		c[x][y] = (mint)(r[x][y]-x)*(sumr[x][y-2]-sumr[x][u[x][y]-1]);
    		ansc+=c[x][y],c[x][y]+=c[x][y-1];
    	}
    }
    mint ansf = 0;
	for(int x=1;x<=m;x++){
    	for(int y=4;y<=n;y++){
    		if(!a[x][y])	continue;
    		ansf+=c[x][y-1]-c[x][u[x][y]-1];
    	}
    }
    cout<<(int)(ansc*C)<<" "<<(int)(ansf*F)<<"\n";
}

int main(){
    iosf
	cin>>Test;
 	int c;cin>>c;
    for(;Case<=Test;++Case) solve();
    return 0;
}
2024/9/24 21:35
加载中...