이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "shoes.h"
using namespace std;
#define ll long long
#define endl '\n'
const int N = 2e5 + 5;
vector<ll> node[100005];
ll a[200005], in[200005];
ll count_swaps(vector<int> s){
ll ans = 0;
int n = s.size();
if (n <= 2000){
for (int i = 0; i < n; i++){
bool flag = false;
for (int j = 0; j < i; j++){
if (((s[j] + s[i]) == 0) && in[j] == 0){
flag = true;
if (s[i] < 0) {
ans = ans + i - j;
for (int k = i - 1; k >= j; k--){
swap(s[k], s[k + 1]);
swap(in[k], in[k + 1]);
}
in[j + 1] = 1;
in[j] = 1;
break;
} else {
ans = ans + i - j - 1;
for (int k = i - 1; k > j; k--){
swap(s[k], s[k + 1]);
swap(in[k], in[k + 1]);
}
in[j + 1] = 1;
in[j] = 1;
break;
}
}
}
}
return ans;
} else {
ll cnt = 1;
for (int i = 0; i < n; i++){
if (s[i] > 0){
node[s[i]].push_back(cnt - 1);
cnt += 2;
}
}
for (int i = 1; i <= (n / 2); i++){
if (node[i].size() == 0) continue;
reverse(node[i].begin(), node[i].end());
}
for (int i = 0; i < n; i++){
if (s[i] < 0){
ans = ans + abs(i - node[-s[i]].back());
node[-s[i]].pop_back();
}
}
return ans;
}
}
/*
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
if (fopen("VietCT.INP", "r")){
freopen("VietCT.INP", "r", stdin);
freopen("VietCT.OUT", "w", stdout);
}
ll n;
cin >> n;
vector<int> mem;
for (int i = 1; i <= (2 * n); i++){
ll u;
cin >> u;
mem.push_back(u);
}
cout << count_swaps(mem);
}
*/
/*
2
-2 -2 2 2
*/
컴파일 시 표준 에러 (stderr) 메시지
shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:17:30: warning: variable 'flag' set but not used [-Wunused-but-set-variable]
17 | bool flag = false;
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |