QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#796537#9738. Make It DivisibleatuerWA 1ms7680kbC++141.7kb2024-12-01 20:39:052024-12-01 20:39:07

Judging History

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

  • [2024-12-01 20:39:07]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7680kb
  • [2024-12-01 20:39:05]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define endl "\n"

const int N = 5e5+10, mod = 1e9+7;

int n, m, k;

int a[N];
int pre[N],nxt[N];
set<int> s;

void fj(int y,int x)
{
	for(int i=1;i*i<=x;i++)
	{
		if(x%i==0)
		{
			if(y<i&&y+k>=i)
			{
				s.insert(i-y);
			}
			int b=x/i;
			if(y<b&&y+k>=b)
			{
				s.insert(b-y);
			}
		}
	}
}



void solve()
{
	s.clear();
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		pre[i]=0;
		nxt[i]=0;
	}
	if(n==1)
	{
		cout<<k<<" "<<(1+k)*k/2<<endl;
		return;
	}
	for(int i=2;i<=n;i++)
	{
		if(a[i]!=a[1])
		{
			fj(min(a[i],a[1]),abs(a[i]-a[1]));
			break;
		}
	}
	a[0]=0;
	stack<int> st;
	if(st.size()==0)
	{
		cout<<k<<" "<<(1+k)*k/2<<endl;
		return;
	}
	st.push(0);
	for(int i=1;i<=n;i++)
	{
		while(a[i]<a[(int)st.top()])
		{
			st.pop();
		}
		pre[i]=st.top();
		st.push(i);
		//cout<<i<<" "<<pre[i]<<endl;
	}
	while(!st.empty())
	{
		st.pop();
	}
	a[n+1]=0;
	st.push(n+1);
	for(int i=n;i>=1;i--)
	{
		while(a[i]<a[(int)st.top()])
		{
			st.pop();
		}
		nxt[i]=st.top();
		st.push(i);
	}
	int cnt=0;
	int sum=0;
	for(auto x:s)
	{
		bool f=true;
		for(int i=1;i<=n;i++)
		{
			int now=a[i]+x;
			if(pre[i]>=1)
			{
				int ll=a[pre[i]]+x;
				if(now%ll)
				{
					f=false;
					break;
				}
			}
			if(nxt[i]<=n)
			{
				int rr=a[nxt[i]]+x;
				if(now%rr)
				{
					f=false;
					break;
				}
			}
		}
		if(f)
		{
			cnt++;
			sum+=x;
		}
	}
	cout<<cnt<<" "<<sum<<endl;
}

signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cout << fixed << setprecision(15);
	int ttt = 1;
	cin >> ttt;
	while (ttt--) solve();
	return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 7680kb

input:

3
5 10
7 79 1 7 1
2 1000000000
1 2
1 100
1000000000

output:

10 55
1000000000 500000000500000000
100 5050

result:

wrong answer 1st lines differ - expected: '3 8', found: '10 55'