QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#741948 | #9738. Make It Divisible | OutsiderZz | WA | 0ms | 3756kb | C++23 | 2.0kb | 2024-11-13 15:31:30 | 2024-11-13 15:31:37 |
Judging History
你现在查看的是最新测评结果
- [2024-11-27 18:44:44]
- hack成功,自动添加数据
- (/hack/1263)
- [2024-11-14 09:10:13]
- hack成功,自动添加数据
- (/hack/1178)
- [2024-11-13 15:31:30]
- 提交
answer
#include <bits/stdc++.h>
using i64 = long long;
void solve() {
int n, k;
std::cin >> n >> k;
std::vector<int> a(n);
for (int i = 0; i < n; i++) {
std::cin >> a[i];
}
std::vector<int> l(n, -1), r(n, -1);
std::vector<int> stk;
int rt;
for (int i = 0; i < n; i++) {
int last = -1;
while (!stk.empty() && a[i] < a[stk.back()]) {
last = stk.back();
stk.pop_back();
}
if (!stk.empty()) {
r[stk.back()] = i;
} else {
rt = i;
}
l[i] = last;
stk.emplace_back(i);
}
//std::cerr << rt << " " << l[rt] << " " << r[rt] << "\n";
auto dfs = [&](auto &&self, int x) -> int {
int g = 0;
if (l[x] != -1) {
auto y = self(self, l[x]);
g = std::__gcd(g, y);
g = std::__gcd(g, a[l[x]] - a[x]);
}
if (r[x] != -1) {
auto y = self(self, r[x]);
g = std::__gcd(g, y);
g = std::__gcd(g, a[r[x]] - a[x]);
}
return g;
};
auto v = dfs(dfs, rt);
//std::cerr << v << "\n";
if (v == 0) {
std::cout << k << " " << 1LL * k * (k + 1) / 2 << "\n";
} else if (v == 1) {
std::cout << 0 << " " << 0 << "\n";
} else {
std::vector<int> cand;
for (int i = 1; i * i <= v; i++) {
if (v % i == 0) {
cand.push_back(i);
if (i != v / i) {
cand.push_back(v / i);
}
}
}
int x = a[rt];
int cnt = 0;
i64 res = 0;
for (auto y : cand) {
if (y > x && y - x <= k) {
cnt++;
res += y - x;
}
}
std::cout << cnt << " " << res << "\n";
}
}
int main() {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
int t;
std::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: 3552kb
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: 3756kb
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'