QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#175858#7185. Poor Studentsucup-team1231#RE 1ms5912kbC++142.6kb2023-09-11 03:21:532023-09-11 03:21:53

Judging History

你现在查看的是最新测评结果

  • [2023-09-11 03:21:53]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:5912kb
  • [2023-09-11 03:21:53]
  • 提交

answer

#pragma GCC optimize("-Ofast","-funroll-all-loops","-ffast-math")
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
typedef long long ll;
#define SZ 666666
int n,k,c[50005][55];
typedef pair<int,int> pii;
#define fi first
#define se second
template<class T>
struct Heap {
priority_queue<T> a,b;
void maintain() {
    while(!b.empty()) {
        assert(!a.empty());
        if(a.top()!=b.top()) break;
        a.pop(); b.pop();
    }
}
bool empty() {
    maintain();
    return a.empty();
}
T top() {
    maintain();
    assert(!a.empty());
    return a.top();
}
void edt(T x,int k) {
    if(k>0) a.push(x);
    else b.push(x);
}
};
Heap<pii> t[55][55],g[55];
int ax[55],a[55];
void assign(int x,int u) {
    for(int i=0;i<k;++i) if(i!=ax[x]) {
        t[ax[x]][i].edt(pii(c[x][i]-c[x][ax[x]],x),u);
    }
}
ll f[1<<10][10];
int bk[1<<10][10];
int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin>>n>>k;
    for(int i=1;i<=n;++i)
        for(int j=0;j<k;++j)
            cin>>c[i][j],g[j].edt(pii(c[i][j]*=-1,i),1);
    for(int j=0;j<k;++j) cin>>a[j];
    ll tans=0;
    for(int i=1;i<=n;++i) {
        memset(f,-127/3,sizeof f);
        for(int j=0;j<k;++j)
            if(!g[j].empty()) f[1<<j][j]=g[j].top().first,bk[1<<j][j]=-1;
        ll sw[13][13];
        memset(sw,-127/3,sizeof sw);
        for(int a=0;a<k;++a)
            for(int b=0;b<k;++b) {
                if(t[a][b].empty()) continue;
                sw[a][b]=t[a][b].top().first;
            }
        ll ans=-8e18; int X,B;
        for(int x=1;x<(1<<k);++x)
            for(int b=0;b<k;++b) if(x&(1<<b)) {
                if(::a[b]&&f[x][b]>ans) ans=f[x][b],X=x,B=b;
                for(int a=0;a<k;++a) if(!(x&(1<<a))) {
                    ll cur = f[x][b]+sw[b][a];
                    ll &tg = f[x^(1<<a)][a];
                    if(cur>tg) tg=cur, bk[x^(1<<a)][a]=b;
                }
            }
        tans-=ans;
        // cout<<X<<","<<B<<":"<<ans<<"\n";
        static int st[2333],ppl[2333]; int sn=0;
        while(X) {
            st[sn++]=B;
            int bb = bk[X][B]; X^=1<<B; B=bb;
        }
        ppl[sn-1]=g[st[sn-1]].top().second;
        {
        int i=ppl[sn-1];
        for(int j=0;j<k;++j) g[j].edt(pii(c[i][j],i),-1);
        }
        for(int i=1;i<sn;++i) ppl[i-1]=t[st[i]][st[i-1]].top().second;
        for(int i=0;i+1<sn;++i) assign(ppl[i],-1);
        for(int i=0;i<sn;++i) ax[ppl[i]]=st[i], assign(ppl[i],1);
        // for(int i=0;i<sn;++i)
        //     cout<<st[i]<<","<<ppl[i]<<" ";
        // cout<<"\n";
        --::a[st[0]];
    }
    printf("%lld\n",tans);
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 5912kb

input:

6 2
1 2
1 3
1 4
1 5
1 6
1 7
3 4

output:

12

result:

ok answer is '12'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3876kb

input:

3 3
1 2 3
2 4 6
6 5 4
1 1 1

output:

8

result:

ok answer is '8'

Test #3:

score: -100
Runtime Error

input:

1000 10
734 303 991 681 755 155 300 483 702 442
237 256 299 675 671 757 112 853 759 233
979 340 288 377 718 199 935 666 576 842
537 363 592 349 494 961 864 727 84 813
340 78 600 492 118 421 478 925 552 617
517 589 716 7 928 638 258 297 706 787
266 746 913 978 436 859 701 951 137 44
815 336 471 720 2...

output:


result: