QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#475288 | #9129. Quotient Sum | ucup-team4352# | WA | 1ms | 5672kb | C++23 | 908b | 2024-07-13 13:47:26 | 2024-07-13 13:47:26 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define lowbit(x) (x&-x)
#define inf 2000000000
#define log(x) (31^__builtin_clz(x))
using namespace std;
ll a[200005],dp[200005];
const ll qp18=1e18;
void solve(){
int n;
cin>>n;
ll ans=0;
set<ll>s;
map<ll,int>mp;
for(int i=1;i<=n;i++){
cin>>a[i];
dp[i]=2e18;
}
dp[1]=0;
sort(a+1,a+n+1);
for(int i=1;i<=n;i++){
mp[a[i]]=i;
s.insert(a[i]);
}
for(int i=1;i<n;i++){
s.erase(a[i]);
int tmp=a[i+1]/a[i];
for(int j=tmp;j<=tmp+10;j++){
if(a[i]*j>qp18)break;
if(s.lower_bound(a[i]*j)!=s.end()){
ll rs=*s.lower_bound(a[i]*j);
if(rs>=a[i]*(j+1))continue;
int loc=mp[rs];
dp[loc]=min(dp[loc],dp[i]+j);
}
}
}
cout<<dp[n]<<"\n";
}
int main(){
ios::sync_with_stdio(0), cin.tie(0);
int t=1;
//cin>>t;
while(t--)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3792kb
input:
3 2 3 6
output:
3
result:
ok "3"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3544kb
input:
2 15 4
output:
3
result:
ok "3"
Test #3:
score: 0
Accepted
time: 1ms
memory: 5672kb
input:
9 284791808 107902 13660981249408 4622332661 13405199 24590921 361 244448137 16077087227955422
output:
4580
result:
ok "4580"
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3624kb
input:
9 12 9 5 17 2 6 7 1 15
output:
8
result:
wrong answer 1st words differ - expected: '6', found: '8'