Submission #54227955


Source Code Expand

#pragma GCC optimize(2,3,"Ofast","inline")
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=2e5+10,R=1e6;
int n;
int a[maxn],nx[R+10];
ll ans;
inline int erfen(int x){
    int l=1,r=n,res=0;
    while(l<=r){
        int mid=(l+r)>>1;
        if(a[mid]>x){l=mid+1;res=mid;}
        else    r=mid-1;
    }
    return res;
}
signed main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++)   scanf("%d",&a[i]);
    sort(a+1,a+n+1,greater<int>());
    for(int i=1;i<=R;i++){nx[i]=erfen(i);}
    for(int i=1;i<=n;i++){
        int now=n;
        while(now>i){
            int k=a[i]/a[now];
            int nxt=nx[a[i]/k];
            if(nxt<=i||nxt>n)    nxt=i;
            ans+=1ll*(now-nxt)*k;
            now=nxt;
        }
    }
    printf("%lld\n",ans);
}

Submission Info

Submission Time
Task E - Max/Min
User yaohaoyou
Language C++ 20 (gcc 12.2)
Score 475
Code Size 817 Byte
Status AC
Exec Time 1636 ms
Memory 8588 KiB

Compile Error

Main.cpp: In function ‘int main()’:
Main.cpp:19:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   19 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
Main.cpp:20:34: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   20 |     for(int i=1;i<=n;i++)   scanf("%d",&a[i]);
      |                             ~~~~~^~~~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 475 / 475
Status
AC × 3
AC × 25
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All min_01.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
min_01.txt AC 3 ms 7640 KiB
random_01.txt AC 1257 ms 8396 KiB
random_02.txt AC 400 ms 7944 KiB
random_03.txt AC 1252 ms 8352 KiB
random_04.txt AC 1153 ms 8304 KiB
random_05.txt AC 1259 ms 8468 KiB
random_06.txt AC 1113 ms 8276 KiB
random_07.txt AC 1636 ms 8588 KiB
random_08.txt AC 251 ms 7760 KiB
random_09.txt AC 1631 ms 8464 KiB
random_10.txt AC 814 ms 7980 KiB
random_11.txt AC 1632 ms 8460 KiB
random_12.txt AC 1308 ms 8208 KiB
random_13.txt AC 1111 ms 8464 KiB
random_14.txt AC 677 ms 8168 KiB
random_15.txt AC 1146 ms 8496 KiB
random_16.txt AC 421 ms 8028 KiB
random_17.txt AC 26 ms 8276 KiB
random_18.txt AC 30 ms 8352 KiB
random_19.txt AC 29 ms 8352 KiB
random_20.txt AC 51 ms 8384 KiB
random_21.txt AC 1227 ms 8460 KiB
sample_01.txt AC 4 ms 7500 KiB
sample_02.txt AC 3 ms 7728 KiB
sample_03.txt AC 6 ms 7576 KiB