QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#204496#7078. Tower of the Sorcerer275307894aWA 26ms21104kbC++141.4kb2023-10-07 12:14:472023-10-07 12:14:47

Judging History

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

  • [2023-10-07 12:14:47]
  • 评测
  • 测评结果:WA
  • 用时:26ms
  • 内存:21104kb
  • [2023-10-07 12:14:47]
  • 提交

answer

#include<bits/stdc++.h>
#define Gc() getchar() 
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;using LL=__int128;
const int N=1e5+5,M=1e5,K=600+5,mod=1e9+7,Mod=mod-1;const db eps=1e-6;const ll INF=1e18+7;mt19937 rnd(263082);
int n,m,Mx,A[N],B[N],C[N];ll f[N],st[N][20];
ll qry(int x,int y){
	int d=__lg(y-x+1);return min(st[x+(1<<d)-1][d],st[y][d]);
}
void trans(int x){
	int i,j;int y=A[x]-1;
	for(i=1;i<=min(y,x-1);i=j+1){
		j=min(y/(y/i),x-1);
		f[x]=min(f[x],qry(i,j)+1ll*y/i*x-(A[x]-1)/Mx*x);
	}
}
void Solve(){
	int i,j;scanf("%d%d",&n,&m);
	ll sum=0;Mx=m;Me(A,0x3f);
	for(i=1;i<=n;i++) scanf("%d%d",&B[i],&C[i]),Mx=max(Mx,B[i]);
	for(i=1;i<=n;i++) {sum+=(C[i]-1)/Mx*B[i];A[B[i]]=min(A[B[i]],C[i]);}
	Me(f,0x3f);f[m]=0;
	for(i=1;i<=Mx;i++){
		if(A[i]<=M) trans(i);
		for(st[i][0]=f[i],j=1;(1<<j)<=i;j++) st[i][j]=min(st[i][j-1],st[i-(1<<j-1)][j-1]);
		// cerr<<f[i]<<' ';
	}
	printf("%lld\n",f[Mx]+sum);
}
int main(){
	int t=1;
	// scanf("%d",&t);
	while(t--) Solve();
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 6492kb

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: 26ms
memory: 21104kb

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:

108399

result:

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