Submission #42181933


Source Code Expand

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define op(x) ((x&1)?x+1:x-1)
#define odd(x) (x&1)
#define even(x) (!odd(x))
#define lc(x) (x<<1)
#define rc(x) (lc(x)|1)
#define lowbit(x) (x&-x)
#define mp(x,y) make_pair(x,y)
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
using namespace std;
const ll MAXN = 2e5+10,INF=1e18;
void tomin(ll& x,ll y){x=min(x,y);}
void tomax(ll& x,ll y){x=max(x,y);}

ll n,x;
ll a[MAXN],b[MAXN],pre[MAXN];
ll to[MAXN][30]; //向后跳x次

int tmp[MAXN],tot;
ll S[MAXN];

int cmp(int x,int y){
	assert(a[x] > 1);assert(a[y] > 1);
	return b[x] * (a[y]-1) < b[y] * (a[x]-1);
}

typedef array<ll,2> pr;

void chk(pr& x,pr y,int md){
	if(x[0] > y[0])x=y;
	else if((x[0]==y[0])){
		if(!md){
			if(x[1] < y[1])x=y;
		}else{
			if(x[1] > y[1])x=y;
		}
	}
}
pr operator+(pr x,pr y){
	return {x[0]+y[0],x[1]+y[1]};
}
//

pr dp[MAXN];

pr p[MAXN],g[MAXN];

pr chk(ll mid,int md=0){
	rep(i,0,n)dp[i] = g[i] = p[i] = {INF,INF};
	dp[0] = {0,0};

	rep(i,1,n){
		p[i-1] = dp[i-1] + (pr){-S[i-1],0};
		if(i>1)chk(p[i-1],p[i-2],md);

		if(a[i] > 1){
			g[i] = p[i-1];
			p[i-1] = {INF,INF};
		}else{
			pr v = p[i-1] + (pr){S[i]-mid,1};
			chk(dp[i],v,md);
		}

		int u=pre[i],j=1;
		while(u){
			if(j==30)break;
			pr v = g[u] + (pr){S[i]-mid + to[i][j],1};
			chk(dp[i],v,md);

			u=pre[u-1];j++;
		}
	}

	return dp[n];
}

int main(){

	ios::sync_with_stdio(false);

	cin>>n>>x;
	rep(i,1,n){
		cin>>a[i]>>b[i];
		pre[i] = (a[i]!=1) ? (i) : (pre[i-1]);
		S[i] = S[i-1] + ((a[i]==1) ? (b[i]) : (0));
	}


	rep(i,1,n){
		int u=i;tot=0;
		rep(j,1,29){
			if(!pre[u])break;
			u=pre[u];
			tmp[++tot]=u;
			sort(tmp+1,tmp+1+tot,cmp);

			ll S=0;
			rep(k,1,tot){
				S=S*a[tmp[k]]+b[tmp[k]];
				if(S>x){S=INF;break;}
			}
			to[i][j]=S;
			u--;
		}
	}

	
	ll L=-1e9,R=0,ret=INF;

	while(L<=R){
		ll mid=(L+R)/2;
		pr tmp=chk(mid);
		ll val=tmp[0] + tmp[1]*mid;
		if(val <= x){
			ret=mid;R=mid-1;
		}else{
			L=mid+1;
		}
	}
	
	assert(ret!=INF);
	
	pr Rv=chk(ret),Lv=chk(ret,1); 

	ll val = Rv[0] + Rv[1] * ret;
	
	assert(val <= x);
	ll diff = min(Rv[1] - Lv[1],(x-val) / (-ret) );

	cout<<Rv[1] - diff<<" "<<val-diff*ret<<" ";

    return 0;
}

Submission Info

Submission Time
Task Ex - Shojin
User Crying
Language C++ (GCC 9.2.1)
Score 650
Code Size 2385 Byte
Status AC
Exec Time 1596 ms
Memory 66164 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 650 / 650
Status
AC × 5
AC × 110
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 00_sample_04.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 00_sample_04.txt, 01_handmade_00.txt, 01_handmade_01.txt, 01_handmade_02.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt, 02_random_12.txt, 02_random_13.txt, 02_random_14.txt, 02_random_15.txt, 02_random_16.txt, 02_random_17.txt, 02_random_18.txt, 02_random_19.txt, 02_random_20.txt, 02_random_21.txt, 02_random_22.txt, 02_random_23.txt, 02_random_24.txt, 02_random_25.txt, 02_random_26.txt, 02_random_27.txt, 02_random_28.txt, 02_random_29.txt, 02_random_30.txt, 02_random_31.txt, 02_random_32.txt, 02_random_33.txt, 02_random_34.txt, 02_random_35.txt, 02_random_36.txt, 02_random_37.txt, 02_random_38.txt, 02_random_39.txt, 03_b_sum_max_00.txt, 03_b_sum_max_01.txt, 03_b_sum_max_02.txt, 03_b_sum_max_03.txt, 04_annealing_killer_00.txt, 04_annealing_killer_01.txt, 04_annealing_killer_02.txt, 04_annealing_killer_03.txt, 04_annealing_killer_04.txt, 04_annealing_killer_05.txt, 04_annealing_killer_06.txt, 04_annealing_killer_07.txt, 05_beam_killer_00.txt, 05_beam_killer_01.txt, 05_beam_killer_02.txt, 05_beam_killer_03.txt, 05_beam_killer_04.txt, 05_beam_killer_05.txt, 05_beam_killer_06.txt, 05_beam_killer_07.txt, 05_beam_killer_08.txt, 05_beam_killer_09.txt, 05_beam_killer_10.txt, 05_beam_killer_11.txt, 06_same_00.txt, 06_same_01.txt, 06_same_02.txt, 06_same_03.txt, 06_same_04.txt, 06_same_05.txt, 06_same_06.txt, 06_same_07.txt, 06_same_08.txt, 06_same_09.txt, 06_same_10.txt, 06_same_11.txt, 06_same_12.txt, 06_same_13.txt, 06_same_14.txt, 06_same_15.txt, 06_same_16.txt, 06_same_17.txt, 06_same_18.txt, 06_same_19.txt, 06_same_20.txt, 06_same_21.txt, 06_same_22.txt, 06_same_23.txt, 06_same_24.txt, 07_almost_same_00.txt, 07_almost_same_01.txt, 07_almost_same_02.txt, 07_almost_same_03.txt, 07_almost_same_04.txt, 08_a_leq_2_00.txt, 08_a_leq_2_01.txt, 08_a_leq_2_02.txt, 08_a_leq_2_03.txt, 09_a_leq_3_00.txt, 09_a_leq_3_01.txt, 09_a_leq_3_02.txt, 09_a_leq_3_03.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 6 ms 3524 KB
00_sample_01.txt AC 2 ms 3636 KB
00_sample_02.txt AC 2 ms 3640 KB
00_sample_03.txt AC 3 ms 3620 KB
00_sample_04.txt AC 2 ms 3696 KB
01_handmade_00.txt AC 2 ms 3632 KB
01_handmade_01.txt AC 2 ms 3536 KB
01_handmade_02.txt AC 2 ms 3572 KB
02_random_00.txt AC 2 ms 3572 KB
02_random_01.txt AC 6 ms 3784 KB
02_random_02.txt AC 56 ms 5556 KB
02_random_03.txt AC 2 ms 3588 KB
02_random_04.txt AC 201 ms 11408 KB
02_random_05.txt AC 4 ms 3740 KB
02_random_06.txt AC 2 ms 3588 KB
02_random_07.txt AC 2 ms 3564 KB
02_random_08.txt AC 2 ms 3580 KB
02_random_09.txt AC 1430 ms 64680 KB
02_random_10.txt AC 54 ms 5456 KB
02_random_11.txt AC 76 ms 16448 KB
02_random_12.txt AC 1534 ms 66000 KB
02_random_13.txt AC 1466 ms 66044 KB
02_random_14.txt AC 1475 ms 66048 KB
02_random_15.txt AC 1455 ms 66052 KB
02_random_16.txt AC 1483 ms 65996 KB
02_random_17.txt AC 1535 ms 66048 KB
02_random_18.txt AC 1481 ms 66000 KB
02_random_19.txt AC 1513 ms 66092 KB
02_random_20.txt AC 1478 ms 66040 KB
02_random_21.txt AC 1512 ms 66040 KB
02_random_22.txt AC 88 ms 19232 KB
02_random_23.txt AC 1548 ms 66096 KB
02_random_24.txt AC 1596 ms 66148 KB
02_random_25.txt AC 1494 ms 66052 KB
02_random_26.txt AC 1495 ms 66080 KB
02_random_27.txt AC 1495 ms 66028 KB
02_random_28.txt AC 1440 ms 66164 KB
02_random_29.txt AC 1557 ms 66032 KB
02_random_30.txt AC 1509 ms 66040 KB
02_random_31.txt AC 1515 ms 66024 KB
02_random_32.txt AC 1486 ms 66004 KB
02_random_33.txt AC 89 ms 19168 KB
02_random_34.txt AC 1462 ms 66000 KB
02_random_35.txt AC 1477 ms 66120 KB
02_random_36.txt AC 1483 ms 65980 KB
02_random_37.txt AC 1503 ms 66032 KB
02_random_38.txt AC 1514 ms 66052 KB
02_random_39.txt AC 1538 ms 66052 KB
03_b_sum_max_00.txt AC 91 ms 19108 KB
03_b_sum_max_01.txt AC 1490 ms 66028 KB
03_b_sum_max_02.txt AC 1456 ms 66080 KB
03_b_sum_max_03.txt AC 1458 ms 66108 KB
04_annealing_killer_00.txt AC 1533 ms 66040 KB
04_annealing_killer_01.txt AC 1533 ms 66028 KB
04_annealing_killer_02.txt AC 1534 ms 66048 KB
04_annealing_killer_03.txt AC 1545 ms 66036 KB
04_annealing_killer_04.txt AC 1546 ms 66120 KB
04_annealing_killer_05.txt AC 1545 ms 66052 KB
04_annealing_killer_06.txt AC 1172 ms 66148 KB
04_annealing_killer_07.txt AC 1174 ms 66092 KB
05_beam_killer_00.txt AC 1178 ms 66092 KB
05_beam_killer_01.txt AC 1172 ms 66152 KB
05_beam_killer_02.txt AC 1176 ms 66096 KB
05_beam_killer_03.txt AC 1177 ms 66032 KB
05_beam_killer_04.txt AC 1173 ms 66120 KB
05_beam_killer_05.txt AC 1175 ms 66028 KB
05_beam_killer_06.txt AC 1174 ms 66124 KB
05_beam_killer_07.txt AC 1182 ms 66124 KB
05_beam_killer_08.txt AC 1179 ms 66052 KB
05_beam_killer_09.txt AC 1175 ms 65996 KB
05_beam_killer_10.txt AC 1179 ms 66052 KB
05_beam_killer_11.txt AC 1178 ms 66112 KB
06_same_00.txt AC 1172 ms 66048 KB
06_same_01.txt AC 1174 ms 66108 KB
06_same_02.txt AC 1177 ms 66048 KB
06_same_03.txt AC 1180 ms 66048 KB
06_same_04.txt AC 1179 ms 66052 KB
06_same_05.txt AC 1176 ms 66112 KB
06_same_06.txt AC 1172 ms 66052 KB
06_same_07.txt AC 1180 ms 66032 KB
06_same_08.txt AC 1181 ms 66096 KB
06_same_09.txt AC 1180 ms 65980 KB
06_same_10.txt AC 1179 ms 66124 KB
06_same_11.txt AC 1177 ms 66108 KB
06_same_12.txt AC 1178 ms 66160 KB
06_same_13.txt AC 1176 ms 66120 KB
06_same_14.txt AC 1177 ms 66096 KB
06_same_15.txt AC 1139 ms 66044 KB
06_same_16.txt AC 1145 ms 66124 KB
06_same_17.txt AC 1133 ms 66096 KB
06_same_18.txt AC 1134 ms 65980 KB
06_same_19.txt AC 1153 ms 66076 KB
06_same_20.txt AC 1145 ms 66120 KB
06_same_21.txt AC 1136 ms 66044 KB
06_same_22.txt AC 1152 ms 66112 KB
06_same_23.txt AC 1138 ms 66108 KB
06_same_24.txt AC 1125 ms 66080 KB
07_almost_same_00.txt AC 1179 ms 66032 KB
07_almost_same_01.txt AC 1174 ms 66056 KB
07_almost_same_02.txt AC 1192 ms 66116 KB
07_almost_same_03.txt AC 1181 ms 66048 KB
07_almost_same_04.txt AC 1178 ms 66092 KB
08_a_leq_2_00.txt AC 1502 ms 66152 KB
08_a_leq_2_01.txt AC 1358 ms 66028 KB
08_a_leq_2_02.txt AC 1536 ms 66024 KB
08_a_leq_2_03.txt AC 1535 ms 66048 KB
09_a_leq_3_00.txt AC 1521 ms 66092 KB
09_a_leq_3_01.txt AC 1330 ms 65972 KB
09_a_leq_3_02.txt AC 1368 ms 66032 KB
09_a_leq_3_03.txt AC 1449 ms 65996 KB