QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#661201#8936. Team ArrangementReqCxmChtChrTL 742ms3972kbC++143.1kb2024-10-20 15:10:422024-10-20 15:10:47

Judging History

This is the latest submission verdict.

  • [2024-10-20 15:10:47]
  • Judged
  • Verdict: TL
  • Time: 742ms
  • Memory: 3972kb
  • [2024-10-20 15:10:42]
  • Submitted

answer

#include<bits/stdc++.h>
//#pragma GCC optimize(3)
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
//#define int long long
#define ll long long
#define ull unsigned ll
#define db double
#define ldb long db
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pbI push_back
#define inf 1e9
#define mdI int mid=(l+r)>>1
#define lowbit(x) (x&-x)
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define MAXN 61
#define MAXM 5010
#define gint __int128
#define MOD 998244353
int qread(){
	char o=getchar();int f=1,x=0;
	for(;!isdigit(o);o=getchar())if(o=='-')f*=-1;
	for(;isdigit(o);o=getchar())x=x*10+o-'0';
	return f*x;
}
void chmx(int &x,int y){if(y>x)x=y;}
void chmi(int &x,int y){if(y<x)x=y;}
bool FLA;
namespace MathPart{
	#define rep(a,b,c) for(int a=b;a<=c;a++)
	#define vep(a,b,c) for(int a=b;a>=c;a--) 
	void exgcd(ll a,ll b,ll &x,ll &y){if(b==0){x=1,y=0;return;}exgcd(b,a%b,y,x);y-=(a/b)*x;}
	ll inv(ll a,ll p=MOD){ll x,y;exgcd(a,p,x,y);return (x+p)%p;}
	gint qp(ll a,ll b,ll p=MOD){gint rs=1,bs=a;while(b){if(b&1){rs=rs*bs%p;}bs=bs*bs%p;b>>=1;}return rs;}
	ll fac[MAXN],ifac[MAXN];
	void initF(ll n,ll p=MOD){
		fac[0]=1;rep(i,1,n){fac[i]=fac[i-1]*i%p;}
		ifac[n]=inv(fac[n],p);vep(i,n-1,0){ifac[i]=ifac[i+1]*(i+1)%p;}
	}
	ll C(ll n,ll m){if(n<m){return 0;}return fac[n]*ifac[m]%MOD*ifac[n-m]%MOD;}
	ll CC(ll n,ll m,ll p=MOD){ll rs=1;rep(i,0,m-1){rs=rs*(n-i)%p*inv(i+1,MOD)%p;}return rs;}
	ll S2OL(ll n,ll m){
		ll rs=0,d=1,f=1;
		for(ll k=0;k<=m;k++){
			rs=(rs+f*C(m,k)*qp(m-k,n,MOD)%MOD+MOD)%MOD;
			d=d*max(k,1ll)%MOD;f*=-1;
		}return rs*inv(d,MOD)%MOD;
	}
	ll phi(ll a){ll rs=a,m=sqrt(a);
		rep(i,2,m){if(a%i==0){rs=rs/i*(i-1);while(a%i==0){a/=i;}}}
		if(a>1){rs=rs/a*(a-1);}return rs;
	}
	bool MR(ll pr){if(pr<2)return 0;if(pr==3)return 1;if(pr==2)return 1;
		ll a=pr-1,b=0;while(!(a&1))a>>=1,b++;
		for(int i=1;i<=8;++i){
		    ll x=rand()%(pr-2)+2,v=qp(x,a,pr),j;if(v==1||v==pr-1)continue;
		    for(j=0;j<b-1;j++){v=(gint)v*v%pr;if(v==pr-1)break;}
			if(v!=pr-1)return 0;
		}return 1;
	}
}
//using namespace MathPart;
int cnt=0;
int n,ans=-inf,A[MAXN];
pii a[MAXN];int w[MAXN];vector<int>vec[MAXN];
void dfs(int x,int lst,int rem){
	if(rem==0){
		int ANS=0;
		rep(i,1,x){ANS+=w[A[i]];}
		if(ANS<=ans)return;
		int j=0;
		multiset<int>S;
		bool can=0;
		rep(i,1,x){
			while(j<n&&j<A[i]){j++;for(auto it:vec[j]){S.insert(it);}}
			rep(j,1,A[i]){
				if(S.empty()){can=1;break;}
				int it=*S.begin();
				if(it<A[i]){can=1;break;}
				S.erase(S.find(it)); 
			}
			if(can)break;
		}
		if(!can)chmx(ans,ANS);
		cnt++;return;
	}
	if(rem<lst)return;
	rep(i,lst,rem){A[x+1]=i;dfs(x+1,i,rem-i);}
}
bool FLB;
signed main(){
	cerr<<((&FLB)-(&FLA))/1024.0/1024<<endl;
	cin>>n;
	rep(i,1,n){a[i].fi=qread(),a[i].se=qread();vec[a[i].fi].pbI(a[i].se);}
	rep(i,1,n)w[i]=qread();
	dfs(0,1,n);
	if(ans==-inf)puts("impossible");
	else{cout<<ans;}
}
/*
23的分拆数:1255 
60的分拆数:966467 即10^6 
判定可行性使用贪心,w从小到大考虑先取r小的 
*/

详细

Test #1:

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

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

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

input:

2
1 1
2 2
1 1

output:

impossible

result:

ok single line: 'impossible'

Test #4:

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

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

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

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

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: 0
Accepted
time: 0ms
memory: 3812kb

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:

5939733

result:

ok single line: '5939733'

Test #9:

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

input:

14
1 7
1 2
8 8
1 1
7 8
6 9
7 8
1 4
6 9
3 3
1 1
3 7
5 8
4 8
-7139089 6365816 -9893288 5936146 -2803918 -4961415 1495365 -2564851 -2630365 -8608883 5813455 -4005459 -8844054 6703783

output:

impossible

result:

ok single line: 'impossible'

Test #10:

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

input:

14
6 13
3 7
2 13
6 8
4 5
12 13
3 10
4 11
2 14
3 4
5 13
10 14
10 14
3 12
-8599727 -1496394 855072 -7439122 -5170228 8009298 -250221 5841035 2949765 7166358 -3516548 -6851737 8173765 -917122

output:

impossible

result:

ok single line: 'impossible'

Test #11:

score: 0
Accepted
time: 162ms
memory: 3780kb

input:

60
21 34
13 34
48 49
31 42
5 6
16 30
1 25
35 37
3 14
3 32
25 54
2 41
24 44
27 52
26 55
8 35
31 47
41 42
4 35
53 59
13 19
11 51
36 48
5 59
40 44
28 50
5 51
37 53
50 60
14 50
22 58
20 50
20 21
5 20
19 55
5 45
19 35
7 29
5 53
25 33
19 51
37 41
13 29
12 24
13 40
10 22
1 5
22 32
14 42
11 41
16 60
35 43
3...

output:

impossible

result:

ok single line: 'impossible'

Test #12:

score: 0
Accepted
time: 345ms
memory: 3972kb

input:

60
4 11
1 7
8 24
2 18
11 26
6 18
5 26
5 11
6 21
17 30
9 22
1 29
7 14
9 18
23 26
3 28
3 14
4 16
7 18
2 3
8 8
10 20
8 29
5 28
5 7
16 19
16 18
8 11
5 28
12 21
8 20
8 27
9 23
15 28
1 4
6 27
10 15
10 20
2 7
4 21
9 23
23 25
20 23
19 29
16 25
12 15
3 27
3 9
1 26
9 11
12 14
14 24
16 22
7 7
9 26
24 29
3 27
1...

output:

impossible

result:

ok single line: 'impossible'

Test #13:

score: 0
Accepted
time: 742ms
memory: 3888kb

input:

60
2 4
15 18
1 17
3 10
11 19
3 14
14 14
9 10
9 15
1 17
10 17
3 9
4 10
6 10
7 14
3 20
20 20
5 14
1 9
3 17
10 14
3 13
8 15
9 13
5 9
2 16
4 9
9 19
13 18
4 20
8 19
13 18
9 11
11 14
8 17
7 11
1 11
5 7
10 12
3 8
8 18
9 20
11 19
1 16
1 17
3 20
3 3
2 10
7 7
4 18
8 16
5 7
16 20
1 5
10 15
9 11
2 6
11 19
6 16
...

output:

impossible

result:

ok single line: 'impossible'

Test #14:

score: -100
Time Limit Exceeded

input:

60
1 3
1 3
3 5
2 6
5 5
2 5
5 6
1 5
3 6
6 6
2 6
2 2
2 3
1 6
2 4
2 3
1 3
4 5
2 4
5 5
3 5
3 5
1 5
2 6
3 6
1 6
1 4
3 3
2 2
1 6
2 3
2 6
4 6
5 5
1 6
2 3
1 2
4 4
2 5
1 4
4 4
4 6
2 6
2 3
2 4
1 2
1 4
3 6
2 5
2 6
1 1
1 5
5 6
3 6
1 2
3 5
5 6
5 6
1 6
3 4
-9765941 -9284625 -9136963 -1872925 -9334679 -67293 96416...

output:


result: