QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#606971 | #8936. Team Arrangement | AAA___# | WA | 1ms | 3832kb | C++20 | 3.6kb | 2024-10-03 13:20:50 | 2024-10-03 13:20:53 |
Judging History
answer
#include<iostream>
#include<algorithm>
#include<stack>
#include<set>
#include<unordered_set>
#include<queue>
#include<deque>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<map>
#include<string>
#include<vector>
#include<array>
#include<functional>
using namespace std;
typedef long long ll;
ll highbit(ll x){
ll ans=2;
int num=1;
while(x){
x>>=2;
ans<<=2;
num++;
}
return num;
}
ll lowbit(ll x){
return x&(-x);
}
long long max(long long a,long long b){
return a>b?a:b;
}
long long min(long long a,long long b){
return a>b?b:a;
}
ll gcd(ll x,ll y)
{
if(y==1)
return x;
return gcd(y,x%y);
}
const int maxn=100;
ll w[maxn];
ll L[maxn];
ll R[maxn];
ll ans=-1e17;
ll mx=0;
array<ll,61> num;
array<ll,61> diff;
bool flag=0;
struct node{
ll w,num;
ll id;
bool operator<(node& that){
return this->w*that.num>this->num*that.w;
}
};
void dfs(array<ll,61>& num,array<ll,61>& diff,int pos,int n){
if(pos==n+1){
ll buff=0;
for(int i=1;i<=n;i++){
if(num[i]%i!=0){
return;
}
}
flag=true;
for(int i=1;i<=n;i++){
buff+=w[i]*(num[i]/i);
}
ans=max(ans,buff);
return;
}
vector<node> buff1;
for(int i=1;i<=n;i++){
if((num[i]%i)==0){
if(diff[i]>=(i-(num[i]%i))){
node now;
now.num=i;
now.w=w[i];
buff1.push_back(now);
}
continue;
}
if(diff[i]<(i-(num[i]%i))){
return;
}else{
node now;
now.num=i;
now.w=w[i];
buff1.push_back(now);
}
}
if(buff1.size()==0){
return;
}
sort(buff1.begin(),buff1.end());
ll sum=0;
int nn=n;
for(int i=1;i<=n;i++){
sum+=w[i]*(num[i]/i);
nn-=(num[i]/i);
}
for(int i=1;i<=n;i++){
if((num[i]%i)==0){
continue;
}
nn-=(i-(num[i]%i));
sum+=w[i];
}
mx=(buff1[0].w/buff1[0].num);
mx++;
if(nn<0){
return;
}else{
sum+=(mx*nn);
if(sum<=ans){
return;
}
}
vector<node> buff;
for(int i=L[pos];i<=R[pos];i++){
ll nk=i-(num[i]%i);
node now;
now.id=i;
now.num=nk;
now.w=w[i];
buff.push_back(now);
}
sort(buff.begin(),buff.end());
for(auto q:buff){
int i=q.id;
if(diff[i]>=(i-(num[i]%i))){
for(int j=L[pos];j<=R[pos];j++){
diff[j]--;
}
num[i]++;
dfs(num,diff,pos+1,n);
num[i]--;
for(int j=L[pos];j<=R[pos];j++){
diff[j]++;
}
}
}
return ;
}
void solve() {
int n;
cin>>n;
for(int i=1;i<=n;i++){
diff[i]=num[i]=0;
}
for(int i=1;i<=n;i++){
cin>>L[i]>>R[i];
for(int j=L[i];j<=R[i];j++){
diff[j]++;
}
}
for(int i=1;i<=n;i++){
cin>>w[i];
}
dfs(num,diff,1,n);
if(!flag){
cout<<"impossible"<<endl;
}else{
cout<<ans<<endl;
}
return;
}
int main(void){
unsigned int t;
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
//freopen("input.in","r",stdin);
//cin>>t;
t=1;
while(t--){
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3640kb
input:
3 2 3 1 2 2 2 4 5 100
output:
9
result:
ok single line: '9'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3604kb
input:
3 1 3 3 3 2 3 1 1 100
output:
100
result:
ok single line: '100'
Test #3:
score: 0
Accepted
time: 1ms
memory: 3796kb
input:
2 1 1 2 2 1 1
output:
impossible
result:
ok single line: 'impossible'
Test #4:
score: 0
Accepted
time: 1ms
memory: 3664kb
input:
3 2 3 1 2 2 2 -100 -200 100000
output:
-300
result:
ok single line: '-300'
Test #5:
score: 0
Accepted
time: 1ms
memory: 3832kb
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: 3572kb
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: -100
Wrong Answer
time: 1ms
memory: 3576kb
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:
-6925559
result:
wrong answer 1st lines differ - expected: '-2673021', found: '-6925559'