QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#175866#7185. Poor Studentsucup-team1231#TL 1982ms10472kbC++142.7kb2023-09-11 03:31:122023-09-11 03:31:13

Judging History

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

  • [2023-09-11 03:31:13]
  • 评测
  • 测评结果:TL
  • 用时:1982ms
  • 内存:10472kb
  • [2023-09-11 03:31:12]
  • 提交

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[50005],a[50005];
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: 5740kb

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

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

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:

92039

result:

ok answer is '92039'

Test #4:

score: 0
Accepted
time: 1024ms
memory: 7172kb

input:

5000 10
14 114 254 832 38 904 25 147 998 785
917 694 750 372 379 887 247 817 999 117
802 15 799 515 316 42 69 247 95 144
727 398 509 725 682 456 369 656 693 955
923 1 681 631 962 826 233 963 289 856
165 491 488 832 111 950 853 791 929 240
509 843 667 970 469 260 447 477 161 431
514 903 627 236 144 3...

output:

461878

result:

ok answer is '461878'

Test #5:

score: 0
Accepted
time: 1982ms
memory: 10472kb

input:

10000 10
307 205 765 487 504 526 10 581 234 583
448 443 39 992 976 363 335 588 588 169
920 787 896 822 47 358 230 631 136 299
141 159 414 852 922 945 513 76 111 189
616 104 83 792 24 68 164 975 615 472
150 108 848 517 7 153 107 283 452 165
94 370 910 662 226 720 975 214 324 407
636 65 963 859 590 3 ...

output:

919745

result:

ok answer is '919745'

Test #6:

score: -100
Time Limit Exceeded

input:

50000 10
819 49 278 985 747 872 146 129 898 569
929 427 54 846 136 475 448 304 591 428
238 844 664 991 990 863 308 571 867 958
775 690 792 697 557 325 824 654 303 833
542 942 262 534 501 575 273 60 701 488
733 855 810 405 294 909 638 975 801 836
382 265 818 765 240 69 980 889 472 211
629 434 128 389...

output:


result: