QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#742020#9738. Make It DivisibleOutsiderZzWA 0ms3580kbC++232.5kb2024-11-13 15:39:102024-11-13 15:39:10

Judging History

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

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

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;
    while (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);
        }

        //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);

        if (T == 4) {
            if (n < 5) {
                for (int i = 0; i < n; i++) {
                    std::cout << a[i] << " \n"[i == n - 1];
                }
            }
        }
        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";
        }
    }

    return 0;
}

详细

Test #1:

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

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

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 7 23 5
1 1
1 5 2
0 0
5 23 7
0 0

result:

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