QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#606853#8936. Team ArrangementKanate#WA 1ms3672kbC++141.9kb2024-10-03 12:40:292024-10-03 12:40:29

Judging History

This is the latest submission verdict.

  • [2024-10-03 12:40:29]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 3672kb
  • [2024-10-03 12:40:29]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
// #define int long long 
#define rint int
#define endl '\n'
#define uint unsigned long long
void debug(int *a,int n){for(rint i=1;i<=n;i++) cout<<a[i]<<" ";cout<<endl;}
void debug(int *a){for(rint i=1;a[i];i++) cout<<a[i]<<" ";cout<<endl;}
void debug(int x){cout<<"debug: "<<x<<endl;}
int read(){
    int x=0,f=1;char c=getchar();
    while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
    while(isdigit(c))x=x*10+c-48,c=getchar();
    return x*f;
}const int N=2e5+10,p=1e9,mod=998244353;

int n,ans,w[N];
struct node{
	int l,r;
}a[N];
vector<int> ve,vee;
int cal()
{
	int sum=0;
	for(auto &it:ve) sum+=w[it];
	return sum;
}

bool use[N];
vector<int> res,res2;
bool check()
{
	res2.clear();
	for(rint i=1;i<=n;i++) use[i]=0,res2.push_back(i);
	for(auto &it:ve)
	{
		vee.clear(),res.clear();
		for(auto &i:res2)
		if(!use[i]&&a[i].l<=it) res.push_back(i);
		
		for(auto i:res)
		if(!use[i]&&a[i].r>=it&&a[i].l<=it) 
		{
			vee.push_back(i);
			if(vee.size()==it) break;
		}
		if(vee.size()<it) return 0;
		sort(vee.begin(),vee.end(),[&](const int &A,const int &B){return a[A].l>a[B].l;});
		for(rint i=0;i<it;i++) use[vee[i]]=1;
		
		swap(res,res2);
	}
	return 1;
}

void dfs(int x,int now)
{
	if(!x)
	{
		if(check()) ans=max(ans,cal());
		return;
	}
	if(now!=1) dfs(x,now-1);
	if(x>=now)
	{
		ve.push_back(now);
		dfs(x-now,now);
		ve.pop_back();
	}
}

void Work()
{
	n=read(),ans=-p;
	for(rint i=1;i<=n;i++) a[i]={read(),read()};
	for(rint i=1;i<=n;i++) w[i]=read();
	// for(rint i=1;i<=n;i++) a[i]={1,n};
	// for(rint i=1;i<=n;i++) w[i]=i;
	dfs(n,n);
	if(ans==-p) puts("impossible");
	else cout<<ans<<endl;
}

signed main()
{
    #ifndef ONLINE_JUDGE
	// freopen("1.in", "r", stdin);
	// freopen("1.out", "w", stdout);
	#else
	#endif
    
	int T=1;
	// int T=read();
	while(T--) Work();
	
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3672kb

input:

3
2 3
1 2
2 2
4 5 100

output:

impossible

result:

wrong answer 1st lines differ - expected: '9', found: 'impossible'