| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1141136 | altern23 | Arranging Shoes (IOI19_shoes) | C++20 | 0 ms | 328 KiB |
#include "shoes.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
long long count_swaps(vector<int> s) {
ll n = s.size();
vector<pair<ll, ll>> isi[n + 5];
for(int i = 0; i < n; i++){
isi[abs(s[i])].push_back({i, s[i]});
}
ll ans = 0;
for(ll i = 1; i <= n; i++){
stack<ll> pos, neg;
for(auto [idx, val] : isi[i]){
// kalau - ketemu +
if(val < 0){
if(!pos.empty()){
ans += idx - pos.top();
pos.pop();
}
else{
neg.push(idx);
}
}
else{
if(!neg.empty()){
ans += idx - neg.top() - 1;
neg.pop();
}
else{
pos.push(idx);
}
}
}
}
return ans;
}
| # | 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... | ||||
