QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#671430#7078. Tower of the SorcererSoestxWA 4ms22564kbC++232.6kb2024-10-24 12:23:212024-10-24 12:23:22

Judging History

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

  • [2024-10-24 12:23:22]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:22564kb
  • [2024-10-24 12:23:21]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pll pair<int,int>
#define fi first
#define se second
#define lowbit(x) (x&(-x))
typedef long long LL;
typedef unsigned long long ull;
int n,m,k;
int res;
const int N=1e6+10,M=1e5,mod=998244353;
const double eps=1e-6,inf=1e8;

int bit[N],dap[N];
int sum[N];
int dp[N];

struct stu
{
	int hp,ad;
	bool operator<(const stu &B) const
	{
		if(ad==B.ad) return hp<B.hp;
		else return ad<B.ad;
	}
}st[N];

void modify(int id,int x)
{
	if(bit[id]<x) return;
	bit[id]=dap[id]=x;
	while(id<=M)
	{
		bit[id]=x;
		for(int i=1;i<lowbit(id);i<<=1)
		{
			bit[id]=min(bit[id],bit[id-1]);
		}
		id+=lowbit(id);
	}
}
int ti;
int quer(int l,int r)
{
	ti++;
	int res=dap[r];
	while(l<=r)
	{
		int lr=r-(r&-r)+1;
		if(lr>=l) res=min(res,bit[r]),r=lr-1;
		else res=min(res,dap[r]),r--;
	}
	return res;
}

int qes(int id)
{
	//cout<<id<<"---------------------------"<<endl;
	int ma=1e18;
	for(int i=m;i<st[id].ad;i++)
	{
		int t=st[id].hp/i;
		int j;
		if(t)
		j=st[id].hp/t;
		else j=id-1;
		j=max(j,st[i].ad-1);
		if(ma>quer(i,j)+t*st[id].ad)
		{
			ma=quer(i,j)+t*st[id].ad;
		}
		t--;
		if(st[id].hp%j==0) ma=min(ma,dap[j]+t*st[id].ad);
		i=j;
	}
	return ma+sum[id-1];
}

void solve() {
	memset(bit,0x3f,sizeof bit);
	memset(dap,0x3f,sizeof dap);
	cin>>n>>m;
	for(int i=1;i<=n;i++) cin>>st[i].ad>>st[i].hp;
	sort(st+1,st+1+n);
	//for(int i=1;i<=n;i++) cout<<"---"<<st[i].ad<<" "<<st[i].hp<<endl;
	int mx=max(m,st[n].ad);
	if(n>10)
	for(int i=1;i<=n;i++)
	{
		if(st[i].hp<=679) cout<<st[i].ad<<endl;
	}
	for(int i=1;i<=n;i++)
	{
		sum[i]=(st[i].hp/mx)*st[i].ad;
		if(st[i].hp%mx==0) sum[i]-=st[i].ad;
		sum[i]+=sum[i-1];
	}
	int fro=0;
	while(fro<n&&st[fro].ad<=m) fro++;
	modify(m,0);
	//cout<<fro<<"---------"<<endl;
	for(int i=fro;i<=n;i++)
	{
		dp[i]=qes(i);
		//cout<<i<<" "<<dp[i]<<"----"<<dp[i]-sum[i]<<endl;
		modify(st[i].ad,dp[i]-sum[i]);
	}
	//cout<<ti<<endl;
	cout<<dp[n]<<endl;
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int T=1;
    //cin>>T;
    while(T--)
    {
        solve();
    }
    return 0;
}
/*
4 1
3 2
4 4
5 6
1 6

3 1
3 2
4 4
1 6


24 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
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 22564kb

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: 4ms
memory: 21528kb

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:

2036
2612
2859
6624
6692
7530
8279
10413
13643
17415
18645
25687
29227
30218
39984
49250
62547
63349
63414
63801
69486
71745
71814
72089
76635
79268
83123
84948
85652
92214
92614
93454
93841
94936
95898
98290
169560

result:

wrong answer 1st lines differ - expected: '0', found: '2036'