QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#755290#9738. Make It Divisiblezake#WA 0ms3636kbC++171.7kb2024-11-16 16:58:152024-11-16 16:58:15

Judging History

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

  • [2024-11-27 18:44:44]
  • hack成功,自动添加数据
  • (/hack/1263)
  • [2024-11-16 16:58:15]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3636kb
  • [2024-11-16 16:58:15]
  • 提交

answer

#include<bits/stdc++.h>

#define int long long
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
using namespace std;

void solve();


signed main() {
    fast
    int t = 1;
    cin >> t;
    while (t--) solve();
}

const int N = 5e4 + 10;

int n, k;
int a[N], b[N];

vector<int> fac(int x){
    vector<int> res;
    for(int i = 1; i * i <= x; i++){
        if(x % i == 0){
            res.push_back(i);
            if(i * i != x) res.push_back(x / i);
        }
    }
    sort(res.begin(), res.end());
    return res;
}

int gcd_seq(int l, int r, int x){
    int d = 0;
    for(int i = l; i <= r; i++){
        d = gcd(d, a[i] + x);
    }
    return d;
}

bool check(int l, int r, int x){
    if(l >= r) return true;
    int d = gcd_seq(l, r, x), mn = *min_element(a + l, a + r + 1) + x;
    if(d != mn) return false;
    int lst = l;
    bool res = true;
    for(int i = l; i <= r; i++){
        if(a[i] + x == d){
            res &= check(lst, i - 1, x);
            lst = i + 1;
        }
    }
    res &= check(lst, r, x);
    return res;
}

void solve() {
    cin >> n >> k;
    for(int i = 1; i <= n; i++) cin >> b[i], a[i] = b[i];

    if(*max_element(a + 1, a + n + 1) == *min_element(a + 1, a + n + 1)){
        cout << k << ' ' << k * (k + 1) / 2 << '\n';
        return;
    }

    sort(a + 1, a + n + 1);
    int d = 0;
    for(int i = 2; i <= n; i++) d = gcd(d, a[i] - a[i - 1]);
    auto facs = fac(d);
    int cnt = 0, sum = 0;
    for(auto f : facs){
        if(f <= a[1]) continue;
        if(a[1] + k < f) break;
        int x = f - a[1];
        if(check(1, n, x)) cnt++, sum += x;
    }
    cout << cnt << ' ' << sum << '\n';
}

详细

Test #1:

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

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

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: 0ms
memory: 3572kb

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 178th lines differ - expected: '1 2', found: '0 0'