답안 #543426

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
543426 2022-03-30T14:22:00 Z Blobo2_Blobo2 Arranging Shoes (IOI19_shoes) C++17
10 / 100
1 ms 300 KB
#include "shoes.h"
//#include "grader.cpp"
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define endl "\n"
#define all(v)  v.begin(),v.end()
#define gen(arr,n,nxt)  generate(arr,arr+n,nxt)
#define Blobo2 ios_base::sync_with_stdio(false);cin.tie(0);
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<pair<long long,long long>, null_type,less<pair<long long,long long>>, rb_tree_tag,tree_order_statistics_node_update>

//s.order_of_key(x)
//s.find_by_order(idx)

long long count_swaps(vector<int32_t> v) {
    int n = v.size();
    long long arr[n];
    for(int i=0;i<n;i++)arr[i] = abs(v[i]);
    ordered_set st;
    long long cnt=0;
    for(int i=n-1;i>=0;i--){
        st.insert({arr[i],i});
        int idx = st.order_of_key(make_pair(arr[i],i));
        cnt += idx;
    }
    stack<int>s[(n/2)+1];
    bool vis[n];
    memset(vis,0,sizeof vis);
    for(int i=n-1;i>=0;i--){
        if(v[i] > 0){
            s[v[i]].push(i);
        }
        else{
            if(!s[-v[i]].empty()){
                vis[s[-v[i]].top()] = 1;
                s[-v[i]].pop();
                vis[i] = 1;
            }
        }
    }
    int c = 0;
    for(int i=0;i<n;i++)c += vis[i] == 0;
    c/=2;
    cnt += c;
    return cnt;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Incorrect 1 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 1 ms 296 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Incorrect 1 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Incorrect 1 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -