QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#139163 | #2670. Arranging shoes | Qwerty1232# | 10 | 0ms | 4064kb | C++20 | 1.1kb | 2023-08-12 18:37:41 | 2024-07-04 01:39:57 |
Judging History
answer
#include "shoes.h"
#include <algorithm>
#include <cassert>
#include <map>
#include <numeric>
long long count_swaps(std::vector<int> s) {
int n = s.size() / 2;
// if (n <= 8) {
// ;
// }
int64_t res = 0;
// for (int i = 0, c = 0; i < 2 * n; i++) {
// if (s[i] < 0) {
// int c2 = i - c;
// res += abs(c - c2);
// } else {
// c++;
// }
// }
std::map<int, std::pair<std::vector<int>, std::vector<int>>> map;
for (int i = 0; i < 2 * n; i++) {
auto& pr = map[abs(s[i])];
if (s[i] > 0) {
pr.second.push_back(i);
} else {
pr.first.push_back(i);
}
}
int64_t sum = 0;
for (auto& [sz, pr] : map) {
auto& [vc1, vc2] = pr;
int m = vc1.size();
for (int i = 0; i < m; i++) {
int it = std::lower_bound(vc2.begin(), vc2.end(), vc1[i]) - vc2.begin();
res += abs(i - it);
sum += abs(vc1[i] - vc2[i]) - 1;
}
}
// assert(sum % 2 == 0);
// res += sum / 2;
res += sum;
return res;
}
详细
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 0ms
memory: 4064kb
input:
08f55b3f-c300-4051-a472-59ca2a776178 1 -1 1
output:
9ce55564-5404-428a-8d2e-0d809c85101e OK 0
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 3772kb
input:
08f55b3f-c300-4051-a472-59ca2a776178 1 1 -1
output:
9ce55564-5404-428a-8d2e-0d809c85101e OK 1
result:
ok 3 lines
Subtask #2:
score: 0
Wrong Answer
Dependency #1:
100%
Accepted
Test #3:
score: 20
Accepted
time: 0ms
memory: 3788kb
input:
08f55b3f-c300-4051-a472-59ca2a776178 2 -1 -2 2 1
output:
9ce55564-5404-428a-8d2e-0d809c85101e OK 2
result:
ok 3 lines
Test #4:
score: 0
Accepted
time: 0ms
memory: 3764kb
input:
08f55b3f-c300-4051-a472-59ca2a776178 2 -2 1 -1 2
output:
9ce55564-5404-428a-8d2e-0d809c85101e OK 3
result:
ok 3 lines
Test #5:
score: 0
Accepted
time: 0ms
memory: 3772kb
input:
08f55b3f-c300-4051-a472-59ca2a776178 2 -2 2 -1 1
output:
9ce55564-5404-428a-8d2e-0d809c85101e OK 0
result:
ok 3 lines
Test #6:
score: 0
Accepted
time: 0ms
memory: 4056kb
input:
08f55b3f-c300-4051-a472-59ca2a776178 2 -1 -2 2 1
output:
9ce55564-5404-428a-8d2e-0d809c85101e OK 2
result:
ok 3 lines
Test #7:
score: -20
Wrong Answer
time: 0ms
memory: 3724kb
input:
08f55b3f-c300-4051-a472-59ca2a776178 2 -1 2 1 -2
output:
9ce55564-5404-428a-8d2e-0d809c85101e OK 3
result:
wrong answer 3rd lines differ - expected: '2', found: '3'
Subtask #3:
score: 0
Wrong Answer
Test #37:
score: 0
Wrong Answer
time: 0ms
memory: 3772kb
input:
08f55b3f-c300-4051-a472-59ca2a776178 2 -2 -2 2 2
output:
9ce55564-5404-428a-8d2e-0d809c85101e OK 3
result:
wrong answer 3rd lines differ - expected: '1', found: '3'
Subtask #4:
score: 0
Wrong Answer
Test #74:
score: 15
Accepted
time: 0ms
memory: 3788kb
input:
08f55b3f-c300-4051-a472-59ca2a776178 1 -1 1
output:
9ce55564-5404-428a-8d2e-0d809c85101e OK 0
result:
ok 3 lines
Test #75:
score: -15
Wrong Answer
time: 0ms
memory: 3768kb
input:
08f55b3f-c300-4051-a472-59ca2a776178 2 -1 -2 1 2
output:
9ce55564-5404-428a-8d2e-0d809c85101e OK 2
result:
wrong answer 3rd lines differ - expected: '1', found: '2'
Subtask #5:
score: 0
Skipped
Dependency #2:
0%
Subtask #6:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%