麻烦管理员看一下两个 Hack 了大批题解的代码
查看原帖
麻烦管理员看一下两个 Hack 了大批题解的代码
690722
Add_Catalyst楼主2024/7/2 21:40

麻烦管理员看一下两个 Hack 了大批题解的代码


Hack 思路

题解区的题解(还算上 OI Wiki)在以下两组数据的加持之下输出了五花八门的答案……

样例来自学校 OJ,被偶然发现了代码漏洞,然后我们老师认为是由于 memset (可能赋值不够大)以及数据类型及其范围(比如 1≤h≤263−11 \le h \le 2^{63} - 1,只开 long long 会导致有些题解最后一步无法计算,同时也导致还有些题解 memset 出错)的问题,导致在 hh 大到一定程度时,某些代码就出现了问题。

鄙人认为 题解 P3403 【跳楼机】 - 洛谷专栏 (luogu.com.cn) 这一篇题解的输出是正确的。


Hack 样例(均符合题目范围)

注: 本地代码用了 __int128,并且循环初始化赋值,运行于 Embarcadero Dev-C++ 6.3(不过不知道能不能发出来)。

输入 #1

6184094783567293996
65062 86520 81714

本地输出 #1

3092047391775739345

输入 #2

7313656749410855992
99535 18245 58700

本地输出 #2

1462731349881230984

题解 P3403 【跳楼机】 - 洛谷专栏 (luogu.com.cn)

补全后代码:(这个查不到提交记录,也不给全代码,害得我疑惑好久……)

#include<bits/stdc++.h>
#define fi first
#define se second
#define ll long long
#define mp make_pair
#define pb push_back
#define pi pair<int,int>
#define pq priority_queue
#define ui unsigned int
using namespace std;
template<typename T>inline void rd(T &x) {
	T s=0;
	int f=1;
	char c=getchar();
	while(c<'0'||c>'9') {
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9') {
		s=s*10+(c-'0');
		c=getchar();
	}
	x=s*f;
}
template<typename T>inline void print(T x,char End='\n') {
	x<0?x=-x,putchar('-'):0;
	static short Stack[105],top(0);
	do Stack[++top]=x%10,x/=10;
	while(x);
	while(top)putchar(Stack[top--]|48);
	return putchar(End),void();
}
/*以下为原代码*/
const int N = 1e5 + 7;
const ll inf = (1ull << 63) - 1;
ll h, d[N], ans;
int x, y, z, v[N];
vector< pi > e[N];
pq< pair< ll, int > > q; 

int main() {
	rd(h), --h, rd(x), rd(y), rd(z);
	for (int i = 0; i < x; i++) e[i].pb(mp((i + y) % x, y)), e[i].pb(mp((i + z) % x, z)), d[i] = inf;
	d[0] = 0, q.push(mp(0, 0));
	while (q.size()) {
		int x = q.top().se;
		q.pop();
		if (v[x]) continue;
		v[x] = 1;
		for (ui i = 0; i < e[x].size(); i++) {
			int y = e[x][i].fi, z = e[x][i].se;
			if (d[y] > d[x] + z) d[y] = d[x] + z, q.push(mp(-d[y], y));
		}
	}
	for (int i = 0; i < x; i++)
		if (h >= d[i]) ans += (h - d[i]) / x + 1;
	print(ans);
	return 0;
}

输出 #1

3092047391775739345

输出 #2

1462731349881230984

题解 P3403 【跳楼机】 - 洛谷专栏 (luogu.com.cn)

输出 #1

3905379339159982640

输出 #2

3667712038370864636

题解 P3403 【跳楼机】 - 洛谷专栏 (luogu.com.cn)

输出 #1

3905379339159982640

输出 #2

3667712038370864636

题解 P3403 【跳楼机】 - 洛谷专栏 (luogu.com.cn)

输出 #1

3905379339159982640

输出 #2

3667712038370857048

P3403 跳楼机 - 洛谷专栏 (luogu.com.cn)

输出 #1

3905379339159982640

输出 #2

3667712038370864636

题解 P3403 【跳楼机】 - 洛谷专栏 (luogu.com.cn)

输出 #1

3905379339159982640

输出 #2

3667712038370857048

题解 P3403 【跳楼机】 - 洛谷专栏 (luogu.com.cn)

输出 #1

3905379339159982640

输出 #2

3667712038370864636

题解 P3403 【跳楼机】 - 洛谷专栏 (luogu.com.cn)

输出 #1

3092047391775739345

输出 #2

1462731349881230984

题解 P3403 【跳楼机】 - 洛谷专栏 (luogu.com.cn)

输出 #1

3905379339159982640

输出 #2

3667712038370864636

题解 P3403 【跳楼机】 - 洛谷专栏 (luogu.com.cn)

输出 #1

3905379339160008385

输出 #2

3667712038370864636

题解 P3403 【跳楼机】 - 洛谷专栏 (luogu.com.cn)

输出 #1

3905379339160006615

输出 #2

3667712038370890904

同余最短路 - OI Wiki (oi-wiki.org)

输出 #1

3905379339159982640

输出 #2

3667712038370864636

2024/7/2 21:40
加载中...