QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#739753#9738. Make It Divisibleir101WA 6ms8252kbC++202.9kb2024-11-12 22:58:052024-11-12 22:58:10

Judging History

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

  • [2024-11-27 18:44:44]
  • hack成功,自动添加数据
  • (/hack/1263)
  • [2024-11-14 09:10:13]
  • hack成功,自动添加数据
  • (/hack/1178)
  • [2024-11-12 22:58:10]
  • 评测
  • 测评结果:WA
  • 用时:6ms
  • 内存:8252kb
  • [2024-11-12 22:58:05]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
#define PII pair<int,int>
#define PI4 pair<int,array<int,3>>
//#define endl '\n'
#define int long long
#define i64 long long
#define  lc p<<1
#define  rc p<<1|1
using namespace  std;
const int N = 1e6 + 10;

bool isprime[N]; // isprime[i]表示i是不是素数
int prime[N]; // 现在已经筛出的素数列表
int cnt; // 已经筛出的素数个数
int a[N];
void euler(int n) {
	memset(isprime, true, sizeof(isprime)); // 先全部标记为素数
	isprime[1] = false; // 1不是素数
	for (int i = 2; i <= n; ++i) { // i从2循环到n(外层循环)
		if (isprime[i]) prime[++cnt] = i;
		// 如果i没有被前面的数筛掉,则i是素数
		for (int j = 1; j <= cnt && i * prime[j] <= n; ++j)
			// 筛掉i的素数倍,即i的prime[j]倍
			// j循环枚举现在已经筛出的素数(内层循环)
		{
			isprime[i * prime[j]] = false;
			// 倍数标记为合数,也就是i用prime[j]把i * prime[j]筛掉了
			if (i % prime[j] == 0) break;
			// 最神奇的一句话,如果i整除prime[j],退出循环
			// 这样可以保证线性的时间复杂度
		}
	}
}
vector<PII>q;
vector<int>inv;
void dfs(int x, int s) {
	if (x == q.size()) {
		inv.push_back(s);
		return;

	}
	for (int i = 0; i <= q[x].second; i++) {
		dfs(x + 1, s);
		s *= q[x].first;
	}
}
void solve() {
	int n, k;
	cin >> n >> k;
	q.clear();
	inv.clear();
	vector<int>qx;
	int g = 0;
	int mn = 1e9;
	int f = 1;
	int mi = 1;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
//		if(i%2){
//			a[i]=735134400+1;
//		}else{
//			a[i]=1;
//		}
		if (i > 1) {
			if (a[i] == a[i - 1]) {

			} else {
				g = __gcd(abs(a[i] - a[i - 1]), g);
				f = 0;
				mi = i;
			}
		}
		mn = min(mn, a[i]);
	}
	if (f) {
		cout << k << ' ' << k*(k + 1) / 2 << endl;
		return;
	}
	int t = abs(a[mi] - a[mi - 1]);
	int pos = 1;
	while (pos <= cnt && t > 1 && prime[pos]*prime[pos] <= t) {
		int s = 0;
		while (t % prime[pos] == 0) {
			t /= prime[pos];
			s++;
		}
		if (s) {
			q.push_back({prime[pos], s});
		}
		pos++;
	}
	if (t > 1) {
		q.push_back({t, 1});
	}
	dfs(0, 1);
	int m = min(a[mi], a[mi - 1]);
	for (int i = 0; i < inv.size(); i++) {
		if (inv[i] > m && inv[i] - m <= k) {
			qx.push_back(inv[i] - m);
		}
	}
//	cout<<qx.size()<<endl;
	for (int i = 3; i <= n; i++) {
		int s = abs(a[i] - a[i - 1]);
		int mn = min(a[i], a[i - 1]);
		for (int j = 0; j < qx.size(); j++) {
			int x = qx[j];
			if (s % (x + mn) != 0) {
				swap(qx[j], qx.back());
				qx.pop_back();
			}
		}
	}
	int cc = 0;
	int sum = 0;
//	cout<<g<<endl;
	for (auto x : qx) {
		if (g % (x + mn) == 0) {
			cc++;
			sum += x;
		}
	}
	cout << cc << ' ' << sum << endl;
}
signed main() {


	ios::sync_with_stdio(false), cin.tie(0);
	ll t = 1;
	cin >> t;
	euler(1e6);
	while (t--) {
		solve();
	}
}

详细

Test #1:

score: 100
Accepted
time: 6ms
memory: 8248kb

input:

3
5 10
7 79 1 7 1
2 1000000000
1 2
1 100
1000000000

output:

3 8
0 0
100 5050

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 6ms
memory: 8252kb

input:

4
201 1000000000
1 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5...

output:

0 0
1 1
0 0
0 0

result:

wrong answer 2nd lines differ - expected: '0 0', found: '1 1'