QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#695458#7078. Tower of the Sorcererucup-team4352RE 2ms11592kbC++231.7kb2024-10-31 20:05:012024-10-31 20:05:02

Judging History

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

  • [2024-10-31 20:05:02]
  • 评测
  • 测评结果:RE
  • 用时:2ms
  • 内存:11592kb
  • [2024-10-31 20:05:01]
  • 提交

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(j)-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: 100
Accepted
time: 2ms
memory: 11592kb

input:

4 1
3 2
4 4
5 6
1 6

output:

9

result:

ok single line: '9'

Test #2:

score: -100
Runtime Error

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:


result: