ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#212775 | #3830. D | eam2539 | 70 | 142ms | 3812kb | C++11 | 2.8kb | 2024-10-20 10:58:33 | 2024-10-20 12:42:59 |
answer
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
bool check_k0(int x, int n, int m, const vector<int> &a) {
ll operations_needed = 0;
vector<ll> diff(n + 2, 0);
ll current = 0;
for (int j=1; j<=n; ++j) {
current += diff[j];
if(current < a[j-1]) {
ll need = a[j-1] - current;
operations_needed += need;
if(operations_needed > m) return false;
int s = min(j + x, n);
diff[j] += need;
diff[s +1] -= need;
current += need;
}
}
return operations_needed <= m;
}
bool check_k1(int x, int n, int m, const vector<int> &a) {
ll max_required_x = 0;
for (int j=1; j<=n; ++j) {
ll required = ( (ll)a[j-1] + m -1 ) / m + j -1;
if(x < required) {
return false;
}
}
return true;
}
bool check_k2(int x, int n, int m, const vector<int> &a){
vector<ll> diff_c(n+2,0);
vector<ll> diff_ci(n+2,0);
vector<ll> diff_ci2(n+2,0);
ll sum_c =0, sum_ci=0, sum_ci2=0;
ll operations =0;
for(int j=1; j<=n; j++){
sum_c += diff_c[j];
sum_ci += diff_ci[j];
sum_ci2 += diff_ci2[j];
ll b_j = sum_c * (ll)j * j + (-2LL *x * sum_c -2LL * sum_ci) * (ll)j + sum_c * (ll)x *x + 2LL *x * sum_ci + sum_ci2;
if(b_j < a[j-1]){
ll deficit = a[j-1] - b_j;
if(x ==0){
return false;
}
ll need = (deficit + (ll)x *x -1) / ((ll)x *x);
operations += need;
if(operations >m) return false;
diff_c[j] += need;
if(j +x +1 <=n){
diff_c[j +x +1] -= need;
}
diff_ci[j] += need * j;
if(j +x +1 <=n){
diff_ci[j +x +1] -= need * j;
}
diff_ci2[j] += need * (ll)j * j;
if(j +x +1 <=n){
diff_ci2[j +x +1] -= need * (ll)j * j;
}
sum_c += need;
sum_ci += need * j;
sum_ci2 += need * (ll)j * j;
b_j += need * (ll)x *x - 2LL *x * need *j + need * (ll)j *j;
}
}
return operations <=m;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m, k;
cin >> n >> m >> k;
vector<int> a(n);
for (auto &x : a) cin >> x;
int left = 0, right = 200000;
int answer = -1;
while(left <= right) {
int mid = left + (right - left)/2;
bool feasible = false;
if(k ==0) {
feasible = check_k0(mid, n, m, a);
} else if(k ==1) {
feasible = check_k1(mid, n, m, a);
} else if(k ==2) {
feasible = check_k2(mid, n, m, a);
}
if(feasible) {
answer = mid;
right = mid -1;
} else {
left = mid +1;
}
}
cout << answer;
}
详细
小提示:点击横条可展开更详细的信息
Subtask #1:
score: 5
Accepted
Test #1:
score: 5
Accepted
time: 0ms
memory: 1252kb
input:
5 2 0 1 4 2 4 2
output:
-1
result:
ok 1 number(s): "-1"
Test #2:
score: 0
Accepted
time: 0ms
memory: 1252kb
input:
5 4 0 3 3 3 2 4
output:
4
result:
ok 1 number(s): "4"
Test #3:
score: 0
Accepted
time: 0ms
memory: 1252kb
input:
5 3 0 5 2 2 4 2
output:
-1
result:
ok 1 number(s): "-1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 1248kb
input:
5 5 0 5 4 1 3 2
output:
4
result:
ok 1 number(s): "4"
Test #5:
score: 0
Accepted
time: 0ms
memory: 1252kb
input:
5 2 0 5 4 2 4 4
output:
-1
result:
ok 1 number(s): "-1"
Subtask #2:
score: 15
Accepted
Test #6:
score: 15
Accepted
time: 9ms
memory: 2372kb
input:
100000 3 0 55571 62024 7086 67802 12577 42004 72323 45260 40287 39641 64847 42428 20318 80027 1675 1...
output:
-1
result:
ok 1 number(s): "-1"
Test #7:
score: 0
Accepted
time: 6ms
memory: 2368kb
input:
100000 8 0 36036 57465 41887 17317 60373 61269 46492 67963 2549 76969 65274 49046 45876 28759 90924 ...
output:
-1
result:
ok 1 number(s): "-1"
Test #8:
score: 0
Accepted
time: 7ms
memory: 2368kb
input:
100000 345779 0 77937 16610 76642 46218 97870 25174 72710 41405 46404 77129 58889 92261 62956 90112 ...
output:
33331
result:
ok 1 number(s): "33331"
Test #9:
score: 0
Accepted
time: 8ms
memory: 2368kb
input:
100000 130400 0 20765 84750 25569 4034 50808 69305 81243 22986 10531 40222 39994 26549 22297 82520 6...
output:
99997
result:
ok 1 number(s): "99997"
Test #10:
score: 0
Accepted
time: 11ms
memory: 2372kb
input:
100000 912222 0 8745 38207 60092 71722 52971 57093 95705 81528 46159 5367 17799 81004 56400 92268 70...
output:
11107
result:
ok 1 number(s): "11107"
Subtask #3:
score: 0
Wrong Answer
Test #11:
score: 10
Accepted
time: 0ms
memory: 1260kb
input:
1000 1 1 993 705 891 648 406 9 983 913 370 408 607 47 85 199 767 448 723 255 253 302 754 135 641 726...
output:
1991
result:
ok 1 number(s): "1991"
Test #12:
score: -10
Wrong Answer
time: 0ms
memory: 1260kb
input:
1000 529 1 321 273 256 430 151 307 590 682 756 267 100 169 963 681 121 604 781 631 573 463 50 114 36...
output:
1001
result:
wrong answer 1st numbers differ - expected: '56', found: '1001'
Subtask #4:
score: 0
Wrong Answer
Test #16:
score: 0
Wrong Answer
time: 25ms
memory: 1592kb
input:
100000 4 1 10156 27005 39480 62054 63362 28009 65831 14391 93683 7991 17027 26313 1403 15929 30567 1...
output:
124742
result:
wrong answer 1st numbers differ - expected: '91939', found: '124742'
Subtask #5:
score: 20
Accepted
Test #21:
score: 20
Accepted
time: 0ms
memory: 1284kb
input:
1000 169 2 853 394 985 195 859 84 227 50 641 365 409 407 845 112 7 582 920 965 590 869 550 781 40 44...
output:
26
result:
ok 1 number(s): "26"
Test #22:
score: 0
Accepted
time: 1ms
memory: 1280kb
input:
1000 874 2 717 216 44 176 32 180 933 647 934 213 975 986 632 998 720 903 974 606 354 934 530 796 700...
output:
14
result:
ok 1 number(s): "14"
Test #23:
score: 0
Accepted
time: 0ms
memory: 1284kb
input:
1000 455 2 647 67 103 814 166 711 324 526 937 533 303 734 424 82 811 760 492 310 430 344 99 427 199 ...
output:
17
result:
ok 1 number(s): "17"
Test #24:
score: 0
Accepted
time: 1ms
memory: 1284kb
input:
1000 1 2 701 530 397 177 358 786 75 190 106 780 406 978 363 548 53 204 496 270 741 900 577 281 457 9...
output:
1030
result:
ok 1 number(s): "1030"
Test #25:
score: 0
Accepted
time: 0ms
memory: 1284kb
input:
1000 873 2 828 767 349 303 964 57 405 154 571 802 85 4 704 946 938 225 440 479 948 165 619 331 46 69...
output:
14
result:
ok 1 number(s): "14"
Subtask #6:
score: 30
Accepted
Test #26:
score: 30
Accepted
time: 20ms
memory: 3812kb
input:
100000 31778 2 9482 16920 65207 41338 19891 97532 56865 946 56851 5908 19270 8065 53369 97241 69805 ...
output:
93
result:
ok 1 number(s): "93"
Test #27:
score: 0
Accepted
time: 13ms
memory: 3812kb
input:
100000 6 2 93983 87323 30431 58395 29480 7132 61292 78220 39593 10909 54117 16301 15515 86002 75066 ...
output:
16964
result:
ok 1 number(s): "16964"
Test #28:
score: 0
Accepted
time: 20ms
memory: 3812kb
input:
100000 86747 2 39111 48163 20134 88227 19418 52897 9740 19221 33808 97530 22220 93923 57860 92452 77...
output:
65
result:
ok 1 number(s): "65"
Test #29:
score: 0
Accepted
time: 4ms
memory: 3808kb
input:
100000 3 2 3 97260 65263 38481 46694 94780 72822 23184 76915 31099 72401 63002 14464 49133 49775 121...
output:
33634
result:
ok 1 number(s): "33634"
Test #30:
score: 0
Accepted
time: 17ms
memory: 3808kb
input:
100000 95256 2 57106 93938 1905 58600 32034 15380 47197 85902 24934 6275 11606 93191 32480 33253 959...
output:
63
result:
ok 1 number(s): "63"