2 条题解
-
11
假如你不小心把
对于 的数据:
“ ”
看成了
“”,
又特别喜欢开
unsigned long long你就得到了 分。
这就是自然溢出
但是,我们读题的时候,一般都会非常小心,这该怎么办?
其实这题不用高精度,就是把 分成正的和负的,把 的整数带进去,看看哈希值是不是相等就行了。
当然你要先把每个 的哈希值预处理出来。
复杂度 。
#include<bits/stdc++.h> #define int long long #define R(x) x=read() #define ccf 998244353 using namespace std; //#define MYBUF (1 << 20) //char buf[MYBUF], *p1, *p2; //#define getchar() \ // (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, MYBUF, stdin), p1 == p2) \ // ? EOF \ // : *p1++) inline int read() { int x=0,y=1; char e=getchar(); while(e<'0'||e>'9') { if(e=='-')y=-1; e=getchar(); } while(e>='0'&&e<='9') { x=(x<<1)+(x<<3)+(e-'0'); e=getchar(); } return x*y; } int n,m,A[105]; int cnt; struct node { int i,d; } a1[105],a2[105]; int tot1,tot2; int fac[105]; int ans[1000005]; signed main() { R(n),R(m); for(int i=0; i<=n; ++i) { string s; cin>>s; if(s[0]=='-') { ++tot2; a2[tot2].i=i; for(int i=1; i<s.size(); ++i) { a2[tot2].d=(a2[tot2].d*10+s[i]-'0')%ccf; } } else { ++tot1; a1[tot1].i=i; for(int i=0; i<s.size(); ++i) { a1[tot1].d=(a1[tot1].d*10+s[i]-'0')%ccf; } } } cnt=0; for(int i=1; i<=m; ++i) { int h1=0,h2=0; fac[0]=i; for(int j=1; j<=n; ++j) { fac[j]=fac[j-1]*i%ccf; } for(int j=1; j<=tot1; ++j) { h1=(h1+a1[j].d*fac[a1[j].i])%ccf; } for(int j=1; j<=tot2; ++j) { h2=(h2+a2[j].d*fac[a2[j].i])%ccf; } if(h1==h2) { ans[++cnt]=i; } } cout<<cnt<<"\n"; for(int i=1; i<=cnt; ++i) { cout<<ans[i]<<"\n"; } return 0; }
对了,大家在模拟赛快结束的时候不要出去逛悠。
-
1
- 1
信息
- ID
- 130
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 7
- 标签
- (无)
- 递交数
- 29
- 已通过
- 9
- 上传者