QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#278288 | #7875. Queue Sorting | lifan | Compile Error | / | / | C++14 | 1.2kb | 2023-12-07 14:35:40 | 2023-12-07 14:35:40 |
Judging History
answer
//
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define op(x) ((x&1)?x+1:x-1)
#define odd(x) (x&1)
#define even(x) (!odd(x))
#define lc(x) (x<<1)
#define rc(x) (lc(x)|1)
#define lowbit(x) (x&-x)
#define mp(x,y) make_pair(x,y)
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
using namespace std;
const int MAXN = 510,mod = 998244353;
void add(ll& x,ll y){x=(x+y)%mod;}
ll addv(ll x,ll y){return (x+y)%mod;}
//
ll n,a[MAXN],dp[MAXN][MAXN],s;
ll C[MAXN*2][MAXN*2];
int main(){
rep(i,0,1000){
C[i][0]=1;
rep(j,1,i)C[i][j]=addv(C[i-1][j-1],C[i-1][j]);
}
cin>>n;
rep(i,1,n)cin>>a[i];
s=1;
while(s<=n && !a[s])s++;
if(s==n+1)return (cout<<"1\n"),0;
ll sum=a[s];
dp[s][0]=1;
rep(i,s+1,n){
if(!a[i]){
memcpy(dp[i],dp[i-1],sizeof dp[i]);
continue;
}
rep(j,0,sum)if(dp[i-1][j]){
ll val=dp[i-1][j];
add(dp[i][j],val);
rep(k,0,a[i]-1){ //枚举最后一格放的个数
ll r=a[i]-k;
rep(p,j,sum-1){
ll x=p-j+1,w=C[x+r-2][r-1];
add(dp[i][p+r],val*w);
}
}
}
sum+=a[i];
}
ll ans=0;
rep(i,0,sum)add(ans,dp[n][i]);
cout<<ans<<endl;
return 0;
}
Details
answer.code: In function ‘int main()’: answer.code:28:9: error: ‘cin’ was not declared in this scope 28 | cin>>n; | ^~~ answer.code:1:1: note: ‘std::cin’ is defined in header ‘<iostream>’; did you forget to ‘#include <iostream>’? +++ |+#include <iostream> 1 | // answer.code:32:27: error: ‘cout’ was not declared in this scope 32 | if(s==n+1)return (cout<<"1\n"),0; | ^~~~ answer.code:32:27: note: ‘std::cout’ is defined in header ‘<iostream>’; did you forget to ‘#include <iostream>’? answer.code:38:25: error: ‘memcpy’ was not declared in this scope 38 | memcpy(dp[i],dp[i-1],sizeof dp[i]); | ^~~~~~ answer.code:1:1: note: ‘memcpy’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’? +++ |+#include <cstring> 1 | // answer.code:57:9: error: ‘cout’ was not declared in this scope 57 | cout<<ans<<endl; | ^~~~ answer.code:57:9: note: ‘std::cout’ is defined in header ‘<iostream>’; did you forget to ‘#include <iostream>’? answer.code:57:20: error: ‘endl’ was not declared in this scope 57 | cout<<ans<<endl; | ^~~~ answer.code:1:1: note: ‘std::endl’ is defined in header ‘<ostream>’; did you forget to ‘#include <ostream>’? +++ |+#include <ostream> 1 | //