QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#789062#9738. Make It DivisibleshinonomezhouWA 1ms3820kbC++141.6kb2024-11-27 19:12:102024-11-27 19:12:12

Judging History

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

  • [2024-11-27 19:12:12]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3820kb
  • [2024-11-27 19:12:10]
  • 提交

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;
  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-1>=1)
      anss.insert((y-x)/i-1);
    if(i-1>=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: 3616kb

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

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

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'