QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#794603 | #9738. Make It Divisible | shinonomezhou | WA | 12ms | 4800kb | C++23 | 1.5kb | 2024-11-30 15:07:36 | 2024-11-30 15:07:36 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=5e4+2e2;
using pll=pair<ll,ll>;
void solve(){
ll n,k;
cin>>n>>k;
vector<ll>b(N,0),ls(N,0),rs(N,0);
ll root=0;
for(int i=1;i<=n;i++){
cin>>b[i];
}
vector<ll>sk;
while(sk.size())sk.pop_back();
sk.push_back(0);
sk.push_back(1);
for(int i=2;i<=n;i++){
while(sk.size()){
ll x=sk.back();
if(x==0){
sk.push_back(i);
break;
}
if(b[i]<b[x]){
rs[x]=ls[i];
ls[i]=x;
sk.pop_back();
}else{
rs[x]=i;
sk.push_back(i);
break;
}
}
}
root=sk[1];
// for(int i=1;i<=n;i++)cout<<ls[i]<<'y'<<rs[i]<<'\n';
set<pll>st;
for(int i=1;i<=n;i++){
if(ls[i]&&b[ls[i]]-b[i]>0)st.insert({b[ls[i]]-b[i],b[i]});
if(rs[i]&&b[rs[i]]-b[i]>0)st.insert({b[rs[i]]-b[i],b[i]});
}
if(st.empty()){
cout<<k<<' '<<1ll*k*(k+1)/2<<'\n';
return;
}
pll p=*st.begin();
set<ll>ans;
ll fi=p.first,se=p.second;
for(ll i=1;i<=sqrt(fi);i++){
if(fi%i)continue;
if(i-se>=1&&i-se<=k)ans.insert(i-se);
if(i*i!=fi){
ll num=fi/i-se;
if(num>=1&&num<=k)ans.insert(num);
}
}
// st.erase(st.begin());
ll cnt=0,sum=0;
for(auto it:ans){
bool flag=1;
for(auto ite:st){
if(ite.first%(ite.second+it)){
flag=0;break;
}
}
if(flag)cnt++;sum+=it;
}
cout<<cnt<<' '<<sum<<'\n';
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
int tt;
cin>>tt;
while(tt--){
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 4316kb
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: 1ms
memory: 4712kb
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: 12ms
memory: 4800kb
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 6 0 0 0 1 0 0 0 20 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 8 0 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 14 0 0 0 0 0 0 0 0 0 0 0 5 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 6 0 0 0 0 0 0 0 0 0 0 0 0 0 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
wrong answer 5th lines differ - expected: '0 0', found: '0 6'