QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#602067#8936. Team Arrangementinksamurai#WA 0ms3872kbC++231.7kb2024-09-30 18:47:372024-09-30 18:47:37

Judging History

This is the latest submission verdict.

  • [2024-09-30 18:47:37]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3872kb
  • [2024-09-30 18:47:37]
  • Submitted

answer

#include <bits/stdc++.h>
#define int ll
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define rng(i,c,n) for(int i=c;i<n;i++)
#define fi first
#define se second
#define pb push_back
#define sz(a) (int) a.size()
#define all(a) a.begin(),a.end()
#define vec(...) vector<__VA_ARGS__>
#define _3M8yqhy ios::sync_with_stdio(0),cin.tie(0)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
void print(){cout<<'\n';}
template<class h,class...t>
void print(const h&v,const t&...u){cout<<v<<' ',print(u...);}

#define nare cout<<"impossible\n"; return;

const int inf=1e18;

void chmax(int&a,int b){
	a=max(a,b);
}

void slv(){
	int n;
	cin>>n;

	vec(pii) a(n);
	rep(i,n){
		cin>>a[i].fi>>a[i].se;
	}

	vi wit(n+1);
	rng(i,1,n+1){
		cin>>wit[i];
	}

	vi open(n+1),close(n+1);
	rep(i,n){
		open[a[i].fi]+=1;
		close[a[i].se]+=1;
	}

	// dp[point][overall chosen][open and chosen] = { maximum value }
	vec(vi) dp(n+1,vi(n+1,-inf)),ndp1,ndp;
	dp[0][0]=0;
	int now=0;
	rng(i,1,n+1){
		ndp=vec(vi)(n+1,vi(n+1,-inf));
		int ad=open[i];
		now+=ad;
		rep(j,n+1){
			rep(k,n+1){
				if(dp[j][k]==-inf) continue;
				rep(take,n+1){
					if(now>=k+take*i){
						int nj=j+take*i;
						int nk=k+take*i;
						chmax(ndp[nj][nk],dp[j][k]+take*wit[i]);
					}
				}
			}
		}
		ndp1=vec(vi)(n+1,vi(n+1,-inf));
		now-=close[i];
		rep(j,n+1){
			rep(k,n+1){
				int nk=k-close[i];
				if(nk<0) continue;
				chmax(ndp1[j][nk],ndp[j][k]);
			}
		}
		dp.swap(ndp1);
	}
	if(dp[n][0]==-inf){
		nare;
	}
	cout<<dp[n][0]<<"\n";
}

signed main(){
_3M8yqhy;
	slv();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 3784kb

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: 3572kb

input:

2
1 1
2 2
1 1

output:

impossible

result:

ok single line: 'impossible'

Test #4:

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

input:

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

output:

-300

result:

ok single line: '-300'

Test #5:

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

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:

6

result:

ok single line: '6'

Test #6:

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

input:

14
3 3
1 2
2 3
2 3
2 3
1 1
2 3
1 3
3 3
1 3
1 3
1 2
2 3
1 3
-9807452 -9610069 4156341 2862447 6969109 -7245265 -2653530 -5655094 6467527 -6872459 3971784 7312155 9766298 -2719573

output:

-16558567

result:

ok single line: '-16558567'

Test #7:

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

input:

14
1 2
1 4
2 3
3 5
4 5
2 5
2 4
2 4
1 2
3 4
1 5
2 4
1 1
4 5
-13763 -7354207 1096407 -9063321 -4824546 -6275546 1258145 -5272834 -8631107 3581157 2320771 -7714508 8446625 -6816167

output:

-2673021

result:

ok single line: '-2673021'

Test #8:

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

input:

14
2 3
4 4
1 7
3 6
3 4
1 1
1 4
4 7
3 7
1 7
2 3
6 6
1 1
3 6
2923142 1686477 640352 2848353 9202543 -4441381 4866381 -3610520 8124124 -1372894 1111310 -7538627 466143 9937961

output:

10814681

result:

wrong answer 1st lines differ - expected: '5939733', found: '10814681'