QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#697712 | #7078. Tower of the Sorcerer | ucup-team4352 | WA | 44ms | 53144kb | C++23 | 2.2kb | 2024-11-01 15:26:43 | 2024-11-01 15:26:43 |
Judging History
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 l=1,r=1;l<hp[i];l=r+1){
r=(hp[i]-1)/((hp[i]-1)/l);
e[l].push_back({i,1ll*((hp[i]-1)/l-(hp[i]-1)/mx)*i});
}
// for(int j=1;(j)*(j)<=hp[i];j++){
// e[j].push_back({i,1ll*((hp[i]-1)/j-((hp[i]-1)/mx))*i});
// e[(hp[i]-1)/j+1].push_back({i,1ll*(j-1-((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(t.w<0)assert(0);
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;
}
/*
40 467
143 18391
471 22687
231 21806
383 94823
362 46527
451 88115
320 89601
360 92308
383 46466
349 95722
270 60335
126 36990
113 68071
355 58054
203 30398
394 36124
117 17117
269 29509
474 36595
201 70286
167 16541
495 63496
242 75553
235 39044
251 14389
212 10259
351 89496
439 83002
407 26598
280 56999
355 46834
174 98959
309 52220
455 30279
352 47589
130 69369
348 31572
423 52546
481 45063
109 54526
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 6ms
memory: 11996kb
input:
4 1 3 2 4 4 5 6 1 6
output:
9
result:
ok single line: '9'
Test #2:
score: -100
Wrong Answer
time: 44ms
memory: 53144kb
input:
5000 679 84191 46042 81916 66659 74636 72443 10252 57443 21838 54620 84896 58466 20832 29643 45949 20576 50399 51434 56472 90759 68909 94348 39459 1731 81207 17614 26465 11775 93861 24936 25017 64663 21042 37570 32903 68583 68840 58347 93849 10841 10190 77131 10595 1959 57163 59047 16066 89850 73741...
output:
107497
result:
wrong answer 1st lines differ - expected: '0', found: '107497'