QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#544224#2772. PosterizeevirirAC ✓13ms5224kbC++202.8kb2024-09-02 13:12:182024-09-02 13:12:19

Judging History

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

  • [2024-09-02 13:12:19]
  • 评测
  • 测评结果:AC
  • 用时:13ms
  • 内存:5224kb
  • [2024-09-02 13:12:18]
  • 提交

answer

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2")
#define setp(x) cout<<fixed<<setprecision(x)
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define forn(i,a,b) for(int i=(a);i<(b);i++)
#define fore(i,a,b) for(int i=(a);i<=(b);i++)
#define pb push_back
#define F first
#define S second
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
//template<typename T>
//using pbds = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
void SD(int t=0){ cout<<"PASSED "<<t<<endl; }
template<typename T> void amax(T &a, T b){ a=max(a,b); }
template<typename T> void amin(T &a, T b){ a=min(a,b); }
struct Hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const ll INF = ll(1e18);
const int MOD = 998244353;
const bool DEBUG = 0;
const int MAXN = 100005;
const int LG = 21;
const int MAXA = 256;

ll sq(ll x) { return x * x; }

int main()
{
    cin.tie(0)->sync_with_stdio(0);

    ll n,K; cin>>n>>K;
    ll cnt[MAXA + 1]{};
    forn(i,0,n)
    {
        ll r,c; cin>>r>>c; r++;
        cnt[r] += c;
    }

    ll cost[MAXA + 1][MAXA + 1]{};
    fore(i,0,MAXA)
    {
        ll sum = 0;
        fore(j, i + 1, MAXA)
        {
            sum += cnt[j] * sq(j - i);
            cost[i][j] = sum;
        }
        sum = 0;
        for (int j = i - 1; j >= 0; j--)
        {
            sum += cnt[j] * sq(j - i);
            cost[i][j] = sum;
        }
    }

    ll cost2[MAXA + 1][MAXA + 1]{};
    fore(i,0,MAXA) cost2[0][i] = cost[i][0];
    fore(k,1,MAXA) fore(i,k+1,MAXA)
    {
        ll minc = INF;
        for (int l = k; l <= i; l++)
        {
            minc = min(minc, cost[k][l] + cost[i][l + 1]);
        }
        cost2[k][i] = minc;
    }

    ll dp[MAXA + 1][K + 1];
    fore(i,0,MAXA) fore(j,0,K) dp[i][j] = INF;
    dp[0][0] = 0;
    fore(i,0,MAXA) fore(j,1,K)
    {
        ll& cur = dp[i][j];
        forn(k,0,i)
        {
            cur = min(cur, dp[k][j - 1] + cost2[k][i]);
        }
    }
    ll ans = INF;
    fore(i,0,MAXA)
    {
        amin(ans, dp[i][K] + cost[i][MAXA]);
    }
    cout << ans << '\n';

    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 4672kb

input:

2 1
50 20000
150 10000

output:

66670000

result:

ok single line: '66670000'

Test #2:

score: 0
Accepted
time: 3ms
memory: 4756kb

input:

2 2
50 20000
150 10000

output:

0

result:

ok single line: '0'

Test #3:

score: 0
Accepted
time: 3ms
memory: 4756kb

input:

4 2
0 30000
25 30000
50 30000
255 30000

output:

37500000

result:

ok single line: '37500000'

Test #4:

score: 0
Accepted
time: 3ms
memory: 4628kb

input:

1 1
163 1678444

output:

0

result:

ok single line: '0'

Test #5:

score: 0
Accepted
time: 0ms
memory: 4624kb

input:

2 1
57 49423747
70 45412534

output:

4004469058

result:

ok single line: '4004469058'

Test #6:

score: 0
Accepted
time: 3ms
memory: 4756kb

input:

3 1
22 1999658
108 14672547
228 33913820

output:

202829097745

result:

ok single line: '202829097745'

Test #7:

score: 0
Accepted
time: 0ms
memory: 4680kb

input:

1 1
6 13343769

output:

0

result:

ok single line: '0'

Test #8:

score: 0
Accepted
time: 3ms
memory: 4704kb

input:

2 2
139 14793520
166 39544951

output:

0

result:

ok single line: '0'

Test #9:

score: 0
Accepted
time: 3ms
memory: 4704kb

input:

5 5
1 10434053
87 64237482
178 22588478
206 6224069
207 6490527

output:

0

result:

ok single line: '0'

Test #10:

score: 0
Accepted
time: 3ms
memory: 4692kb

input:

43 7
7 21117676
11 43985745
19 26550408
24 61374250
37 30793027
39 17775808
45 16550892
49 37672778
50 17632291
55 39230902
56 60251874
58 26803315
62 14718367
66 66943616
68 34193731
70 6100828
86 3161927
87 7358429
95 42107192
124 53155547
136 28330676
138 4263273
140 25610037
142 66848575
143 355...

output:

97351261669

result:

ok single line: '97351261669'

Test #11:

score: 0
Accepted
time: 3ms
memory: 4628kb

input:

18 7
0 51043148
4 51394279
14 8616206
17 31895661
21 36896695
39 17787650
78 58547991
82 28396307
124 14213537
135 36191548
138 48984845
155 13499020
195 20918927
199 66783343
212 43612579
224 29400399
237 34733927
242 8120455

output:

17170390905

result:

ok single line: '17170390905'

Test #12:

score: 0
Accepted
time: 0ms
memory: 4764kb

input:

15 4
18 54190207
33 12778194
54 6504917
56 28927356
58 28425881
60 31341495
121 48927453
146 45188730
150 66046210
161 6604712
171 27019457
200 22770213
220 57825866
231 16687045
239 12764704

output:

68242717776

result:

ok single line: '68242717776'

Test #13:

score: 0
Accepted
time: 3ms
memory: 4628kb

input:

25 5
12 37296981
14 48211564
40 10388240
51 19911726
62 65008986
63 38868132
71 36386105
90 50195791
96 3836297
98 39203495
106 33745718
112 57225064
118 10565132
138 64476781
185 5376190
207 12470503
217 39932131
223 45312748
227 15784267
230 8045455
234 59746171
239 16523233
247 39897506
248 41565...

output:

90917093574

result:

ok single line: '90917093574'

Test #14:

score: 0
Accepted
time: 0ms
memory: 4756kb

input:

31 6
1 9012125
17 7746287
37 7183063
51 37126211
52 18276980
60 40589443
63 48158139
68 13663185
74 42562989
78 17715660
87 32784818
99 60756104
112 56781060
142 6194046
150 28425689
151 18567696
164 237948
168 51748936
181 42755955
186 17579521
187 49743165
195 37022647
209 28701584
210 648923
212 ...

output:

82719881164

result:

ok single line: '82719881164'

Test #15:

score: 0
Accepted
time: 3ms
memory: 4628kb

input:

10 4
26 10371899
53 62403259
63 58022707
104 65512078
158 54409970
199 59150841
203 1663385
220 49430005
226 22292590
230 62465997

output:

44984052615

result:

ok single line: '44984052615'

Test #16:

score: 0
Accepted
time: 0ms
memory: 4776kb

input:

41 9
0 48280130
5 49791427
24 45005118
26 24442490
27 4695863
41 44576237
46 22159350
55 21066523
56 56909343
60 48301891
66 20154287
68 20755743
70 27406785
75 27004633
79 19841085
85 8542140
94 28215676
98 63106738
114 45454038
116 60586255
126 41306507
127 20196405
135 36771444
152 27243
155 1925...

output:

56742245774

result:

ok single line: '56742245774'

Test #17:

score: 0
Accepted
time: 3ms
memory: 4632kb

input:

35 3
1 36767065
6 60210617
11 49905872
18 31854863
25 17394051
41 16591978
48 42792735
50 51392887
58 34983839
59 42060376
62 18427923
101 5199820
103 19174892
105 18234493
112 21455346
120 36249003
121 9286127
122 15519696
135 46570184
137 47406987
153 4310326
156 27353531
160 36414018
161 27902137...

output:

483242929010

result:

ok single line: '483242929010'

Test #18:

score: 0
Accepted
time: 3ms
memory: 4772kb

input:

44 10
4 8470547
6 44926623
7 37847358
11 14627353
18 46940300
31 51465661
32 11260139
40 40751690
42 50192441
49 7686171
55 54982372
57 64741316
75 7254385
77 1723250
83 20935097
86 45456007
88 64301891
94 26619029
99 47983825
107 5100038
108 46346349
114 42093525
120 6838481
134 51840315
138 570622...

output:

50618810623

result:

ok single line: '50618810623'

Test #19:

score: 0
Accepted
time: 3ms
memory: 4644kb

input:

17 9
7 53541624
22 22839754
46 59077274
54 47055645
62 18540071
68 681230
97 63623403
111 5745389
118 48323393
123 32787905
137 50879569
156 46346009
187 43345810
212 32938463
217 53212825
218 6244705
225 14871083

output:

7062747077

result:

ok single line: '7062747077'

Test #20:

score: 0
Accepted
time: 3ms
memory: 4712kb

input:

256 1
0 67108864
1 67108864
2 67108864
3 67108864
4 67108864
5 67108864
6 67108864
7 67108864
8 67108864
9 67108864
10 67108864
11 67108864
12 67108864
13 67108864
14 67108864
15 67108864
16 67108864
17 67108864
18 67108864
19 67108864
20 67108864
21 67108864
22 67108864
23 67108864
24 67108864
25 6...

output:

93827855548416

result:

ok single line: '93827855548416'

Test #21:

score: 0
Accepted
time: 7ms
memory: 5000kb

input:

256 128
0 1
1 1
2 1
3 1
4 1
5 1
6 1
7 1
8 1
9 1
10 1
11 1
12 1
13 1
14 1
15 1
16 1
17 1
18 1
19 1
20 1
21 1
22 1
23 1
24 1
25 1
26 1
27 1
28 1
29 1
30 1
31 1
32 1
33 1
34 1
35 1
36 1
37 1
38 1
39 1
40 1
41 1
42 1
43 1
44 1
45 1
46 1
47 1
48 1
49 1
50 1
51 1
52 1
53 1
54 1
55 1
56 1
57 1
58 1
59 1
60...

output:

128

result:

ok single line: '128'

Test #22:

score: 0
Accepted
time: 3ms
memory: 4672kb

input:

64 2
3 40911638
11 49666553
15 63591702
23 13944411
24 14161662
28 44320583
29 10539924
31 11664430
40 5037519
41 179565
44 30232792
45 39849995
47 19546081
51 15534108
52 47443003
59 47176697
62 30469527
66 46129622
67 62002621
78 52870244
82 41946933
84 44371243
87 62657430
89 28530594
96 36544963...

output:

2624226537526

result:

ok single line: '2624226537526'

Test #23:

score: 0
Accepted
time: 3ms
memory: 4712kb

input:

64 3
20 32859208
25 9972070
27 36143531
35 23160876
44 37038551
47 36468975
50 30557660
53 21594113
55 12660247
57 46808328
58 38372691
72 15674111
77 52045909
79 2929121
82 49976317
83 47327042
85 54452730
98 25909307
100 44539404
104 55079436
107 65821592
108 33240943
112 2484345
113 33708189
114 ...

output:

1288496221990

result:

ok single line: '1288496221990'

Test #24:

score: 0
Accepted
time: 3ms
memory: 4712kb

input:

64 5
2 8869094
10 36199042
17 65195563
19 35624900
33 61303074
35 55732075
37 17244971
43 55343997
46 32336261
54 54122527
57 50100750
58 22730796
59 7728909
60 64618676
61 9446044
62 64860732
66 57723059
73 48601361
81 65762811
87 64912374
88 53994963
99 24546749
105 53061769
106 934066
110 3600875...

output:

445587237443

result:

ok single line: '445587237443'

Test #25:

score: 0
Accepted
time: 3ms
memory: 4652kb

input:

64 12
0 5421758
3 40822150
5 4407861
8 18456012
11 42485060
12 36799578
14 21822826
16 66748339
22 35605067
25 30448327
29 40629505
30 6655754
32 47095620
33 57229952
37 43682278
38 51604216
47 48374748
48 14429954
50 30303338
51 15333945
56 22745316
58 30433797
70 27916593
75 6381103
79 28639648
89...

output:

43911767515

result:

ok single line: '43911767515'

Test #26:

score: 0
Accepted
time: 4ms
memory: 4684kb

input:

64 31
1 28030968
3 7729155
7 1399660
8 21794824
9 53775820
12 41481685
14 55836314
19 61724704
25 5914297
29 56672387
34 16328693
36 39518484
44 35162532
45 26559454
52 20822174
53 22784351
61 22351857
62 11283196
64 34257954
68 7652199
77 34222304
78 60795446
81 23446178
85 48813586
88 54958711
95 ...

output:

2651573425

result:

ok single line: '2651573425'

Test #27:

score: 0
Accepted
time: 4ms
memory: 4776kb

input:

64 47
15 56043943
19 59302907
21 2533192
25 22599875
27 51426033
31 8794553
36 25281243
38 10888227
42 55790623
43 51747499
44 54294005
60 11109146
65 29371766
66 27572255
67 45389948
73 15940382
74 29809671
77 19121190
79 50233436
80 30127046
81 35836882
85 20768039
86 54265830
89 31475105
96 56043...

output:

435408359

result:

ok single line: '435408359'

Test #28:

score: 0
Accepted
time: 3ms
memory: 4712kb

input:

128 3
1 63674470
3 24965396
4 51209733
6 38515239
7 35531452
8 26711613
9 43591284
10 16751155
11 7613408
12 49370305
15 33490274
19 25970284
22 37693218
26 17567536
27 17467751
33 29948882
34 66864931
35 19164740
37 61503859
40 32963888
46 8230059
48 57232204
50 30336072
51 60309329
52 29870907
53 ...

output:

2662445242586

result:

ok single line: '2662445242586'

Test #29:

score: 0
Accepted
time: 3ms
memory: 4704kb

input:

128 5
3 13910178
4 47310962
5 21276245
9 23407785
11 62659572
16 53378750
17 18351425
20 8178833
23 45407351
24 25480846
25 65777461
27 54920382
28 64062717
29 53996855
30 19491948
31 19302546
33 47925211
37 23244062
38 29687359
39 17209664
41 32150466
43 13560555
45 36143353
48 62614177
49 46719266...

output:

902640187420

result:

ok single line: '902640187420'

Test #30:

score: 0
Accepted
time: 3ms
memory: 4712kb

input:

128 14
0 64947032
2 37398882
4 8998813
5 16297960
6 13645698
8 43399696
9 61889547
10 56850160
13 6205154
14 48626057
15 12783006
17 18016153
19 45209358
20 40461414
21 58627677
22 12627425
27 51116582
33 48607302
35 37503821
36 32171601
39 58349403
43 22344857
44 64224509
45 1029028
46 62891728
47 ...

output:

89413182689

result:

ok single line: '89413182689'

Test #31:

score: 0
Accepted
time: 2ms
memory: 4788kb

input:

128 24
0 7642883
4 37839368
6 39743684
7 36616549
10 45748961
11 36916530
12 63955057
14 30978943
16 47537709
17 29424214
18 19550907
19 46495389
20 54959849
23 53395627
24 27457028
28 33507672
30 42502463
31 16241766
32 44202124
34 47998702
37 52954046
38 4963717
39 66484793
40 32160897
43 26897575...

output:

26309188339

result:

ok single line: '26309188339'

Test #32:

score: 0
Accepted
time: 0ms
memory: 4760kb

input:

128 37
0 57556025
2 29614199
6 45361
7 64292424
8 13577345
9 46210619
11 8852538
13 43620574
14 10668797
16 62594153
17 18389135
19 43928655
21 16803341
22 24954013
25 60653010
27 11108201
30 26598033
31 20502379
32 46938716
33 15713128
34 43988870
37 47224377
38 72901
39 31997957
42 8905333
43 1517...

output:

7511588435

result:

ok single line: '7511588435'

Test #33:

score: 0
Accepted
time: 7ms
memory: 4824kb

input:

128 103
0 64735541
1 13934232
7 20690181
9 17784381
10 8047263
11 10577389
12 46040362
13 55457872
14 46766690
15 2706488
17 56097961
20 21997861
21 6121195
23 16657681
27 23873493
30 34457696
32 45445008
34 17459498
35 66483183
36 2085884
37 27138303
38 30346707
39 50202695
40 16767327
41 31007198
...

output:

168966477

result:

ok single line: '168966477'

Test #34:

score: 0
Accepted
time: 3ms
memory: 4632kb

input:

256 5
0 2051062
1 24995822
2 39865591
3 11917440
4 58416976
5 39384867
6 23471990
7 10973213
8 60028337
9 50261931
10 46227978
11 19130683
12 25941984
13 10932531
14 38403589
15 64754525
16 57519759
17 43444930
18 45479359
19 18057894
20 27481563
21 1345691
22 52365293
23 51510934
24 597134
25 61170...

output:

1733352339080

result:

ok single line: '1733352339080'

Test #35:

score: 0
Accepted
time: 3ms
memory: 4724kb

input:

256 15
0 12339247
1 4575246
2 33899396
3 27912674
4 36039873
5 6170362
6 14844352
7 14317932
8 22272326
9 24212733
10 14659615
11 50509869
12 35601179
13 66882780
14 55276793
15 65842735
16 590807
17 44891701
18 29908223
19 60699730
20 41184784
21 41683443
22 64350477
23 45805247
24 21537719
25 6146...

output:

186169557674

result:

ok single line: '186169557674'

Test #36:

score: 0
Accepted
time: 4ms
memory: 4816kb

input:

256 30
0 14143354
1 38990802
2 21839654
3 41122842
4 17428224
5 36813467
6 15914140
7 31631452
8 41143374
9 24556755
10 33471890
11 14128596
12 47024029
13 24985277
14 57332854
15 18765621
16 12072162
17 8800601
18 38647507
19 15338855
20 6702145
21 18115978
22 15824618
23 29005710
24 25560652
25 97...

output:

41831586732

result:

ok single line: '41831586732'

Test #37:

score: 0
Accepted
time: 5ms
memory: 4788kb

input:

256 53
0 44528634
1 2918029
2 11429959
3 19059827
4 52961544
5 41470915
6 3562491
7 43940057
8 559298
9 26081535
10 18207332
11 57182319
12 44298587
13 58001002
14 1280325
15 58210930
16 43581245
17 15513464
18 25548426
19 65539318
20 6684292
21 21169892
22 58168135
23 35672432
24 12510260
25 335981...

output:

14249056387

result:

ok single line: '14249056387'

Test #38:

score: 0
Accepted
time: 3ms
memory: 4868kb

input:

256 83
0 45735818
1 21246514
2 38270602
3 61284101
4 20438014
5 63306026
6 29174038
7 65939848
8 23103208
9 5991977
10 544874
11 66197637
12 27125230
13 8560118
14 19742399
15 24778129
16 36835058
17 3565314
18 47201297
19 55079821
20 24108500
21 57797365
22 58094778
23 15786768
24 47125313
25 26458...

output:

5109272073

result:

ok single line: '5109272073'

Test #39:

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

input:

256 202
0 42506910
1 57739303
2 4744503
3 59957371
4 22340953
5 2195412
6 28581817
7 18105259
8 63491394
9 36402204
10 53316567
11 52861105
12 5433070
13 59112659
14 49376071
15 3678350
16 63439501
17 45275195
18 59591189
19 7446839
20 24534388
21 41549343
22 24533065
23 11761997
24 37499793
25 4496...

output:

382458273

result:

ok single line: '382458273'

Test #40:

score: 0
Accepted
time: 13ms
memory: 5224kb

input:

256 255
0 25349541
1 26192643
2 38422419
3 54245878
4 6714691
5 45305953
6 22546395
7 33740225
8 51331832
9 22786106
10 41260401
11 24382953
12 29258870
13 33349865
14 56863629
15 52824717
16 56396980
17 35959213
18 19284106
19 3189776
20 66855709
21 26979599
22 15158952
23 49854372
24 6171186
25 56...

output:

1248448

result:

ok single line: '1248448'

Test #41:

score: 0
Accepted
time: 12ms
memory: 5196kb

input:

256 256
0 31641105
1 57699963
2 39273871
3 13511593
4 38213832
5 55957957
6 3417330
7 528435
8 42306091
9 47854849
10 65732256
11 56949674
12 49464489
13 39986116
14 37198747
15 19513549
16 32715338
17 32621684
18 39663975
19 41036755
20 45544633
21 54807087
22 32742516
23 47935213
24 35454205
25 28...

output:

0

result:

ok single line: '0'