QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#559214#6355. 5Jessica2333Compile Error//C++141.4kb2024-09-11 20:51:082024-09-11 20:51:08

Judging History

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

  • [2024-09-11 20:51:08]
  • 评测
  • [2024-09-11 20:51:08]
  • 提交

answer

#include<iostream>
#include<vector>
using namespace std;
int N,S,A[200008],buc[400008],W[508],V[508];
struct NODE{
	int l,r;
};
vector<NODE> f[400008];
int vis[400008];
const int O=200000;
bool g[2008][2008];
void add_(int p,int l,int r)
{
//	cout<<" add_ "<<p-O<<" "<<l<<" "<<r<<"\n";
	if(f[p].empty()) f[p].push_back({l,r});
	else
	{
		vector<NODE> vec;
		for(auto v:f[p]) vec.push_back(v);
		f[p].clear();
		bool flag=1;
		for(auto v:vec)
		{
			if(v.r<l-1) f[p].push_back(v);
			else if(l<=v.l&&v.r<=r) continue;
			else if(v.l>r+1) f[p].push_back({l,r}),f[p].push_back(v),flag=0;
			else l=min(l,v.l),r=max(r,v.r);
		}
		if(flag) f[p].push_back({l,r});
	}
}
signed main()
{
	cin>>N>>S;O=N;
	for(int i=1;i<=N;i++) cin>>A[i],buc[A[i]]++;
	int N2=0;
	for(int i=1;i<=N;i++)
		for(int j=0;buc[A[i]];j++) V[++N2]=A[i]*min(1<<j,buc[A[i]]),W[N2]=min(1<<j,buc[A[i]]),buc[A[i]]-=W[N2];
	f[O].push_back({0,0});
	for(int i=1;i<=N2;i++)
	{
		if(V[i]>0)
		{
			for(int j=S+O-1;j>=0;j--)
			{
				if(j+V[i]-W[i]>=S+O) continue;
				for(auto v:f[j])
				{
					add_(j+V[i]-W[i],v.l+W[i],v.r+W[i]);
				}
			}
		}
		else
		{
			for(int j=0;j<S+O;j++)
			{
				if(j+V[i]-W[i]<0) continue;
				for(auto v:f[j])
				{
					add_(j+V[i]-W[i],v.l+W[i],v.r+W[i]);
				}
			}
		}
	}
	long long ans=0;
	for(int i=0;i<S+O;i++) for(auto v:f[i]) ans+=v.r-v.l+1;
	cout<<ans;
	return 0;
}
/*
1 1
0 1
*/

Details

answer.code: In function ‘int main()’:
answer.code:34:20: error: assignment of read-only variable ‘O’
   34 |         cin>>N>>S;O=N;
      |                   ~^~