이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//#include "shoes.h"
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
set<pair<int, int>> left_shoes;
ll n, now,idx, ans;
map<int, set<int>>i_r_shoes;
queue<pair<int, int>> q;
void shift() {
for(auto c : left_shoes) {
int IDX = c.first;
if(now <= IDX && IDX <= idx) {
ans++;
q.push({IDX, c.second});
}
}
while(!q.empty()) {
int a = q.front().first , b = q.front().second;
left_shoes.erase({a, b});
left_shoes.insert({a + 1, b});
q.pop();
}
for(auto &c : i_r_shoes) {
queue<int> q_p;
for(int d : c.second) {
if(now <= d && d <= idx) q_p.push(d), ans++;
}
while(!q_p.empty()) {
int a = q_p.front();
//if(c.second.find(a) != c.second.end()) printf("YES\n");
c.second.erase(a);
c.second.insert(a+1);
//printf("now %d %d\n", c.first, a+1);
q_p.pop();
}
}
}
long long count_swaps(std::vector<int> s) {
n = s.size();
for(int i = 0; i < n; i++) {
if(s[i] < 0) left_shoes.insert({i, s[i]});
else i_r_shoes[s[i]].insert(i);
}
while(!left_shoes.empty()) {
idx = (*left_shoes.begin()).first;
int type = (*left_shoes.begin()).second;
left_shoes.erase({idx, type});
shift();
now++;
/*printf("here --> %d %d \n", type, idx);
for(auto c : left_shoes) {
printf("%d %d\n", c.second, c.first);
}
for(auto c : i_r_shoes) {
for(auto d : c.second)printf("%d %d\n", c.first, d);
}
*/
idx = *i_r_shoes[-type].begin();
i_r_shoes[-type].erase(idx);
shift();
now++;/*
printf("%d\n", ans);
for(auto c : left_shoes) {
printf("%d %d\n", c.second, c.first);
}
for(auto c : i_r_shoes) {
for(auto d : c.second)printf("%d %d\n", c.first, d);
}*/
}
return ans;
}
/*int main() {
int N;
cin >> N;
vector<int> v;
for(int i = 0; i < 2*N; i++) {
int x;
cin >> x;
v.push_back(x);
}
printf("%lld\n", count_swaps(v));
}*/
# | 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... |