QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#346058#6355. 5chenxinyang2006RE 26ms25368kbC++142.5kb2024-03-07 20:03:382024-03-07 20:03:42

Judging History

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

  • [2024-03-07 20:03:42]
  • 评测
  • 测评结果:RE
  • 用时:26ms
  • 内存:25368kb
  • [2024-03-07 20:03:38]
  • 提交

answer

#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(j);i<=(k);i++)
#define per(i,j,k) for(int i=(j);i>=(k);i--)
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define db double
#define ldb long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mkp make_pair
#define eb emplace_back
#define SZ(S) (int)S.size()
//#define mod 998244353
//#define mod 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3f
using namespace std;

template <class T>
void chkmax(T &x,T y){
	if(x < y) x = y;
}

template <class T>
void chkmin(T &x,T y){
	if(x > y) x = y;
}

inline int popcnt(int x){
	return __builtin_popcount(x);
}

inline int ctz(int x){
	return __builtin_ctz(x);
}


/*ll power(ll p,int k = mod - 2){
	ll ans = 1;
	while(k){
		if(k % 2 == 1) ans = ans * p % mod;
		p = p * p % mod;
		k /= 2;	
	}
	return ans;
}*/
int n,m,S;
int occ[200005],a[200005];

vector <int> f[400005],g[400005];
void upd(int pos,int val,int w){
	int i = 0,j = 0;
	while(i < SZ(g[pos - val]) && j < SZ(g[pos])){
		if(g[pos - val][i] + w < g[pos][j]) f[pos].eb(g[pos - val][i++] + w);
		else f[pos].eb(g[pos][j++]);
	}
	while(i < SZ(g[pos - val])) f[pos].eb(g[pos - val][i++] + w);
	while(j < SZ(g[pos])) f[pos].eb(g[pos][j++]);
	g[pos].clear();
	for(int cur:f[pos]){
		if(SZ(g[pos]) >= 2 && cur - g[pos][SZ(g[pos]) - 2] <= m) g[pos].pop_back();
		g[pos].eb(cur);
	}
	f[pos].clear();	
}

void fix(int val,int w){
//	printf("fix %d %d\n",val,w);
	per(pos,n + S,n + val) upd(pos,val,w);
}

void revfix(int val,int w){
//	printf("revfix %d %d\n",val,w);
	assert(val < 0);
	rep(i,0,n + S - val) upd(i,val,w);
}

int main(){
//	freopen("test.in","r",stdin);
	scanf("%d%d",&n,&S);
	rep(i,1,n){
		scanf("%d",&a[i]);
		occ[a[i]]++;
	}
	g[n].eb(0);
	m = occ[1];
	rep(i,2,S){
		rep(k,0,17){
			if(occ[i] >= (1 << k)){
				fix((i - 1) << k,1 << k);
				occ[i] -= 1 << k;
			}
		}
		if(occ[i]) fix((i - 1) * occ[i],occ[i]);
	}
/*	rep(i,n,n + S){
		printf("dp %d\n",i);
		for(int val:g[i]) printf("%d ",val);
		printf("\n");
	}*/

	rep(k,0,17){
		if(occ[0] >= (1 << k)){
			revfix(-(1 << k),1 << k);
			occ[0] -= 1 << k;
		}	
	}
	if(occ[0]) revfix(-occ[0],occ[0]);
/*	rep(i,0,n + S){
		printf("dp %d\n",i);
		for(int val:g[i]) printf("%d ",val);
		printf("\n");
	}*/
	ll ans = 0;
	rep(i,0,n + S){
		rep(k,0,SZ(g[i]) - 2) ans += min(g[i][k + 1] - g[i][k],1 + m);
		if(!g[i].empty()) ans += m + 1;
	}
	printf("%lld\n",ans);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

7 9
0 0 0 1 1 2 5

output:

42

result:

ok 1 number(s): "42"

Test #2:

score: 0
Accepted
time: 0ms
memory: 24080kb

input:

10 33
9 9 8 1 1 1 1 1 1 1

output:

48

result:

ok 1 number(s): "48"

Test #3:

score: 0
Accepted
time: 3ms
memory: 22680kb

input:

10 14
2 4 4 1 0 1 0 1 0 1

output:

81

result:

ok 1 number(s): "81"

Test #4:

score: 0
Accepted
time: 3ms
memory: 23436kb

input:

10 14
3 5 3 0 1 0 1 0 1 0

output:

87

result:

ok 1 number(s): "87"

Test #5:

score: 0
Accepted
time: 0ms
memory: 22640kb

input:

40 50
1 1 1 1 3 3 0 3 1 1 0 0 2 1 0 0 1 0 0 2 7 1 2 1 3 0 2 2 3 1 1 0 0 2 0 1 1 0 1 1

output:

1067

result:

ok 1 number(s): "1067"

Test #6:

score: 0
Accepted
time: 0ms
memory: 24032kb

input:

1200 1000
1 1 2 3 0 1 0 0 1 1 0 2 3 0 1 2 0 0 1 0 4 1 1 2 1 1 0 0 1 1 0 1 0 0 1 0 1 0 0 0 1 1 0 1 0 0 1 0 0 1 1 0 1 2 0 4 0 3 1 6 0 1 1 0 0 0 0 4 0 0 0 0 0 0 1 0 0 1 7 1 1 1 0 1 0 1 0 1 1 0 0 1 1 1 3 0 1 0 1 0 0 1 1 2 2 0 1 1 0 0 1 4 1 2 0 0 0 3 0 0 2 1 0 2 0 0 0 1 1 0 0 2 0 0 0 0 1 1 0 1 0 1 6 1 1 ...

output:

737899

result:

ok 1 number(s): "737899"

Test #7:

score: 0
Accepted
time: 11ms
memory: 23300kb

input:

12000 10000
1 1 0 0 1 0 2 1 3 0 0 1 0 3 1 1 0 1 1 1 1 1 2 1 0 1 2 1 0 1 2 0 5 1 1 1 0 2 0 1 0 1 0 3 2 0 1 0 1 1 2 1 0 0 1 1 0 1 0 0 0 1 0 1 0 1 0 4 0 1 3 1 0 0 1 0 1 2 1 0 0 1 1 0 2 1 1 0 1 0 1 0 0 2 1 1 3 0 1 1 1 0 0 0 1 1 1 0 3 0 0 0 2 0 0 0 1 0 2 0 1 1 1 0 0 1 0 1 0 2 0 0 0 0 0 0 0 1 0 1 0 0 4 1 ...

output:

73685347

result:

ok 1 number(s): "73685347"

Test #8:

score: 0
Accepted
time: 26ms
memory: 25368kb

input:

36000 30000
0 3 4 1 2 1 1 0 0 1 1 0 1 0 2 1 0 0 0 0 2 1 0 2 0 0 0 0 0 1 1 4 1 4 0 0 2 0 0 0 1 1 0 0 1 1 0 1 0 0 0 0 1 1 0 3 1 1 1 0 0 0 0 0 0 1 2 0 2 3 0 0 0 0 3 1 0 0 0 1 0 1 2 0 0 2 0 1 0 0 2 1 1 0 3 1 6 0 0 1 1 2 0 1 2 0 0 1 0 1 1 0 0 1 0 0 0 1 0 2 0 1 1 1 0 0 5 2 0 5 1 0 0 0 0 1 1 1 8 0 1 1 0 1 ...

output:

658813003

result:

ok 1 number(s): "658813003"

Test #9:

score: -100
Runtime Error

input:

200000 200000
0 1 1 1 1 1 0 1 0 3 1 0 0 1 1 0 1 1 1 2 3 0 1 0 1 0 2 5 0 1 1 4 1 1 0 0 0 0 0 0 2 1 0 0 2 1 1 2 0 3 0 1 3 0 1 1 1 0 1 0 1 2 0 1 1 0 0 2 2 1 0 1 1 2 4 1 0 2 0 5 1 2 0 0 1 0 2 3 1 0 1 1 1 1 0 0 0 5 1 0 0 1 2 1 1 0 0 0 1 0 0 1 2 1 0 0 2 1 2 3 0 0 3 1 0 1 0 0 1 1 1 0 1 0 1 0 0 1 0 0 1 1 1 ...

output:


result: