Submission #45833162
Source Code Expand
#include<bits/stdc++.h>
using namespace std;
#define int long long
inline int read(){int x=0,f=1;char ch=getchar(); while(ch<'0'||
ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){
x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}return x*f;}
#define Z(x) (x)*(x)
#define pb push_back
//mt19937 rand(time(0));
//mt19937_64 rand(time(0));
//srand(time(0));
#define N 5010
//#define M
#define mo 998244353
int pw(int a, int b) {
int ans=1;
while(b) {
if(b&1) ans*=a;
a*=a; b>>=1;
ans%=mo; a%=mo;
}
return ans;
}
int fac[N], inv[N], ifac[N];
void init(int n) {
int i;
for(i=fac[0]=1; i<=n; ++i) fac[i]=fac[i-1]*i%mo;
ifac[n]=pw(fac[n], mo-2);
for(i=n-1; i>=0; --i) ifac[i]=ifac[i+1]*(i+1)%mo;
}
int C(int n, int m) {
if(m>n) return 0;
return fac[n]*ifac[m]%mo*ifac[n-m]%mo;
}
const int iv2=pw(2, mo-2);
int n, m, i, j, k, T, rt;
char s[5];
struct Segment_tree {
int tot, ls[N<<2], rs[N<<2];
int dp[N<<2][N], c[N<<2];
void build(int &k, int l, int r) {
if(!k) k=++tot;
if(l==r) return ;
int mid=(l+r)>>1;
build(ls[k], l, mid);
build(rs[k], mid+1, r);
}
void Add(int &a, int b) {
a+=b; if(a>=mo || a<=-mo) a%=mo;
}
void push_up(int k) {
int i, j;
for(i=1; i<=m; ++i) dp[k][i]=(dp[ls[k]][i]+dp[rs[k]][i])%mo;
for(i=1; i<=m; ++i)
for(j=1; i+j<=m; ++j)
Add(dp[k][i+j], dp[ls[k]][i]*dp[rs[k]][j]);
}
void add(int k, int l, int r, int x, int y) {
if(l==r) {
c[k]+=y;
for(int i=0; i<=m; ++i) dp[k][i]=0;
for(int i=1; i<=c[k] && i*x<=m; ++i) {
dp[k][i*x]=C(c[k], i);
// printf("dp[%lld][%lld]=%lld\n", k, i*x, dp[k][i*x], C(c[k], i));
}
return ;
}
int mid=(l+r)>>1;
if(x<=mid) add(ls[k], l, mid, x, y);
else add(rs[k], mid+1, r, x, y);
push_up(k);
}
}Seg;
signed main()
{
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
// T=read();
// while(T--) {
//
// }
n=read(); m=read();
init(5000);
Seg.build(rt, 1, m);
for(i=1; i<=n; ++i) {
scanf("%s%lld", s+1, &k);
if(s[1]=='+') j=1; else j=-1;
Seg.add(1, 1, m, k, j);
printf("%lld\n", Seg.dp[1][m]);
}
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | F - #(subset sum = K) with Add and Erase |
| User | zhangtingxi |
| Language | C++ 20 (gcc 12.2) |
| Score | 0 |
| Code Size | 2208 Byte |
| Status | WA |
| Exec Time | 2211 ms |
| Memory | 13960 KiB |
Compile Error
Main.cpp: In function ‘int main()’:
Main.cpp:88:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
88 | scanf("%s%lld", s+1, &k);
| ~~~~~^~~~~~~~~~~~~~~~~~~
Judge Result
| Set Name | Sample | All | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 0 / 525 | ||||||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | sample_01.txt |
| All | sample_01.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt, test_20.txt, test_21.txt, test_22.txt, test_23.txt, test_24.txt, test_25.txt, test_26.txt, test_27.txt, test_28.txt, test_29.txt, test_30.txt, test_31.txt, test_32.txt, test_33.txt, test_34.txt, test_35.txt, test_36.txt, test_37.txt, test_38.txt, test_39.txt, test_40.txt, test_41.txt, test_42.txt, test_43.txt, test_44.txt, test_45.txt, test_46.txt, test_47.txt, test_48.txt, test_49.txt, test_50.txt, test_51.txt, test_52.txt, test_53.txt, test_54.txt, test_55.txt, test_56.txt, test_57.txt, test_58.txt, test_59.txt, test_60.txt, test_61.txt, test_62.txt, test_63.txt, test_64.txt, test_65.txt, test_66.txt, test_67.txt, test_68.txt, test_69.txt, test_70.txt, test_71.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| sample_01.txt | AC | 1 ms | 3788 KiB |
| test_01.txt | AC | 190 ms | 4564 KiB |
| test_02.txt | AC | 176 ms | 4612 KiB |
| test_03.txt | AC | 2 ms | 3764 KiB |
| test_04.txt | TLE | 2207 ms | 3812 KiB |
| test_05.txt | TLE | 2207 ms | 4188 KiB |
| test_06.txt | TLE | 2207 ms | 4604 KiB |
| test_07.txt | TLE | 2207 ms | 6244 KiB |
| test_08.txt | WA | 175 ms | 4792 KiB |
| test_09.txt | TLE | 2208 ms | 7212 KiB |
| test_10.txt | TLE | 2207 ms | 3816 KiB |
| test_11.txt | TLE | 2207 ms | 4672 KiB |
| test_12.txt | WA | 126 ms | 4616 KiB |
| test_13.txt | TLE | 2208 ms | 12236 KiB |
| test_14.txt | TLE | 2208 ms | 7556 KiB |
| test_15.txt | TLE | 2207 ms | 4132 KiB |
| test_16.txt | AC | 147 ms | 4012 KiB |
| test_17.txt | WA | 210 ms | 4828 KiB |
| test_18.txt | TLE | 2207 ms | 8428 KiB |
| test_19.txt | TLE | 2208 ms | 8984 KiB |
| test_20.txt | AC | 156 ms | 3884 KiB |
| test_21.txt | TLE | 2207 ms | 3932 KiB |
| test_22.txt | TLE | 2208 ms | 5292 KiB |
| test_23.txt | TLE | 2208 ms | 7972 KiB |
| test_24.txt | WA | 167 ms | 4400 KiB |
| test_25.txt | TLE | 2207 ms | 3568 KiB |
| test_26.txt | TLE | 2207 ms | 4748 KiB |
| test_27.txt | TLE | 2208 ms | 6192 KiB |
| test_28.txt | WA | 14 ms | 3952 KiB |
| test_29.txt | TLE | 2208 ms | 7172 KiB |
| test_30.txt | TLE | 2211 ms | 3632 KiB |
| test_31.txt | TLE | 2207 ms | 4628 KiB |
| test_32.txt | WA | 190 ms | 4600 KiB |
| test_33.txt | TLE | 2208 ms | 13960 KiB |
| test_34.txt | TLE | 2208 ms | 8964 KiB |
| test_35.txt | TLE | 2207 ms | 4152 KiB |
| test_36.txt | AC | 173 ms | 4012 KiB |
| test_37.txt | TLE | 2207 ms | 5064 KiB |
| test_38.txt | TLE | 2208 ms | 10112 KiB |
| test_39.txt | TLE | 2208 ms | 8612 KiB |
| test_40.txt | AC | 146 ms | 3944 KiB |
| test_41.txt | AC | 256 ms | 3852 KiB |
| test_42.txt | TLE | 2207 ms | 6496 KiB |
| test_43.txt | TLE | 2208 ms | 7700 KiB |
| test_44.txt | AC | 2 ms | 3764 KiB |
| test_45.txt | AC | 9 ms | 3744 KiB |
| test_46.txt | AC | 2 ms | 3920 KiB |
| test_47.txt | AC | 2 ms | 3800 KiB |
| test_48.txt | AC | 13 ms | 4004 KiB |
| test_49.txt | TLE | 2208 ms | 9288 KiB |
| test_50.txt | TLE | 2210 ms | 7168 KiB |
| test_51.txt | TLE | 2210 ms | 4772 KiB |
| test_52.txt | WA | 2 ms | 3884 KiB |
| test_53.txt | TLE | 2208 ms | 13268 KiB |
| test_54.txt | TLE | 2208 ms | 9256 KiB |
| test_55.txt | TLE | 2207 ms | 4200 KiB |
| test_56.txt | AC | 98 ms | 3848 KiB |
| test_57.txt | TLE | 2208 ms | 5792 KiB |
| test_58.txt | TLE | 2208 ms | 8864 KiB |
| test_59.txt | TLE | 2208 ms | 9248 KiB |
| test_60.txt | AC | 7 ms | 3788 KiB |
| test_61.txt | TLE | 2207 ms | 3760 KiB |
| test_62.txt | TLE | 2210 ms | 5240 KiB |
| test_63.txt | TLE | 2211 ms | 7616 KiB |
| test_64.txt | AC | 144 ms | 4484 KiB |
| test_65.txt | TLE | 2207 ms | 3596 KiB |
| test_66.txt | TLE | 2207 ms | 3988 KiB |
| test_67.txt | TLE | 2208 ms | 5912 KiB |
| test_68.txt | WA | 186 ms | 4680 KiB |
| test_69.txt | TLE | 2208 ms | 7632 KiB |
| test_70.txt | TLE | 2207 ms | 3776 KiB |
| test_71.txt | TLE | 2207 ms | 4232 KiB |