QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#742063#9738. Make It DivisibleOutsiderZzWA 1ms3624kbC++232.4kb2024-11-13 15:45:582024-11-13 15:45:58

Judging History

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

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

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";
        bool ok = true;
        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 && g <= a[x]) {
                ok = false;
            }
            return g;
        };

        auto v = dfs(dfs, rt);

        if (!ok) {
            std::cout << 0 << " " << 0 << "\n";
        } else 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: 3624kb

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

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

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: '1 1'