QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#540611#8936. Team Arrangementucup-team3659#WA 0ms3996kbC++141.3kb2024-08-31 17:29:112024-08-31 17:29:12

Judging History

This is the latest submission verdict.

  • [2024-08-31 17:29:12]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3996kb
  • [2024-08-31 17:29:11]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
const int N = 65;
struct node{int l,r;}a[N];
int n, w[N], cnt[N], ans = -1e9, ww[N], num[N], pp[N], mo[13340];
long long state;

void dfs(int rest, int x)
{
	if(rest%x==0)
	{
		cnt[x] = rest / x;
		int i, j, k, res = 0, ok = 1;
		state = 0;
		for(i=j=1;i<=x;i++)
		{
			while(j<=n&&a[j].l>=i) state |= 1ll << num[j++];
			res += cnt[i] * w[i];
			k = i * cnt[i];
			while(k--)
			{
				if(!state)
				{
					ok = 0;
					break;
				}
				int x = mo[(state&-state)%13331];
				if(a[pp[x]].l>i||a[pp[x]].r<i)
				{
					ok = 0;
					break;
				}
				state ^= 1ll << x;
			}
			if(!ok) break;
		}
		if(ok) ans = max(ans,res);
	}
	for(cnt[x]=0;x*cnt[x]+(x+1)<=rest;cnt[x]++) dfs(rest-x*cnt[x],x+1);
}

int main()
{
	int i, j;
	scanf("%d", &n);
	for(i=1;i<=n;i++) scanf("%d%d", &a[i].l, &a[i].r);
	for(i=1;i<=n;i++) scanf("%d", &w[i]);
	sort(&a[1],&a[n]+1,[](node a,node b){if(a.l!=b.l)return a.l<b.l;return a.r<b.r;});
	for(i=1;i<=n;i++) ww[a[i].r]++;
	for(i=1;i<=n;i++) ww[i] += ww[i-1];
	for(i=n;i>=1;i--) num[i] = --ww[a[i].r], pp[num[i]] = i;
	for(i=0,j=1;i<=60;i++,j=j*2%13331) mo[j] = i;
	dfs(n,1);
	if(ans==(int)-1e9) printf("impossible");
	else printf("%d", ans);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
2 3
1 2
2 2
4 5 100

output:

9

result:

ok single line: '9'

Test #2:

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

input:

3
1 3
3 3
2 3
1 1 100

output:

100

result:

ok single line: '100'

Test #3:

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

input:

2
1 1
2 2
1 1

output:

impossible

result:

ok single line: 'impossible'

Test #4:

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

input:

3
2 3
1 2
2 2
-100 -200 100000

output:

-300

result:

ok single line: '-300'

Test #5:

score: -100
Wrong Answer
time: 0ms
memory: 3804kb

input:

9
1 4
2 5
3 4
1 5
1 1
2 5
3 5
1 3
1 1
1 1 1 1 1 1 1 1 1

output:

5

result:

wrong answer 1st lines differ - expected: '6', found: '5'