QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#744163 | #9738. Make It Divisible | ucup-team4975# | WA | 0ms | 3616kb | C++14 | 2.7kb | 2024-11-13 21:02:25 | 2024-11-13 21:02:26 |
Judging History
你现在查看的是最新测评结果
- [2024-11-27 18:44:44]
- hack成功,自动添加数据
- (/hack/1263)
- [2024-11-14 09:10:13]
- hack成功,自动添加数据
- (/hack/1178)
- [2024-11-13 21:02:25]
- 提交
answer
#define LOCAL
#include <bits/stdc++.h>
#define fir first
#define sec second
#define el '\n'
#ifdef LOCAL
#define FINISH cerr << "FINISH" << endl;
#else
#define FINISH ;
#endif
#ifdef LOCAL
#define debug(x) cerr << setw(4) << #x << " == " << x << endl
#else
#define debug(x)
#endif
#ifdef LOCAL
#define debugv(x) \
cerr << setw(4) << #x << ":: "; \
for (auto i : x) \
cerr << i << " "; \
cerr << endl
#else
#define debugv(x)
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
ostream& operator<<(ostream& out, PII& x)
{
out << x.fir << " " << x.sec << endl;
return out;
}
const int mod = 998244353;
const int inf = 0x3f3f3f3f;
const int N = 200020;
void solve()
{
int n, k, mna = inf;
cin >> n >> k;
vector<int> a(n + 1, 0);
for (int i = 1; i <= n; i++) {
cin >> a[i];
mna = min(mna, a[i]);
}
int flag = 1;
for (int i = 1; i <= n; i++) {
if (a[i] != a[1])
flag = 0;
}
if (flag == 1) {
cout << k << " " << 1ll * (k + 1) * k / 2 << el;
return;
}
vector<int> ans;
int nowans = 0;
auto merge = [&](auto& self, int l, int r) {
if (l >= r)
return;
int mn = inf;
for (int i = l; i <= r; i++) {
mn = min(mn, a[i]);
}
// cout << l << " " << r << " " << mn << endl;
int g = 0;
for (int i = l + 1; i <= r; i++) {
int res = abs(a[i] - a[i - 1]);
g = __gcd(g, res);
}
if (g == 0)
return;
/*if (l == 1 && r == n) {
for (int i = 1; i * i <= g; i++) {
if (g % i == 0) {
if (i > mn)
ans[i - mn] = 1;
if (g / i > mn)
ans[g / i - mn] = 1;
}
}
nowans = 1;
}*/
/*else
{
for (int i = 1; i * i <= g; i++) {
if (i * i == g) {
if (i > mn)
ans[i - mn]++;
}
else if (g % i == 0) {
if (i > mn)
ans[i - mn]++;
if (g / i > mn)
ans[g / i - mn]++;
}
}
nowans++;
}*/
ans.push_back(g);
int las = l - 1;
for (int i = l; i <= r; i++) {
if (a[i] == mn) {
self(self, las + 1, i - 1);
las = i;
}
else if (i == r) {
self(self, las + 1, r);
}
}
};
merge(merge, 1, n);
ll answer = 0;
int g = ans[0];
for (int x : ans) {
g = __gcd(x, g);
}
set<int> s;
for (int i = 1; i * i <= g; i++) {
if (i * i == g) {
if (i > mna)
s.insert(i - mna);
}
else if (g % i == 0) {
if (i > mna)
s.insert(i - mna);
if (g / i > mna)
s.insert(g / i - mna);
}
}
for (auto x : s) {
if (x <= k)
answer += x;
}
cout << s.size() << " " << answer << el;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int T = 1;
cin >> T;
while (T--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3616kb
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: 0ms
memory: 3552kb
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'