QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#783182#9798. Safety Firstucup-team902ML 0ms0kbC++203.5kb2024-11-26 00:43:372024-11-26 00:43:38

Judging History

你现在查看的是最新测评结果

  • [2024-11-26 00:43:38]
  • 评测
  • 测评结果:ML
  • 用时:0ms
  • 内存:0kb
  • [2024-11-26 00:43:37]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define cs const
#define re register
#define pb push_back
#define y0 sxxxxx
#define pii pair<int, int>
#define ll long long
#define fi first
#define se second
#define bg begin
namespace IO{

cs int RLEN=1<<22|1;
char ibuf[RLEN],*ib,*ob;
inline char gc(){
    (ib==ob)&&(ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
    return (ib==ob)?EOF:*ib++;
}
inline int read(){
    char ch=gc();
    int res=0;bool f=1;
    while(!isdigit(ch))f^=ch=='-',ch=gc();
    while(isdigit(ch))res=(res*10)+(ch^48),ch=gc();
    return f?res:-res;
}
inline ll readll(){
    char ch=gc();
    ll res=0;bool f=1;
    while(!isdigit(ch))f^=ch=='-',ch=gc();
    while(isdigit(ch))res=(res*10)+(ch^48),ch=gc();
    return f?res:-res;
}
inline char readchar(){
	char ch=gc();
	while(isspace(ch))ch=gc();
	return ch;
}
inline int readstring(char *s){
	int top=0;char ch=gc();
	while(isspace(ch))ch=gc();
	while(!isspace(ch)&&ch!=EOF)s[++top]=ch,ch=gc();
	s[top+1]='\0';return top;
}

}
using IO::read;
using IO::readll;
using IO::readchar;
using IO::readstring;
template <typename tp>
inline void chemx(tp &a, tp b) { (a < b) ? (a = b) : 0; }
template <typename tp>
inline void chemn(tp &a, tp b) { (a > b) ? (a = b) : 0; }

cs int mod=998244353;
inline int add(int a,int b){return (a+b)>=mod?(a+b-mod):(a+b);}
inline int dec(int a,int b){return (a<b)?(a-b+mod):(a-b);}
inline int mul(int a,int b){static ll r;r=(ll)a*b;return (r>=mod)?(r%mod):r;}
inline void Add(int &a,int b){a=(a+b)>=mod?(a+b-mod):(a+b);}
inline void Dec(int &a,int b){a=(a<b)?(a-b+mod):(a-b);}
inline void Mul(int &a,int b){static ll r;r=(ll)a*b;a=(r>=mod)?(r%mod):r;}
inline int ksm(int a,int b,int res=1){for(;b;b>>=1,Mul(a,a))(b&1)&&(Mul(res,a),1);return res;}
inline int Inv(int x){return ksm(x,mod-2);}
inline int fix(ll x){x%=mod;return (x<0)?x+mod:x;}

cs int N=2005,M=51;
char xx;
int f[N][M][N];
int ans1[N][N],ans2[N][N];
int n,m,k;
char yy;
void solve(){
    n=2000,m=2000;
    k=45;
    // for(int j=1;j<=k;j++)f[1][j][j]=1;
    // for(int i=1;i<=n;i++)
    // for(int )
    f[0][1][0]=1;
    for(int i=0;i<=n;i++)
    for(int j=0;j<=k;j++)
    for(int s=0;s<=m;s++)if(f[i][j][s]){
        int v=f[i][j][s];
        if(j<k)Add(f[i][j+1][s],v);
        if(i<n)Add(f[i+1][j][s],v);
        if(i<n&&s+j<=m)Add(f[i+1][j][s+j],v);
    }
    for(int i=0;i<=n;i++)
    for(int j=0;j<=k;j++)
    for(int s=0;s<=m;s++){
        if(i<n&&s+j<=m)Add(ans1[i+1][s+j],f[i][j][s]);
    }
    for(int i=n;i>=1;i--){
        memset(f[i],0,sizeof(f[i]));

        for(int s=0;s<=m;s++)
        if(s+k+1<=m)Add(f[i][1][s+k+1],f[i-1][k][s]);
    }
    // for(int i=0;i<=n;i++)
    // for(int s=0;s<=m;s++){
    //     if(i<n&&s+k+1<=m)Add(g[i+1][1][s+k+1],f[i][k][s]);
    // } 
    for(int i=1;i<=n;i++)
    for(int j=1;j<=k;j++)
    for(int s=0;s<=m;s++)if(f[i][j][s]){
        if(i<n)Add(f[i+1][j][s],f[i][j][s]);
        if(i<n&&j<k&&s+k+1<=m)Add(f[i+1][j+1][s+k+1],f[i][j][s]);
        if(s+j<=m)Add(f[i][j][s+j],f[i][j][s]);
    }
    for(int i=1;i<=n;i++)
    for(int j=1;j<=k;j++)
    for(int s=0;s<=m;s++){
    //    if(g[i][j][s])cout<<i<<" "<<j<<" "<<s<<" "<<g[i][j][s]<<'\n';
        Add(ans2[i][s],f[i][j][s]);
    }
}   


int main() {
	#ifdef Stargazer
	freopen("1.in","r",stdin);
//	freopen("1.out","w",stdout);
	#endif
  //  cout<<(&yy-&xx)/1024/1024<<'\n';
	int T=read();
    solve();
    while(T--){
        int x=read(),y=read();
        cout<<add(ans1[x][y],ans2[x][y])<<'\n';
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Memory Limit Exceeded

input:

3
1 3
2 3
3 3

output:

1
4
10

result: