QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#553914 | #362. Sparklers | makrav | 50 | 61ms | 3972kb | C++20 | 2.7kb | 2024-09-08 22:53:52 | 2024-09-08 22:53:52 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define pb push_back
#define ff first
#define sc second
#define int __int128
void solve() {
ll n, k, t; cin >> n >> k >> t;
k--;
vector<ll> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
int L = -1, R = 1e9;
while (R - L > 1) {
int M = (L + R) / 2;
vector<int> x(n);
for (int i = 0; i < n; i++) {
x[i] = a[i] - 2 * M * i * t;
}
vector<vector<bool>> dp(n, vector<bool>(n));
dp[k][k] = 1;
for (int len = 2; len <= n; len++) {
for (int i = 0; i + len - 1 < n; i++) {
dp[i][i + len - 1] = (dp[i][i + len - 2] && x[i] >= x[i + len - 1]) | (dp[i + 1][i + len - 1] && x[i] >= x[i + len - 1]);
}
}
if (dp[0][n - 1]) R = M;
else L = M;
continue;
int psl = k, psr = k;
for (int i = k - 1; i >= 0; i--) {
if (x[i] > x[psl]) psl = i;
}
for (int i = k + 1; i < n; i++) {
if (x[i] < x[psr]) psr = i;
}
if (x[psl] < x[psr] || x[0] < x[n - 1]) {
L = M;
continue;
}
int curl = k, curr = k;
bool good = true;
while (curl != psl) {
int mnl = x[curl], j = curl;
for (; x[j] <= x[curl]; j--) {
mnl = min(mnl, x[j]);
}
while (curr < n && x[curl] >= x[curr]) {
if (x[curr] <= mnl) break;
curr++;
}
if (curr >= n || x[curr] > x[curl]) {
good = false;
break;
}
curl = j;
}
if (!good) {
L = M;
continue;
}
curl = 0;
curr = n - 1;
while (curl < psl) {
int mnl = x[curl], j = curl + 1;
for (; x[j] < x[curl]; j++) {
mnl = min(mnl, x[j]);
}
while (curr >= 0 && x[curl] >= x[curr]) {
if (x[curr] <= mnl) break;
curr--;
}
if (curr < 0 || x[curr] > x[curl]) {
good = false; break;
}
curl = j;
}
if (good) R = M;
else L = M;
}
cout << (ll) R << '\n';
}
signed main() {
ll tt = 1;
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
cin >> tt;
#else
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
#endif
while (tt--) {
solve();
}
return 0;
}
详细
Subtask #1:
score: 20
Accepted
Test #1:
score: 20
Accepted
time: 0ms
memory: 3748kb
input:
10 9 2 0 1117660 2284171 3390084 3568342 4222750 5180454 6186411 6360445 6519656
output:
181102
result:
ok single line: '181102'
Test #2:
score: 20
Accepted
time: 0ms
memory: 3776kb
input:
3 2 1 0 368765 1493921
output:
373481
result:
ok single line: '373481'
Test #3:
score: 20
Accepted
time: 0ms
memory: 3596kb
input:
9 8 4 0 1970871 2488111 3723411 5581758 7596649 8984403 9989980 10451978
output:
168215
result:
ok single line: '168215'
Test #4:
score: 20
Accepted
time: 0ms
memory: 3592kb
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: 20
Accepted
time: 0ms
memory: 3536kb
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: 20
Accepted
time: 0ms
memory: 3808kb
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: 20
Accepted
time: 0ms
memory: 3608kb
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: 20
Accepted
time: 0ms
memory: 3540kb
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: 20
Accepted
time: 0ms
memory: 3608kb
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: 20
Accepted
time: 0ms
memory: 3520kb
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: 20
Accepted
time: 0ms
memory: 3608kb
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: 20
Accepted
time: 0ms
memory: 3612kb
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: 20
Accepted
time: 0ms
memory: 3600kb
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: 20
Accepted
time: 0ms
memory: 3808kb
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: 20
Accepted
time: 0ms
memory: 3820kb
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: 20
Accepted
time: 0ms
memory: 3528kb
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: 20
Accepted
time: 0ms
memory: 3528kb
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: 20
Accepted
time: 0ms
memory: 3604kb
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: 20
Accepted
time: 0ms
memory: 3584kb
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: 20
Accepted
time: 0ms
memory: 3604kb
input:
2 1 1 0 1000000000
output:
500000000
result:
ok single line: '500000000'
Test #21:
score: 20
Accepted
time: 0ms
memory: 3596kb
input:
1 1 1 0
output:
0
result:
ok single line: '0'
Subtask #2:
score: 30
Accepted
Dependency #1:
100%
Accepted
Test #22:
score: 30
Accepted
time: 32ms
memory: 3908kb
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:
211260
result:
ok single line: '211260'
Test #23:
score: 30
Accepted
time: 21ms
memory: 3600kb
input:
568 176 10 0 4822188 12835213 21145111 24069578 25428693 37689591 44528013 53494376 62691761 74853861 87803170 99563518 103793768 116721590 124706385 130511788 140228697 151031085 156719085 163061026 163972683 168129081 176494838 179979518 193257722 204266763 207017659 212179406 223965988 232681126 ...
output:
88184
result:
ok single line: '88184'
Test #24:
score: 30
Accepted
time: 27ms
memory: 3736kb
input:
729 47 4 0 533644 614452 918872 1066928 1633243 2052575 2487683 2677252 2956221 3502185 4032500 4606055 4794447 5434290 5685999 5741100 6004356 6550878 6840957 7439030 7730019 8034922 8440581 8528403 9017686 9170499 9576985 9721356 10115002 10425275 10673108 11300867 11667482 12163892 12313691 12846...
output:
59242
result:
ok single line: '59242'
Test #25:
score: 30
Accepted
time: 57ms
memory: 3720kb
input:
1000 16 1 0 300418 720839 1101334 1270642 1358485 1699613 2031751 2076100 2078250 2167047 2223905 2537060 2672439 2879343 3014590 3445224 3884089 4118024 4432980 4484003 4777108 5200064 5540984 5890142 6227183 6625240 6942951 7338632 7348721 7383868 7709001 7793033 7912649 8267321 8447335 8873296 89...
output:
124746
result:
ok single line: '124746'
Test #26:
score: 30
Accepted
time: 58ms
memory: 3972kb
input:
1000 134 1 0 157000 165508 193836 347260 355223 653813 723441 766606 877569 1153254 1380323 1690537 1975409 2111433 2376749 2665106 2914807 3080873 3485222 3755909 3805411 4001843 4137840 4494580 4805592 5039944 5276573 5561247 5690839 6040123 6111803 6184345 6565504 6885171 6988886 7160962 7455902 ...
output:
102156
result:
ok single line: '102156'
Test #27:
score: 30
Accepted
time: 58ms
memory: 3968kb
input:
1000 167 1 0 337310 734264 1228171 1775353 1937515 1966717 2134352 2626557 3090581 3311943 3632694 3760763 4140320 4492696 5133898 5367854 5677466 5879158 6422820 6961196 7515753 8203291 8286108 8479558 8486789 8700986 9096429 9530532 9724870 10239491 10937150 11172992 11835729 12509154 13162049 137...
output:
184550
result:
ok single line: '184550'
Test #28:
score: 30
Accepted
time: 56ms
memory: 3780kb
input:
1000 583 1 0 1155216 2243968 3441256 5297971 6209914 7762324 9015919 9734409 10298287 12090390 13680839 15187680 16616775 17433179 18990924 19345637 20328209 21047781 22310574 23253675 24084243 25052744 26433441 26505138 26771451 27773965 28197193 29214668 29604538 31446792 31634297 33050511 3342317...
output:
507288
result:
ok single line: '507288'
Test #29:
score: 30
Accepted
time: 59ms
memory: 3972kb
input:
1000 648 1 0 149277 558491 833172 1061298 1159483 1289104 1512423 1829467 1932459 2206872 2427755 2682759 2982638 3167870 3203058 3379660 3581887 3642593 4001751 4241647 4652799 4829201 5197712 5208113 5569955 5587313 5858867 6044105 6335886 6640171 6724803 6804688 7017976 7450352 7879658 8063683 84...
output:
135848
result:
ok single line: '135848'
Test #30:
score: 30
Accepted
time: 58ms
memory: 3808kb
input:
1000 795 1 0 686899 726596 1248874 1493856 3062405 3640995 4212376 5570483 6826974 7121530 7833336 7901177 9464878 10585555 11892848 12528701 13269468 14456032 15998686 16803364 17796407 17884537 18272340 18495999 19828084 21233255 22510945 23456317 23827759 25261874 25370977 25481392 26520168 27639...
output:
470218
result:
ok single line: '470218'
Test #31:
score: 30
Accepted
time: 60ms
memory: 3784kb
input:
1000 759 1 0 292968 1286267 2746799 3008098 3957531 4083400 4553850 4986193 5454234 6032115 7233640 8832257 9344907 10846015 12427055 13269890 13699022 14707280 16218583 17252404 17774007 18676352 19819174 19838334 20655789 21327375 21561066 21565972 22261363 23332536 23645399 25210904 26335730 2763...
output:
554416
result:
ok single line: '554416'
Test #32:
score: 30
Accepted
time: 61ms
memory: 3784kb
input:
1000 458 1 0 504827 848739 1086846 1573082 1728990 1823619 2014935 2220271 2557191 3044420 3330136 3678193 4215244 4491655 4635399 4825647 5307762 5723073 6193581 6343163 6412549 6939317 7448527 7653234 8109406 8247186 8694349 9107982 9256817 9308402 9897870 10061482 10680266 11210653 11660005 11804...
output:
157794
result:
ok single line: '157794'
Test #33:
score: 30
Accepted
time: 60ms
memory: 3716kb
input:
1000 456 1 0 443096 828592 853300 2166760 3763688 4474083 5605059 5924755 6028046 7560910 9185540 9439212 10435851 11748693 12592624 13982847 15349361 15813754 16470798 16918094 17846923 18854493 19038890 20646465 21723048 22912066 23442080 24187299 24764257 25671485 27317603 28811914 29024954 30682...
output:
427924
result:
ok single line: '427924'
Test #34:
score: 30
Accepted
time: 55ms
memory: 3808kb
input:
1000 853 1 0 582236 707105 1485183 1565456 2305904 2945856 3588155 3639466 3983620 4616508 5234636 5253012 5318842 5973684 6450836 7271793 7564151 7828478 8062226 8365405 9058247 9229188 9935587 10236602 10498734 10859622 11459300 11790218 11802398 12225935 12315792 12739191 13278401 13767688 138153...
output:
216536
result:
ok single line: '216536'
Test #35:
score: 30
Accepted
time: 60ms
memory: 3672kb
input:
1000 678 1 0 1423965 1720061 2770130 3164514 4617891 4997811 5376811 6259000 6374700 7470084 8144917 8322317 9000489 10446643 11863354 13237339 14715403 16069900 16610423 17007435 17434598 17563153 18434143 19847695 20451294 20754484 20996075 21921238 22485230 22769421 22889959 23834563 25066889 251...
output:
391962
result:
ok single line: '391962'
Test #36:
score: 30
Accepted
time: 58ms
memory: 3808kb
input:
1000 79 1 0 146771 587793 895168 1125168 1335036 1452933 1526650 1918223 2012769 2582329 3104377 3194601 3300365 3442735 3461648 3982416 4296813 4857404 4920820 5369944 5920776 6374534 6792185 6999303 7246112 7728670 8213772 8686243 8874923 8977574 9463313 9471641 9583689 9890568 10222513 10395290 1...
output:
253173
result:
ok single line: '253173'
Test #37:
score: 30
Accepted
time: 58ms
memory: 3972kb
input:
1000 80 1 0 8138 16097 55052 132991 173831 191917 291217 349204 387976 510410 538297 566672 684616 763244 787637 872089 996937 1099484 1222638 1282821 1406083 1530218 1560976 1622871 1740617 1831309 1868920 1940406 2016359 2041718 2176541 2311739 2434375 2484665 2541798 2626695 2666664 2684068 26903...
output:
40462
result:
ok single line: '40462'
Test #38:
score: 30
Accepted
time: 60ms
memory: 3940kb
input:
1000 696 1 0 287744 552034 1939818 2810607 3742043 4697514 6394294 6952380 7749944 8885258 9610948 10729116 11520305 11842566 13495115 14422538 15759779 16950184 17730382 18723101 19644608 20937824 22314327 23483431 24832581 25116142 26646011 27722092 29174150 29817352 31121574 32062527 33269915 335...
output:
509406
result:
ok single line: '509406'
Test #39:
score: 30
Accepted
time: 57ms
memory: 3732kb
input:
1000 946 1 0 321611 583133 948259 1393880 1500586 1817398 2169635 2570310 3022668 3464202 3619114 4306711 5208482 5807290 6072910 6553270 7162827 7731663 8862192 9108146 10221512 11221274 12152335 12304641 12874083 13391968 13881281 14409814 14949312 14998383 16001073 16039140 16428078 17264220 1761...
output:
337421
result:
ok single line: '337421'
Test #40:
score: 30
Accepted
time: 59ms
memory: 3708kb
input:
1000 356 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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'
Subtask #3:
score: 0
Time Limit Exceeded
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Test #41:
score: 0
Time Limit Exceeded
input:
64944 48942 10 0 132465 271583 422988 502187 616524 781356 971483 1147338 1201136 1209297 1270299 1457035 1547500 1588836 1737679 1861812 1861942 1901796 2089337 2273423 2299172 2409479 2564115 2578298 2635887 2711417 2787082 2855980 2873745 2890630 3061756 3123156 3138851 3214185 3271978 3387891 35...