QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#124547 | #362. Sparklers | Adam_GS# | 20 | 1ms | 3840kb | C++17 | 1.7kb | 2023-07-15 05:23:42 | 2024-07-04 00:41:00 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const ld EPS=1e-15;
const ll INF=1e9+7;
const int LIM=1e5+7;
ll T[LIM], n, k, t;
bool check(ll s) {
vector<__int128_t>A, B;
A.pb(t*2*s);
for(int i=k; i<n-1; ++i) {
A.pb(-T[i]);
A.pb(t*2*s);
}
for(int i=k-1; i>=0; --i) {
B.pb(-T[i]);
B.pb(t*2*s);
}
int la=0, lb=0, akta=0, aktb=0;
__int128_t sum=0, suma=0, sumb=0;
bool ok[A.size()+1][B.size()+1];
rep(i, A.size()+1) rep(j, B.size()+1) ok[i][j]=false;
ok[0][0]=true;
rep(i, A.size()+1) rep(j, B.size()+1) {
__int128_t su=0;
rep(a, i) su+=A[a];
rep(a, j) su+=B[a];
if(su<0) continue;
if(i && ok[i-1][j]) ok[i][j]=true;
if(j && ok[i][j-1]) ok[i][j]=true;
}
return ok[A.size()][B.size()];
/*while(la<A.size() || lb<B.size()) {
bool ok=false;
while(akta<A.size() && suma+A[akta]+sum>=0) {
ok=true;
suma+=A[akta];
if(suma>=0) {
sum+=suma;
suma=0;
la=akta+1;
}
++akta;
}
while(aktb<B.size() && sumb+B[aktb]+sum>=0) {
ok=true;
sumb+=B[aktb];
if(sumb>=0) {
sum+=sumb;
sumb=0;
lb=aktb+1;
}
++aktb;
}
if(!ok) break;
}
if(akta<A.size() || aktb<B.size()) return false;
return suma+sumb+sum>=0;*/
}
ll solve(vector<ll>P) {
rep(i, n-1) T[i]=P[i+1]-P[i];
ll po=0, ko=INF;
while(po<ko) {
ll sr=(po+ko)/2;
if(check(sr)) ko=sr; else po=sr+1;
}
return po;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> k >> t; --k;
vector<ll>P(n);
rep(i, n) cin >> P[i];
cout << solve(P) << '\n';
}
詳細信息
Subtask #1:
score: 20
Accepted
Test #1:
score: 20
Accepted
time: 0ms
memory: 3596kb
input:
10 9 2 0 1117660 2284171 3390084 3568342 4222750 5180454 6186411 6360445 6519656
output:
181102
result:
ok single line: '181102'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3540kb
input:
3 2 1 0 368765 1493921
output:
373481
result:
ok single line: '373481'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
9 8 4 0 1970871 2488111 3723411 5581758 7596649 8984403 9989980 10451978
output:
168215
result:
ok single line: '168215'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3600kb
input:
20 18 1 0 462590 635597 1653028 1731039 2632280 2993419 3958675 4824859 4923991 5874922 6721441 7856685 8109245 8187843 8916119 9662776 10617094 11598860 11759660
output:
477159
result:
ok single line: '477159'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3840kb
input:
20 19 1 0 16714 600564 1738550 2860146 3233681 3470376 3511936 4127893 5089595 5771375 5923055 6712524 7645593 7839588 7939256 8270988 8365309 8565641 8764207
output:
242986
result:
ok single line: '242986'
Test #6:
score: 0
Accepted
time: 1ms
memory: 3640kb
input:
20 19 1 0 360130 416278 565928 1137578 1907790 2582414 3700996 4219574 4315031 4708493 5703532 6750886 7008779 7292334 7354499 8425871 8951795 9692673 9903623
output:
318641
result:
ok single line: '318641'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3804kb
input:
20 3 1 0 497352 601758 1175884 1245741 1585758 1746236 2367513 2732420 2739779 3351827 3525038 4143423 4321819 5000239 5107430 5312137 5958753 6370846 6513352
output:
173188
result:
ok single line: '173188'
Test #8:
score: 0
Accepted
time: 1ms
memory: 3608kb
input:
20 7 1 0 416112 1276119 1776741 1971354 3051516 3964787 4752968 5114629 5456785 5783476 6450733 7492246 8117636 8726706 9380206 9424138 9680412 10381694 11143315
output:
394091
result:
ok single line: '394091'
Test #9:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
20 17 1 0 418275 1609767 2826602 4126911 5045015 5863900 5903447 6048863 6976925 7826789 8397913 8479522 9312544 9618482 9751692 10846799 12065875 12985857 14274374
output:
547554
result:
ok single line: '547554'
Test #10:
score: 0
Accepted
time: 0ms
memory: 3536kb
input:
20 5 1 0 636862 675532 1067405 2149723 2433765 3448119 4927611 5075453 6024114 6742671 7335495 8053680 9461089 10479891 11154362 11537902 11790723 12326305 13349359
output:
374282
result:
ok single line: '374282'
Test #11:
score: 0
Accepted
time: 1ms
memory: 3612kb
input:
20 9 1 0 253324 316843 568058 673961 952771 1319011 1398887 1748830 1895752 2246598 2269716 2344119 2451418 2690003 2985338 3065614 3143399 3495892 3568533
output:
124217
result:
ok single line: '124217'
Test #12:
score: 0
Accepted
time: 0ms
memory: 3540kb
input:
20 11 1 0 51952 61227 162819 249127 306399 334761 382780 449122 509397 542856 610609 616723 637063 646745 686393 770737 862074 908186 946759
output:
25317
result:
ok single line: '25317'
Test #13:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
20 20 1 0 560429 1501879 2074034 3034586 3927746 4203223 4704487 5719669 6398636 6727143 7650938 8442426 9196467 9374450 9518016 10137750 10914536 11539863 12123154
output:
330901
result:
ok single line: '330901'
Test #14:
score: 0
Accepted
time: 1ms
memory: 3840kb
input:
20 18 1 0 238996 608018 1366723 1785069 2539784 3289307 3602420 4757227 5445099 5644989 6150519 7171436 7964903 9199069 9472670 10160202 11298237 11504431 12150241
output:
374983
result:
ok single line: '374983'
Test #15:
score: 0
Accepted
time: 1ms
memory: 3556kb
input:
20 16 1 0 260310 303643 510297 1043552 1456874 1889988 2034528 2320694 2791007 3106279 3221006 3686585 4034261 4101785 4113243 4346119 4405697 4733785 5087878
output:
139122
result:
ok single line: '139122'
Test #16:
score: 0
Accepted
time: 1ms
memory: 3596kb
input:
20 8 1 0 484204 551742 1091736 1375852 1491742 1695121 2025199 2649991 2689456 3395295 4015308 4099000 4429963 4591520 5011483 5300133 5567208 6302488 6642143
output:
176556
result:
ok single line: '176556'
Test #17:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
20 6 1 0 62927 133948 189568 367293 532858 671097 693145 766893 880530 939114 944530 1061492 1137014 1312489 1390117 1549261 1657553 1800303 1929758
output:
69120
result:
ok single line: '69120'
Test #18:
score: 0
Accepted
time: 1ms
memory: 3544kb
input:
20 14 1 0 223799 635453 1081261 1241909 1496302 1622006 1780758 1882704 2140804 2503655 2564678 2565246 3012521 3485082 3933129 3986311 4363178 4395662 4701534
output:
223638
result:
ok single line: '223638'
Test #19:
score: 0
Accepted
time: 0ms
memory: 3568kb
input:
20 5 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
output:
0
result:
ok single line: '0'
Test #20:
score: 0
Accepted
time: 0ms
memory: 3472kb
input:
2 1 1 0 1000000000
output:
500000000
result:
ok single line: '500000000'
Test #21:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
1 1 1 0
output:
0
result:
ok single line: '0'
Subtask #2:
score: 0
Time Limit Exceeded
Dependency #1:
100%
Accepted
Test #22:
score: 0
Time Limit Exceeded
input:
732 262 7 0 629941 1835167 3075849 3632747 5477365 7690179 11300419 14778007 18359892 20279775 21163002 22029502 23636159 23778620 24102872 27453702 30784655 35027716 36072504 36591660 41988236 46473109 48716186 49542064 50631925 51952471 57334048 61174375 62942938 67795840 70872460 71304388 7568304...
output:
result:
Subtask #3:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%