2 条题解

  • 11
    @ 2025-4-7 13:25:00

    假如你不小心把

    对于 100%100\% 的数据:

    ai1010000|a_i|\le 10^{10000}

    看成了

    ai0xccfccfccfccfccf|a_i|\le 0xccfccfccfccfccf”,

    又特别喜欢开unsigned long long

    你就得到了 5050 分。

    这就是自然溢出

    但是,我们读题的时候,一般都会非常小心,这该怎么办?

    其实这题不用高精度,就是把 aia_i 分成正的和负的,把 [1,m][1,m] 的整数带进去,看看哈希值是不是相等就行了。

    当然你要先把每个 aia_i 的哈希值预处理出来。

    复杂度 O(nm)O(nm)

    #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;
    }
    

    对了,大家在模拟赛快结束的时候不要出去逛悠。

    • @ 2025-4-7 13:31:49

      警示后人

      模拟赛快结束的时候不要出去逛悠。

      • 如果这个时候出去逛悠,很可能导致题做不完。

      • 出去逛悠是非常容易想出题的,但是来不及调,非常遗憾。

      • 这个时候大家一般都会非常开心,很可能影响自己的代码正确率。

      警钟吃掉

  • 1

信息

ID
130
时间
1000ms
内存
256MiB
难度
7
标签
(无)
递交数
29
已通过
9
上传者