QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#602145 | #8936. Team Arrangement | inksamurai# | WA | 1ms | 3760kb | C++23 | 1.7kb | 2024-09-30 20:11:56 | 2024-09-30 20:11:58 |
Judging History
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,2){
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 or nk>now) continue;
ndp1[j][nk]=ndp[j][k];
// 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();
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3528kb
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: 3532kb
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: 3600kb
input:
2 1 1 2 2 1 1
output:
impossible
result:
ok single line: 'impossible'
Test #4:
score: 0
Accepted
time: 1ms
memory: 3532kb
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: 3760kb
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:
impossible
result:
wrong answer 1st lines differ - expected: '6', found: 'impossible'