QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#695464 | #7078. Tower of the Sorcerer | ucup-team4352 | RE | 0ms | 0kb | C++23 | 1.8kb | 2024-10-31 20:05:38 | 2024-10-31 20:05:42 |
answer
#include<bits/stdc++.h>
#define ll long long
#define pii pair<ll,ll>
#define lowbit(x) (x&-x)
#define log(x) (31^__builtin_clz(x))
using namespace std;
const int maxn=1e5+5;
ll hp[maxn];
ll h[maxn],at[maxn];
ll dis[maxn];
struct node{
int v;
ll w;
};
vector<node>e[maxn];
void solve(){
ll n,t,mx=0;
cin>>n>>t;
mx=t;
memset(hp,0x3f,sizeof(hp));
memset(dis,0x3f,sizeof(dis));
for(int i=1;i<=n;i++){
ll t;
cin>>t>>h[i];
at[i]=t;
mx=max(mx,t);
hp[t]=min(hp[t],h[i]);
}
for(int i=1;i<=1e5;i++){
e[i].push_back({i-1,0});
if(hp[i]>1e5)continue;
for(int j=1;j*j<=hp[i];j++){
e[j].push_back({i,1ll*((hp[i]-1)/j-((hp[i]-1)/mx))*i});
if(j*j!=hp[i])e[(hp[i]-1)/j+1].push_back({i,1ll*(j-1-((hp[i]-1)/mx))*i});
}
for(int j=sqrt(hp[i])-1;j<=600&&j<=hp[i];j++){
e[j].push_back({i,1ll*((hp[i]-1)/j-((hp[i]-1)/mx))*i});
}
}
priority_queue<pii,vector<pii>,greater<pii>>q;
q.push({0,t});
dis[t]=0;
while(!q.empty()){
int u=q.top().second;
ll d=q.top().first;
q.pop();
if(dis[u]<d)continue;
for(auto t:e[u]){
if(dis[t.v]>t.w+dis[u]){
dis[t.v]=t.w+dis[u];
q.push({t.w+dis[u],t.v});
}
}
}
ll ans=dis[mx];
// for(int i=1;i<=5;i++)cout<<dis[i]<<"\n";
for(int i=1;i<=n;i++)ans=ans+1ll*((h[i]-1)/mx)*at[i];
cout<<ans<<"\n";
}
int main(){
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t=1;
// cin>>t;
while(t--)solve();
return 0;
}
/*
1 100
1 333
*/
/*
2 21
123 100000
155 100000
711618
817290
585603
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
4 1 3 2 4 4 5 6 1 6