Submission #428360

#TimeUsernameProblemLanguageResultExecution timeMemory
428360A_DArranging Shoes (IOI19_shoes)C++14
Compilation error
0 ms0 KiB
#include "shoes.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> vec;
long long ans=0,cnt=0;
vector<int> s;
set<ii> st;
map<ii,int> mp;
void fix(int x)
{
    for(int i=0;i<s.size();i++){
        if(s[i]==x){
            for(int j=i-1;j>=cnt;j--){
                ans++;
                swap(s[j],s[j+1]);
            }
            for(int j=i+1;j<=cnt;j++){
                ans++;
                swap(s[j],s[j-1]);
            }
            break;
        }
    }
    cnt+=2;
}
long long count_swaps(std::vector<int> S){
    s=S;
    vec.clear();ans=0;cnt=0;
    for(int i=0;i<s.size();i++){
        if(s[i]<0){
            vec.push_back(abs(s[i]));
        }
    }
    int l=0,r=vec.size()-1;
    while(l<=r){
        int h=l+r;
        h%=2;
        if(h){
            cnt=l*2;
            fix(-vec[l]);
            l++;
        }
        else{
            cnt=r*2;
            fix(-vec[r]);
            r--;
        }
    }
    l=0;r=vec.size()-1;
    while(l<=r){
        int h=l+r;
        h%=2;
        if(h){
            cnt=l*2;
            fix(vec[l]);
            l++;
        }
        else{
            cnt=r*2;
            fix(vec[r]);
            r--;
        }
    }
    return ans;
}

Compilation message (stderr)

shoes.cpp:7:5: error: 'ii' was not declared in this scope
    7 | set<ii> st;
      |     ^~
shoes.cpp:7:7: error: template argument 1 is invalid
    7 | set<ii> st;
      |       ^
shoes.cpp:7:7: error: template argument 2 is invalid
shoes.cpp:7:7: error: template argument 3 is invalid
shoes.cpp:8:5: error: 'ii' was not declared in this scope
    8 | map<ii,int> mp;
      |     ^~
shoes.cpp:8:11: error: template argument 1 is invalid
    8 | map<ii,int> mp;
      |           ^
shoes.cpp:8:11: error: template argument 3 is invalid
shoes.cpp:8:11: error: template argument 4 is invalid
shoes.cpp: In function 'void fix(int)':
shoes.cpp:11:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |     for(int i=0;i<s.size();i++){
      |                 ~^~~~~~~~~
shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:29:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |     for(int i=0;i<s.size();i++){
      |                 ~^~~~~~~~~