QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#789169 | #9738. Make It Divisible | shinonomezhou | WA | 1ms | 3624kb | C++14 | 2.0kb | 2024-11-27 19:27:21 | 2024-11-27 19:27:23 |
Judging History
answer
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define endl "\n"
#define double long double
const int N = 3e5 + 10;
const ll INF = 0x3f3f3f3f3f3f3f;
ll n, m, k;
void solve()
{
cin>>n>>k;
vector<ll>b(n+5),lm(n+5),rm(n+5);
set<ll>tp;
for(int i=1;i<=n;i++){
cin>>b[i];
tp.insert(b[i]);
}
if(tp.size()==1){
cout<<k<<' '<<(k*(k+1)/2)<<endl;
return;
}
set<pll>st;
stack<pll>sta;
sta.push({0,0});
for(int i=1;i<=n;i++){
while(b[i]<=sta.top().first){
sta.pop();
}
lm[i]=sta.top().second;
sta.push({b[i],i});
}
while(!sta.empty())sta.pop();
sta.push({0,n+1});
for(int i=n;i>=1;i--){
while(b[i]<=sta.top().first){
sta.pop();
}
rm[i]=sta.top().second;
sta.push({b[i],i});
}
for(int i=1;i<=n;i++){
if(lm[i]>0)st.insert({b[lm[i]],b[i]});
if(rm[i]<=n)st.insert({b[rm[i]],b[i]});
}
ll mi=INF,x,y;
// ll g=0;
// for(auto e:st){
// g=__gcd(g,e.second-e.first);
// }
// set<ll>anss;
// ll ans=0,cnt=0;
// for(ll i=1;i*i<=g;i++){
// if(i-1>=1){
// anss.insert(i-1);
// }
// if(g/i-1>=1){
// anss.insert(g/i-1);
// }
// }
// for(auto e:anss){
// if(e>k)break;
// cout<<e<<endl;
// cnt++;ans+=e;
// }
// cout<<anss.size()<<' '<<ans<<endl;
for(auto e:st){
if(e.second-e.first<mi){
mi=e.second-e.first;
x=e.first,y=e.second;
}
}
ll cnt=0,ans=0;
set<ll>anss;
for(ll i=1;i*i<=y-x;i++){
if((y-x)/i-x>=1)
anss.insert((y-x)/i-1);
if(i-x>=1)
anss.insert(i-1);
}
for(auto e:anss){
if(e>k)break;
bool ff=true;
for(auto t:st){
if((t.second+e)%(t.first+e)!=0){
ff=false;break;
}
}
if(ff){
// cout<<e<<endl;
cnt++;ans+=e;
}
}
cout<<cnt<<' '<<ans<<endl;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int _ = 1;
cin >> _;
while (_--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3544kb
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: 3624kb
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: 1ms
memory: 3620kb
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'