QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#556201#9129. Quotient SumhezlikWA 1ms5912kbC++141.3kb2024-09-10 15:50:522024-09-10 15:50:53

Judging History

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

  • [2024-09-26 15:38:30]
  • hack成功,自动添加数据
  • (/hack/908)
  • [2024-09-10 15:50:53]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5912kb
  • [2024-09-10 15:50:52]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

typedef long long int64;
typedef long double db;

const int N=200000;
const db eps=1e-12L;
const int64 INF=(1LL<<62)-1;

// struct bigint{

// };

int n;
int64 a[N+9],dp[N+9];

void DivideDP(int l,int r){
  if (l==r) return;
  int mid=(l+r)>>1;
  DivideDP(l,mid);
  std::vector<int> cv;
  auto check=[&](int x,int y,int z){
    // return (dp[z]-dp[y])*(1.0L/a[y]-1.0L/a[x])+eps>=(dp[y]-dp[x])*(1.0L/a[z]-1.0L/a[y]);
    return (__int128)a[2]*(a[0]-a[1])*(dp[2]-dp[1])>=(__int128)a[0]*(a[1]-a[2])*(dp[1]-dp[0]);
  };
  for (int i=l;i<=mid;++i){
    for (;!cv.empty()&&a[cv.back()]==a[i]&&dp[cv.back()]>=dp[i];cv.pop_back());
    for (;cv.size()>=2&&check(cv.end()[-2],cv.back(),i);cv.pop_back());
    cv.push_back(i);
  }
  for (int i=mid+1,j=0;i<=r;++i){
    auto val=[&](int x){
      return a[i]/a[x]+dp[x];
    };
    for (;j+1<(int)cv.size()&&val(cv[j+1])<=val(cv[j]);++j);
    dp[i]=std::min(dp[i],val(cv[j]));
  }
  DivideDP(mid+1,r);
}

void solve() {
  std::cin>>n;
  for (int i=1;i<=n;++i)
    std::cin>>a[i];
  std::sort(a+1,a+n+1);
  for (int i=1;i<=n;++i) dp[i]=INF;
  dp[1]=0;
  DivideDP(1,n);
  std::cout<<dp[n]<<'\n';
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int t=1;
  // cin >> t;
  while (t--) {
    solve();
  }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3864kb

input:

3
2 3 6

output:

3

result:

ok "3"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3624kb

input:

2
15 4

output:

3

result:

ok "3"

Test #3:

score: 0
Accepted
time: 1ms
memory: 5868kb

input:

9
284791808 107902 13660981249408 4622332661 13405199 24590921 361 244448137 16077087227955422

output:

4580

result:

ok "4580"

Test #4:

score: 0
Accepted
time: 1ms
memory: 5664kb

input:

9
12 9 5 17 2 6 7 1 15

output:

6

result:

ok "6"

Test #5:

score: 0
Accepted
time: 0ms
memory: 5604kb

input:

10
19 13 18 11 20 16 6 8 17 3

output:

4

result:

ok "4"

Test #6:

score: 0
Accepted
time: 1ms
memory: 5904kb

input:

8
5 7 11 16 2 15 1 20

output:

7

result:

ok "7"

Test #7:

score: 0
Accepted
time: 0ms
memory: 5616kb

input:

10
13 2 19 11 15 9 16 5 12 1

output:

7

result:

ok "7"

Test #8:

score: 0
Accepted
time: 0ms
memory: 5608kb

input:

8
9 1 14 11 3 12 8 20

output:

7

result:

ok "7"

Test #9:

score: 0
Accepted
time: 0ms
memory: 5900kb

input:

4
4 6 20 3

output:

5

result:

ok "5"

Test #10:

score: -100
Wrong Answer
time: 0ms
memory: 5912kb

input:

382
1495 1297 1197 976 1335 486 1850 992 1483 1269 1898 1593 237 1342 711 957 1992 1401 1413 206 917 1831 1444 698 1291 1987 231 1559 1119 1822 1790 471 736 496 1157 1886 1974 699 1702 321 325 758 683 1826 1051 95 632 456 1224 1590 1394 1854 1226 1963 1926 1819 989 34 980 371 535 807 1541 144 433 12...

output:

12

result:

wrong answer 1st words differ - expected: '11', found: '12'