QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#491771 | #2784. Aliens | Wansur | 0 | 46ms | 10356kb | C++23 | 2.8kb | 2024-07-25 21:57:21 | 2024-07-25 21:57:25 |
Judging History
answer
#include <bits/stdc++.h>
#define ent '\n'
#define f first
#define s second
typedef long long ll;
typedef long double ld;
using namespace std;
const int maxn = 1e6+12;
pair<ld, int> dp[maxn];
vector<int> g[maxn];
bool was[maxn];
vector<int> t;
int L[maxn];
int R[maxn];
int n, m;
struct line{
ld k, b;
int c;
};
bool check(line nw, line last, line prl){
if((nw.b - prl.b) * (prl.k - last.k) <= (last.b - prl.b) * (prl.k - nw.k))return 1;
return 0;
}
int ptr = 0;
vector<line> l;
void add(line x){
while(l.size() && l.back().k == x.k && l.back().b > x.b){
l.pop_back();
}
if(l.size() && l.back().k == x.k && l.back().b <= x.b){
return;
}
while(l.size()>1 && check(x, l.back(), l[l.size()-2])){
l.pop_back();
}
l.push_back(x);
}
pair<ld, int> get(ll x){
if(!l.size()){
return {1e18, 1e9};
}
if(ptr >= l.size()){
ptr = l.size()-1;
}
while(ptr + 1 < l.size() && l[ptr].k * x + l[ptr].b > l[ptr+1].k * x + l[ptr+1].b){
ptr++;
}
return {l[ptr].k * x + l[ptr].b, l[ptr].c + 1};
}
int check(ll k){
add({0, 0, 0});
for(int &i:t){
dp[i] = get(i);
dp[i].f += i * 1ll * i + k;
for(int &j:g[i]){
ll b = j * 1ll * j + dp[R[j]].f, c = dp[R[j]].s;
if(R[j] > j) b -= (R[j] - j) * 1ll * (R[j] - j);
add(line(-2 * j, b, c));
}
}
l.clear();
ptr = 0;
return dp[m].s;
}
long long solve(int k){
ll val = 0;
for(ll l = -2e12, r = 2e12; l <= r;){
ll mid = l + r >> 1;
if(check(mid) <= k){
val = mid;
r = mid - 1;
}
else l = mid + 1;
}
check(val);
return dp[m].f - dp[m].s * val;
}
long long take_photos(int N, int M, int k, vector<int> rr, vector<int> c){
n = N, m = M;
for(int i=1;i<=m;i++){
L[i] = 1e9;
}
m = 0;
for(int i=0;i<n;i++){
if(rr[i] < c[i]){
swap(rr[i], c[i]);
}
rr[i]++, c[i]++;
L[rr[i]] = min(L[rr[i]], c[i]);
R[c[i]] = max(R[c[i]], rr[i]);
for(int x=-1;x<=0;x++){
was[rr[i]+x] = was[c[i]+x] = 1;
}
m = max(m, rr[i]);
}
was[1] = 1;
for(int i=1;i<=m;i++){
R[i] = max(R[i], R[i-1]);
if(!was[i]) continue;
t.push_back(i);
g[max(R[i], i)].push_back(i);
}
ll ans = 1e18;
int l = 1, r = k;
for(; r - l >= 10;){
int m1 = l + (r - l) / 3, m2 = r - (r - l) / 3;
ans = min({ans, solve(m1), solve(m2)});
if(solve(m1) <= solve(m2)){
r = m2;
}
else l = m1;
}
for(int i=l;i<=r;i++){
ans = min(ans, solve(i));
}
return ans;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 4
Accepted
time: 2ms
memory: 10000kb
input:
2 6 2 1 4 4 1
output:
098d134608c94f7413faac591054ee35 16
result:
ok Correct answer: answer = 16
Test #2:
score: 4
Accepted
time: 2ms
memory: 10172kb
input:
1 2 1 0 1
output:
098d134608c94f7413faac591054ee35 4
result:
ok Correct answer: answer = 4
Test #3:
score: 4
Accepted
time: 0ms
memory: 9916kb
input:
2 2 2 0 0 1 0
output:
098d134608c94f7413faac591054ee35 4
result:
ok Correct answer: answer = 4
Test #4:
score: 4
Accepted
time: 0ms
memory: 10212kb
input:
2 3 2 0 1 1 1
output:
098d134608c94f7413faac591054ee35 4
result:
ok Correct answer: answer = 4
Test #5:
score: 4
Accepted
time: 2ms
memory: 9848kb
input:
4 4 4 1 3 0 1 2 1 2 2
output:
098d134608c94f7413faac591054ee35 12
result:
ok Correct answer: answer = 12
Test #6:
score: 4
Accepted
time: 2ms
memory: 9872kb
input:
5 8 5 0 5 2 6 7 4 4 5 2 6
output:
098d134608c94f7413faac591054ee35 52
result:
ok Correct answer: answer = 52
Test #7:
score: 4
Accepted
time: 2ms
memory: 9920kb
input:
8 20 8 6 14 5 13 1 8 17 15 6 9 1 9 2 0 17 8
output:
098d134608c94f7413faac591054ee35 210
result:
ok Correct answer: answer = 210
Test #8:
score: 4
Accepted
time: 0ms
memory: 10168kb
input:
10 10 10 2 2 3 6 8 6 8 3 6 9 4 0 8 4 8 1 0 8 8 9
output:
098d134608c94f7413faac591054ee35 88
result:
ok Correct answer: answer = 88
Test #9:
score: 4
Accepted
time: 0ms
memory: 10000kb
input:
10 100 10 98 25 55 31 36 25 38 77 9 82 11 69 88 42 47 49 19 91 61 13
output:
098d134608c94f7413faac591054ee35 7696
result:
ok Correct answer: answer = 7696
Test #10:
score: 4
Accepted
time: 2ms
memory: 10200kb
input:
50 1 50 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:
098d134608c94f7413faac591054ee35 1
result:
ok Correct answer: answer = 1
Test #11:
score: 4
Accepted
time: 4ms
memory: 9936kb
input:
50 50 50 25 25 44 12 46 47 4 26 10 35 10 3 13 27 14 16 6 28 10 0 27 46 2 19 10 36 29 49 13 16 6 38 32 48 33 33 47 45 8 13 5 21 14 25 21 41 47 49 26 7 4 7 5 34 5 24 16 24 18 26 29 10 32 39 14 39 35 32 11 1 49 17 24 18 38 14 32 48 46 1 45 46 17 36 29 31 24 48 12 33 4 44 38 32 11 6 25 47 9 49
output:
098d134608c94f7413faac591054ee35 2374
result:
ok Correct answer: answer = 2374
Test #12:
score: 4
Accepted
time: 5ms
memory: 9916kb
input:
50 100 50 0 20 49 26 21 27 10 67 79 9 38 75 39 27 36 51 75 81 70 37 57 74 57 64 13 76 53 95 25 11 62 37 78 38 39 19 46 7 92 71 40 27 73 11 30 55 60 67 79 48 3 69 1 27 41 54 80 40 50 50 9 49 75 11 90 62 2 71 14 40 30 48 3 53 68 24 99 25 8 49 35 80 31 24 21 11 92 9 4 97 45 61 56 83 68 75 35 84 77 20
output:
098d134608c94f7413faac591054ee35 9502
result:
ok Correct answer: answer = 9502
Test #13:
score: 4
Accepted
time: 2ms
memory: 9940kb
input:
49 7 49 5 3 0 6 6 2 3 3 4 2 3 4 0 3 1 3 2 4 5 1 1 0 2 1 3 0 4 4 1 6 0 5 1 4 6 3 6 6 6 5 4 0 3 5 5 5 2 0 4 5 3 2 0 2 1 5 2 5 6 4 1 1 5 0 0 4 6 0 5 4 2 6 0 1 5 2 4 6 5 6 3 1 3 6 0 0 4 3 1 2 2 2 4 1 2 3 6 1
output:
098d134608c94f7413faac591054ee35 49
result:
ok Correct answer: answer = 49
Test #14:
score: 0
Wrong Answer
time: 4ms
memory: 9876kb
input:
50 51 50 38 39 6 7 44 45 24 25 30 31 25 26 49 50 10 11 18 19 36 37 7 8 15 16 21 22 32 33 13 14 5 6 11 12 45 46 48 49 47 48 28 29 26 27 40 41 14 15 33 34 23 24 2 3 12 13 19 20 46 47 8 9 35 36 4 5 42 43 39 40 20 21 1 2 37 38 34 35 41 42 22 23 27 28 0 1 31 32 9 10 16 17 29 30 17 18 43 44 3 4
output:
098d134608c94f7413faac591054ee35 201
result:
wrong answer Wrong answer: output = 201, expected = 151
Subtask #2:
score: 0
Wrong Answer
Test #23:
score: 12
Accepted
time: 2ms
memory: 10008kb
input:
2 2 1 0 0 1 1
output:
098d134608c94f7413faac591054ee35 4
result:
ok Correct answer: answer = 4
Test #24:
score: 12
Accepted
time: 2ms
memory: 9940kb
input:
4 3 2 0 0 0 0 0 0 0 0
output:
098d134608c94f7413faac591054ee35 1
result:
ok Correct answer: answer = 1
Test #25:
score: 12
Accepted
time: 0ms
memory: 10208kb
input:
5 5 2 2 2 3 3 4 4 3 3 3 3
output:
098d134608c94f7413faac591054ee35 5
result:
ok Correct answer: answer = 5
Test #26:
score: 12
Accepted
time: 2ms
memory: 9940kb
input:
10 20 3 3 3 15 15 10 10 18 18 4 4 7 7 15 15 2 2 10 10 7 7
output:
098d134608c94f7413faac591054ee35 41
result:
ok Correct answer: answer = 41
Test #27:
score: 12
Accepted
time: 2ms
memory: 9944kb
input:
20 1000 5 737 737 714 714 662 662 163 163 683 683 615 615 23 23 246 246 724 724 90 90 802 802 557 557 146 146 429 429 816 816 164 164 638 638 568 568 957 957 904 904
output:
098d134608c94f7413faac591054ee35 71923
result:
ok Correct answer: answer = 71923
Test #28:
score: 12
Accepted
time: 6ms
memory: 9976kb
input:
200 1000 10 69 69 277 277 350 350 753 753 741 741 849 849 993 993 95 95 928 928 789 789 333 333 795 795 493 493 253 253 661 661 780 780 17 17 394 394 487 487 719 719 426 426 297 297 885 885 323 323 981 981 916 916 0 0 997 997 757 757 374 374 467 467 787 787 297 297 216 216 599 599 62 62 936 936 777 ...
output:
098d134608c94f7413faac591054ee35 77137
result:
ok Correct answer: answer = 77137
Test #29:
score: 0
Wrong Answer
time: 46ms
memory: 10356kb
input:
500 1000 250 599 599 14 14 176 176 963 963 93 93 257 257 403 403 741 741 854 854 862 862 778 778 489 489 711 711 623 623 163 163 750 750 649 649 441 441 245 245 311 311 429 429 756 756 572 572 766 766 837 837 137 137 719 719 244 244 519 519 287 287 251 251 818 818 789 789 305 305 400 400 262 262 359...
output:
098d134608c94f7413faac591054ee35 925
result:
wrong answer Wrong answer: output = 925, expected = 764
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
0%
Subtask #5:
score: 0
Skipped
Dependency #1:
0%
Subtask #6:
score: 0
Skipped
Dependency #1:
0%