QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#425528#6355. 5ushg8877WA 3ms13984kbC++141.5kb2024-05-30 12:53:412024-05-30 12:53:41

Judging History

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

  • [2024-05-30 12:53:41]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:13984kb
  • [2024-05-30 12:53:41]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define vi vector<array<int,2> >
#define ll long long
const int MAXN=2e5+5;
int n,s,cnt[MAXN];
vi vec[MAXN<<1];
vi operator +(vi a,int x){
	vi b;
	for(auto i:a) b.push_back({i[0]+x,i[1]+x});
	return b;
}
void merge(vi &b,vi a){
	if(b.empty()) {swap(a,b);return;}
	vi c;
	for(auto i:b) a.push_back(i);
	sort(a.begin(),a.end());
	for(int i=0,j;i<(int)a.size();i++){
		int l=a[i][0],r=a[i][1];
		j=i;
		while(j+1<(int)a.size()&&a[j+1][0]<=r+1){
			j++;
			r=max(r,a[j][1]);
		}
		i=j;
		c.push_back({l,r});
	}
	swap(c,b);c.clear();
	return;
}
int main(){
	ios::sync_with_stdio(false);
	// freopen("Otomachi_Una.in","r",stdin);
	// freopen("Otomachi_Una.out","w",stdout);
	cin>>n>>s;
	for(int i=1;i<=n;i++){
		int x;cin>>x;
		cnt[x]++;
	}
	vec[MAXN].push_back({0,0});
	int l=0,r=0;
	for(int i=0;i<=s;i++) if(cnt[i]){
		auto upd=[&](int x){
			if(i==0){
				l-=x;
				for(int k=l;k<=r;k++){
					int t=k+(i-1)*x;
					if(-s<=t&&t<=s) if(!vec[k+MAXN].empty()) merge(vec[t+MAXN],vec[k+MAXN]+x);
				}
			}else{
				r+=x;
				for(int k=r;k>=l;k--){
					int t=k+(i-1)*x;
					if(-s<=t&&t<=s) if(!vec[k+MAXN].empty()) merge(vec[t+MAXN],vec[k+MAXN]+x);
				}
			}
		};
		for(int j=0;j<20;j++) if(cnt[i]>=(1<<j)){
			cnt[i]-=(1<<j);
			upd(1<<j);
		}	
		if(cnt[i]) upd(cnt[i]);
	}
	ll ans=0;
	for(int i=-n;i<=s;i++) for(auto j:vec[i+MAXN]) ans+=j[1]-j[0]+1;
	cout<<ans<<'\n';
	cerr<<"Running Time: "<<1.0*clock()/CLOCKS_PER_SEC<<'\n';
}

詳細信息

Test #1:

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

input:

7 9
0 0 0 1 1 2 5

output:

42

result:

ok 1 number(s): "42"

Test #2:

score: -100
Wrong Answer
time: 3ms
memory: 13888kb

input:

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

output:

40

result:

wrong answer 1st numbers differ - expected: '48', found: '40'