QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#175860#7185. Poor Studentsucup-team1231#WA 1ms3808kbC++142.6kb2023-09-11 03:25:342023-09-11 03:25:34

Judging History

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

  • [2023-09-11 03:25:34]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3808kb
  • [2023-09-11 03:25:34]
  • 提交

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());
        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: 0
Wrong Answer
time: 1ms
memory: 3808kb

input:

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

output:

16

result:

wrong answer expected '12', found '16'