QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#742234 | #9738. Make It Divisible | OutsiderZz | WA | 1ms | 3576kb | C++23 | 3.0kb | 2024-11-13 16:08:32 | 2024-11-13 16:08:40 |
Judging History
你现在查看的是最新测评结果
- [2024-11-27 18:44:44]
- hack成功,自动添加数据
- (/hack/1263)
- [2024-11-14 09:10:13]
- hack成功,自动添加数据
- (/hack/1178)
- [2024-11-13 16:08:32]
- 提交
answer
#include <bits/stdc++.h>
using i64 = long long;
void solve() {
}
int main() {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
int t;
std::cin >> t;
int T = t;
for (int t = 0; t < T; t++) {
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);
}
if (t ==231) {
for (int i = 0; i < n; i++) {
std::cout << a[i] << " \n"[i == n - 1];
}
}
//std::cerr << rt << " " << l[rt] << " " << r[rt] << "\n";
std::vector<std::vector<int>> cand;
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]);
}
if (g == 0) {
return 0;
}
std::vector<int> t;
for (int i = 1; i * i <= g; i++) {
if (g % i == 0) {
int v = i;
if (v > a[x] && a[x] + k >= v) {
t.push_back(v - a[x]);
}
if (v * v != g) {
v = g / i;
if (v > a[x] && a[x] + k >= v) {
t.push_back(v - a[x]);
}
}
}
}
cand.push_back(t);
return g;
};
auto v = dfs(dfs, rt);
if (v == 0) {
std::cout << k << " " << 1LL * k * (k + 1) / 2 << "\n";
} else if (v == 1) {
std::cout << 0 << " " << 0 << "\n";
} else {
int cnt = 0;
i64 res = 0;
int N = cand.size();
std::map<int, int> map;
for (auto v : cand) {
for (auto x : v) {
//std::cerr << x << " \n"[x == v.back()];
map[x]++;
}
}
for (auto [x, y] : map) {
if (y == N) {
cnt++;
res += x;
}
}
std::cout << cnt << " " << res << "\n";
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3576kb
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: 0
Accepted
time: 0ms
memory: 3532kb
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 0 0 0 0 0 0
result:
ok 4 lines
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 3552kb
input:
500 4 1000000000 8 14 24 18 4 1000000000 17 10 18 14 4 1000000000 6 17 19 19 4 1000000000 15 14 15 25 4 1000000000 16 16 5 25 4 1000000000 4 30 20 5 4 1000000000 11 4 23 9 4 1000000000 14 25 13 2 4 1000000000 18 18 1 15 4 1000000000 22 22 22 28 4 1000000000 15 17 17 10 4 1000000000 22 14 13 25 4 100...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
wrong answer 232nd lines differ - expected: '0 0', found: '3 27 9 1'