QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#786457#9738. Make It DivisibleshengZzz#WA 10ms6156kbC++201.8kb2024-11-26 21:36:372024-11-26 21:37:15

Judging History

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

  • [2024-11-27 18:44:44]
  • hack成功,自动添加数据
  • (/hack/1263)
  • [2024-11-26 21:37:15]
  • 评测
  • 测评结果:WA
  • 用时:10ms
  • 内存:6156kb
  • [2024-11-26 21:36:37]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e5+10;
int a[N],n,m;
vector<int> X,dc;
inline int Gcd(int a,int b) {
    return !b?a:gcd(b,a%b);
}
void check(int x) {
    int T=sqrt(x);
    for(int i=1;i<=T;i++) {
        if(x%i==0) {
            dc.push_back(i);
            if(i!=x/i) dc.push_back(x/i);
        }
    }
}

int tot; ll sum;

int st[N],top,lc[N],rc[N],rt,Gd[N];
int build() {
    for(int i=1;i<=n;i++) {
        while(top && a[st[top]]>a[i]) lc[i]=st[top--];
        if(top) rc[st[top]]=i;
        st[++top]=i;
    }
    return st[1];
}
int TTT;
bool dfs(int p) {
    int x=lc[p],y=rc[p];
    int G=0;
    if(x) {
        if(!dfs(x)) return false;
        G=gcd(Gd[x],G);
    }
    if(y) {
        if(!dfs(y)) return false;
        G=gcd(Gd[y],G);
    }
    int tt=a[p]+TTT;
    if(G%tt) return false; 
    Gd[p]=gcd(G,tt);
    return true;
}

bool ck(int t) {
    TTT=t;
    if(dfs(rt)) return true;
    else return false;
}

void slv (int a,int b) {
    if(a>b) swap(a,b);
    check(b-a);
    for(auto x:dc) {
        if(x>a && x-a<=m) X.push_back(x-a);
    }

    for(auto x:X)
        if(ck(x)) tot++,sum+=x;

    cout<<tot<<" "<<sum<<"\n";
}

void solve() {
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    rt=build();
    if(n==1) {
        cout<<m<<" "<<(1ll)*m*(m+1)/2<<"\n";
        return;
    }

    for(int i=1;i<n;i++) {
        if(a[i]!=a[i+1]) { slv(a[i],a[i+1]); return;}
    }
    cout<<"0 0\n";
}

void init() {
    X.clear(); dc.clear();
    tot=0; sum=0; top=0;
    for(int i=1;i<=n;i++) lc[i]=rc[i]=0;
}
int main() {
    int T; scanf("%d",&T);
    while(T--) {
        init(); solve();
    }
    return 0;
}

詳細信息

Test #1:

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

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

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: 0
Accepted
time: 1ms
memory: 3680kb

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:

ok 500 lines

Test #4:

score: 0
Accepted
time: 10ms
memory: 6156kb

input:

1
50000 1000000000
230 286458 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 ...

output:

0 0

result:

ok single line: '0 0'

Test #5:

score: 0
Accepted
time: 5ms
memory: 6044kb

input:

1
50000 1000000000
12087 1196491 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 553146...

output:

0 0

result:

ok single line: '0 0'

Test #6:

score: 0
Accepted
time: 4ms
memory: 6072kb

input:

1
50000 1000000000
2138984 42249920 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 3581...

output:

0 0

result:

ok single line: '0 0'

Test #7:

score: -100
Wrong Answer
time: 3ms
memory: 3744kb

input:

500
39 1000000000
75 7 7 381 41 1197 177 177 41 109 109 16 1197 177 41 381 1605 381 381 7 177 177 177 177 177 177 177 177 7 7 143 143 143 143 143 653 143 823 7
61 1000000000
327 327 327 327 405153474 327 405153474 327 810306621 810306621 810306621 810306621 810306621 810306621 810306621 810306621 81...

output:

0 0
25 631568356
13 18925862
1 1
2 6878
1 2
1 1
2 10
1 1
1 110
0 0
1 36
11 4796
1 29
1 4
6 2209209
0 0
3 8
1 2
9 30770061
1000000000 500000000500000000
1 3
0 0
0 0
1 5
1 1
6 6615501
3 8233825
2 1035
2 4
7 1288
0 0
1 3
16 1617883221
2 10
0 0
1 5739
15 102584
3 1100
0 0
2 4
1 1
0 0
0 0
1 1
0 0
0 0
1 1...

result:

wrong answer 23rd lines differ - expected: '1000000000 500000000500000000', found: '0 0'