QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#741976#9738. Make It DivisibleOutsiderZzWA 0ms3716kbC++232.2kb2024-11-13 15:33:472024-11-13 15:34:04

Judging History

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

  • [2024-11-27 18:44:44]
  • hack成功,自动添加数据
  • (/hack/1263)
  • [2024-11-14 09:10:13]
  • hack成功,自动添加数据
  • (/hack/1178)
  • [2024-11-13 15:34:04]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3716kb
  • [2024-11-13 15:33:47]
  • 提交

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) {
        if (n != 2 && k != 1000000000) {
            std::cout << k << " " << rt << " " << a[rt] << "\n";
        }
        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;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3716kb

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: 3464kb

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'