QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#763220 | #9738. Make It Divisible | zqx# | WA | 0ms | 3672kb | C++20 | 2.2kb | 2024-11-19 19:01:51 | 2024-11-19 19:01:52 |
Judging History
answer
#include<bits/stdc++.h>
#define endl "\n"
using namespace std;
using ll = long long;
const int maxn = 5e4 + 10;
vector<int> vec;
ll n,k,st[maxn][20];
void init(void)
{
for(int i=0;i<n;i++)
{
st[i][0]=i?abs(vec[i]-vec[i-1]):vec[i];
}
for(int j=1;j<20;j++)
{
for(int i=0;i+(1<<j)-1<n;i++)
{
st[i][j]=gcd(st[i][j-1],st[i+(1<<(j-1))][j-1]);
}
}
}
ll ask(int l,int r)
{
if(l>r)
{
return 0;
}
int s=__lg(r-l+1);
return gcd(st[l][s],st[r-(1<<s)+1][s]);
}
ll query(int l,int r,ll x)
{
return abs(gcd(vec[l]+x,ask(l+1,r)));
}
vector<int> get(vector<int> vec,int lim)
{
int g=0;
sort(vec.begin(),vec.end());
for(int i=1;i<(int)vec.size();i++)
{
g=gcd(g,abs(vec[i]-vec[i-1]));
}
vector<int> wait;
for(int i=1;i*i<=g;i++)
{
if(g%i==0)
{
if(i>vec[0]&&i-vec[0]<=lim)
{
wait.emplace_back(i-vec[0]);
}
if(g/i>max(i,vec[0])&&g/i-vec[0]<=lim)
{
wait.emplace_back(g/i-vec[0]);
}
}
}
return wait;
}
void solve(void)
{
int mx=-0x3f3f3f3f,mn=0x3f3f3f3f;
cin>>n>>k;
vec.clear();
vec=vector<int>(n);
for(int i=1;i<=n;i++)
{
cin>>vec[i-1];
mx=max(mx,vec[i-1]);
mn=min(mn,vec[i-1]);
}
if(mn==mx)
{
cout<<k<<" "<<k*(k+1)/2<<endl;
return;
}
init();
vector<int> wait=get(vec,k);
vector<tuple<ll,int,int>> range;
ll ans1=0,ans2=0;
for(const auto& x : wait)
{
bool valid=true;
for(const auto& [l,r,y] : range)
{
if(query(l,r,x)!=y+x)
{
valid=false;
break;
}
}
if(valid)
{
ans1++;
ans2+=x;
}
}
cout<<ans1<<" "<<ans2<<endl;
}
int main(void)
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--)
{
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3672kb
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: -100
Wrong Answer
time: 0ms
memory: 3596kb
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 1 1 0 0 0 0
result:
wrong answer 2nd lines differ - expected: '0 0', found: '1 1'