QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#863680#9738. Make It Divisible2018ljw#WA 0ms1792kbC++141.3kb2025-01-19 21:11:562025-01-19 21:11:58

Judging History

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

  • [2025-01-19 21:11:58]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:1792kb
  • [2025-01-19 21:11:56]
  • 提交

answer

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int gcd(int x,int y){
	return y?gcd(y,x%y):x;
}
int abs(int x){
	return x>0?x:-x;
}
int n,k,a[100001],g[100001];
int ls[100001],rs[100001];
int stk[100001],top,sz[100001];
void upd(int &g,int p){
	if(p==-1)return;
	if(g==-1)g=p;
	else g=gcd(g,p);
}
void dfs(int x){
	g[x]=-1;
	if(ls[x]){
		dfs(ls[x]);
		upd(g[x],g[ls[x]]);
		upd(g[x],abs(a[x]-a[x-1]));
	}
	if(rs[x]){
		dfs(rs[x]);
		upd(g[x],g[rs[x]]);
		upd(g[x],abs(a[x+1]-a[x]));
	}
}
bool check(int x){
	if(x>k||x<=0)return 0;
	int i;
	for(i=1;i<=n;i++)if(g[i]!=-1&&g[i]%(a[i]+x))return 0;
	return 1;
}
void solve(){
	int i,j;
	scanf("%d%d",&n,&k);
	top=0;
	for(i=0;i<=n;i++)ls[i]=rs[i]=stk[i]=0;
	for(i=1;i<=n;i++){
		scanf("%d",&a[i]);
		while(top&&a[stk[top]]>a[i])top--;
		ls[i]=rs[stk[top]];
		rs[stk[top]]=i;
		stk[++top]=i;
	}
	int rt=stk[1];
	dfs(rt);
	if(g[rt]<=0){
		printf("%d %lld\n",k,1ll*k*(k+1)/2);
		return;
	}
	long long res=0;
	int cnt=0;
	for(i=a[rt];i*i<=g[rt];i++){
		if(g[rt]%i)continue;
		int v=g[rt]/i;
		if(check(i-a[rt]))res+=i-a[rt],cnt++;
		if(v!=i&&check(v-a[rt]))res+=v-a[rt],cnt++;
	}
	printf("%d %lld\n",cnt,res);
}
int main(){
	int t;
	scanf("%d",&t);
	while(t--)solve();
}

详细

Test #1:

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

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

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

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'