QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#799606#9426. Relearn through Reviewfsy_juruoWA 115ms9828kbC++171010b2024-12-05 16:14:442024-12-05 16:14:44

Judging History

你现在查看的是最新测评结果

  • [2024-12-05 16:14:44]
  • 评测
  • 测评结果:WA
  • 用时:115ms
  • 内存:9828kb
  • [2024-12-05 16:14:44]
  • 提交

answer

#include <bits/stdc++.h>
using LL = long long;

const int maxN = 3e5 + 10;
int T, n;
LL k, a[maxN], pre[maxN], suf[maxN], d[maxN];

LL Labs(LL x) {
	return x > 0 ? x : -x;
}
int main() {
	std::ios::sync_with_stdio(false); std::cin.tie(nullptr);
	std::cin >> T;
	while(T--) {
		std::cin >> n >> k;
		for(int i = 1; i <= n; i++) {
			std::cin >> a[i];
		} 

		pre[1] = a[1];
		suf[n] = a[n];
		for(int i = 2; i <= n; i++) {
			pre[i] = std::__gcd(pre[i - 1], a[i]);
		}
		for(int i = n - 1; i >= 1; i--) {
			suf[i] = std::__gcd(suf[i + 1], a[i]);
		}

		LL ans = pre[n];
		for(int i = 1; i <= n; i++) {
			if(pre[i - 1] != pre[i]) {
				LL t = 0;
				for(int j = i; j <= n; j++) {
					t = std::__gcd(t, a[j] + k);
					ans = std::max(ans, std::__gcd(t, std::__gcd(pre[i - 1], suf[j + 1])));
					// std::cerr << i << " " << j << " " << pre[i - 1] << " " << a[j] + k << " " << t << " " << suf[j + 1] << "\n";
				}
			}
		}

		std::cout << ans << "\n";
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 9760kb

input:

2
6 2
5 3 13 8 10 555
3 0
3 6 9

output:

5
3

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 115ms
memory: 9828kb

input:

100000
1 608611451460421713
33155506392034032
1 743116173559300609
6138108577573005
7 364454564010802125
657035115675878115 657035115675878115 657035115675878115 657035115675878115 657035115675878115 292580551665075990 657035115675878115
4 316648374341335221
365788422120542814 182894211060271407 731...

output:

641766957852455745
749254282136873614
657035115675878115
3
1
98423435849394582
183698346865682381
3
484915690810412536
6
149180825015886938
361813583202892479
915781395066183375
37337367838628559
632093288650732211
377121713907330928
2
494408344393555851
2
2
118387461231999184
1
383091938972089281
1...

result:

wrong answer 4th lines differ - expected: '182894211060271407', found: '3'