QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#650700#3688. 保护古迹Crying100 ✓1509ms4760kbC++142.4kb2024-10-18 16:11:332024-10-18 16:11:34

Judging History

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

  • [2024-10-18 16:11:34]
  • 评测
  • 测评结果:100
  • 用时:1509ms
  • 内存:4760kb
  • [2024-10-18 16:11:33]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef __int128 i128;
typedef array<int,3> tr;
const int N = 110,M = 10,E = 1e4+10,INF = 1e9;
template<typename T>void tomin(T& x,T y){x = min(x,y);}
template<typename T>void tomax(T& x,T y){x = max(x,y);}
//
int m,n,_;
ll xp[M],yp[M],x[N],y[N]; 
vector<tr> e[N];

int g[1<<M],dp[1<<M];

int dis[N][1<<M],vis[N][1<<M],ans[M+1];
priority_queue<tr> pq;

mt19937 rnd(0);
int gen(int L,int R){
    return rnd()%(R-L+1)+L;
}

int dx,dy;
void F(ll& x,ll& y){
    ll vx = x,vy = y;
    x = vx*dx - vy*dy;
    y = vx*dx + vy*dy;
}

int main(){
    cin>>m>>n>>_;
    dx = gen(-1e6,1e6),dy = gen(-1e6,1e6);
    for(int i=0;i<m;i++)cin>>xp[i]>>yp[i],F(xp[i],yp[i]);
    for(int i=1;i<=n;i++)cin>>x[i]>>y[i],F(x[i],y[i]);
    fill(ans+1,ans+1+m,INF);
    fill(g,g+(1<<m),INF);
    fill(dp,dp+(1<<m),INF);

    for(int i=1,u,v,w;i<=_;i++){
        cin>>u>>v>>w;
        if(x[u] > x[v])swap(u,v);
        if(x[u] == x[v])continue;
        int to = 0;
        for(int j=0;j<m;j++){
            if(xp[j] < x[u] || xp[j] >= x[v])continue;
            if(xp[j] == x[u]){
                to |= (yp[j] > y[u])<<j;
                continue;
            }
            if((i128)(yp[j]-y[u]) * (x[v]-xp[j]) > (i128)(y[v]-yp[j]) * (xp[j]-x[u]))to |= 1<<j;
        }
        END:;
        e[u].push_back({v,w,to});
        e[v].push_back({u,w,to});
    }

    for(int s=1;s<=n;s++){
        for(int x=1;x<=n;x++){
            fill(dis[x],dis[x]+(1<<m),INF);
            fill(vis[x],vis[x]+(1<<m),0);
        }
        dis[s][0] = 0; pq.push((tr){0,s,0});
        while(pq.size()){
            tr now = pq.top(); pq.pop();
            int x = now[1],S = now[2]; if(vis[x][S])continue;
            vis[x][S] = 1;
            for(auto [y,w,to] : e[x]){
                int T = S^to;
                if(dis[y][T] > dis[x][S] + w){
                    dis[y][T] = dis[x][S] + w;
                    pq.push((tr){-dis[y][T],y,T});
                }
            }
        }
        for(int S=0;S<(1<<m);S++)tomin(g[S],dis[s][S]);
    }
    dp[0] = 0;
    for(int S=0;S<(1<<m);S++){
        for(int T=S;T;T=(T-1)&S){
            tomin(dp[S],dp[S^T] + g[T]);
        }
        int pcnt = __builtin_popcount(S);
        tomin(ans[pcnt],dp[S]);
    }
    for(int i=m-1;i>=1;i--)tomin(ans[i],ans[i+1]);
    for(int i=1;i<=m;i++)cout<<ans[i]<<endl;

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Pretests


Final Tests

Test #1:

score: 10
Accepted
time: 1ms
memory: 3716kb

input:

4 15 22
5410 32461
699 10935
15358 4949
12312 12094
0 0
0 10000
0 20000
0 30000
0 40000
10000 0
10000 10000
10000 20000
10000 30000
10000 40000
20000 0
20000 10000
20000 20000
20000 30000
20000 40000
1 2 720544
2 3 179817
3 4 215720
4 5 235244
6 7 426732
7 8 207026
8 9 21868
9 10 826571
11 12 103524...

output:

1108166
2424550
3118664
4464984

result:

ok 4 lines

Test #2:

score: 10
Accepted
time: 0ms
memory: 3620kb

input:

3 10 22
-25280101 85991107
-59119079 -317316185
-51950462 253705554
482570262 68721196
917798869 17688203
-933908676 -792658862
-683380520 833213002
-354758856 621197152
565798328 947116192
205922084 507463940
33230777 497529860
-470395815 618808612
908214552 922759158
1 2 377709
1 3 280013
1 4 7966...

output:

709158
709158
898349

result:

ok 3 lines

Test #3:

score: 10
Accepted
time: 153ms
memory: 4096kb

input:

10 50 85
6231 50521
18991 63260
12698 66456
7058 29401
30009 51246
24884 32331
9039 34891
25937 86136
31898 5163
5366 16227
0 0
0 10000
0 20000
0 30000
0 40000
0 50000
0 60000
0 70000
0 80000
0 90000
10000 0
10000 10000
10000 20000
10000 30000
10000 40000
10000 50000
10000 60000
10000 70000
10000 80...

output:

1195466
2472681
4041884
5553478
7122681
8666334
9528483
10452063
11729278
12663325

result:

ok 10 lines

Test #4:

score: 10
Accepted
time: 7ms
memory: 3876kb

input:

6 40 105
-43998493 -436036827
42266136 -302164079
-459969674 -426951574
-57850252 491456513
-300067670 -449468937
407845350 -87254203
-590073551 -765801768
-323031631 -459979429
388485369 -692800539
574472085 -440723648
394731729 -726218141
-708920636 723910697
126266959 -638871607
543081775 -619566...

output:

595676
595676
595676
1343143
1798634
1798634

result:

ok 6 lines

Test #5:

score: 10
Accepted
time: 0ms
memory: 3892kb

input:

1 50 132
73401080 -25169890
-560703393 -184895786
396068526 -4572971
847090150 -873292316
-40926384 352176942
288306188 -758426272
-88062642 535380072
731819841 -988783143
-514912306 80443633
-627251280 945647541
469343638 504347298
448948816 880990438
-618349006 506948378
-240795856 -876097298
1364...

output:

1188428

result:

ok single line: '1188428'

Test #6:

score: 10
Accepted
time: 319ms
memory: 4496kb

input:

8 100 180
46503 33965
88693 58434
13385 27861
13842 36542
89436 2890
51603 38382
73263 74252
3143 50484
0 0
0 10000
0 20000
0 30000
0 40000
0 50000
0 60000
0 70000
0 80000
0 90000
10000 0
10000 10000
10000 20000
10000 30000
10000 40000
10000 50000
10000 60000
10000 70000
10000 80000
10000 90000
2000...

output:

1518993
1675123
3213020
3989964
5629988
8082966
10773790
13655905

result:

ok 8 lines

Test #7:

score: 10
Accepted
time: 1509ms
memory: 4760kb

input:

10 100 180
61685 11763
29335 7087
76804 63256
56878 74426
64052 87794
65602 39922
74651 70492
65932 67041
62951 53806
41446 30445
0 0
0 10000
0 20000
0 30000
0 40000
0 50000
0 60000
0 70000
0 80000
0 90000
10000 0
10000 10000
10000 20000
10000 30000
10000 40000
10000 50000
10000 60000
10000 70000
10...

output:

1159260
2525300
3651031
4810291
5507109
6666369
7470335
8052017
9051107
10446935

result:

ok 10 lines

Test #8:

score: 10
Accepted
time: 600ms
memory: 4448kb

input:

10 80 226
196367790 140261921
341578397 -37013302
-166020054 -18642252
136895226 -375338349
-340096454 -227228102
145704163 26479845
-147471081 490771160
236858347 -29152460
-482273822 -100763369
-423000398 -473229514
808334244 -934454693
-811284143 901898768
225270310 249442025
-271558930 -34874859...

output:

272501
511220
511220
511220
816883
816883
929648
1168367
1168367
1168367

result:

ok 10 lines

Test #9:

score: 10
Accepted
time: 3ms
memory: 4464kb

input:

1 100 285
-276557927 415053799
127903348 148709462
-651742339 -535769353
227438514 321297327
-10817819 -116024832
313798249 -919225767
411278249 -59214214
-7751042 -573007647
104308924 801152933
836228521 -550758059
440055127 564858024
16539940 -146758620
-380079678 -760000243
645835416 -797905099
1...

output:

653554

result:

ok single line: '653554'

Test #10:

score: 10
Accepted
time: 480ms
memory: 4464kb

input:

9 100 285
365159021 -110325337
-405181636 159440345
-418024453 479646955
-398796799 -54366098
-140891792 -343756137
-258166421 463546640
180226062 206955740
394226094 -18913993
155940975 338950781
956204538 -25235812
59550571 576742979
464839825 219048369
-511408953 -232751750
-472418988 543115091
7...

output:

304765
304765
388255
388255
682451
682451
686035
686035
1737758

result:

ok 9 lines