Submission #143856

#TimeUsernameProblemLanguageResultExecution timeMemory
143856daniel920712Arranging Shoes (IOI19_shoes)C++14
Compilation error
0 ms0 KiB
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <map>
#include <vector>

using namespace std;

struct A
{
    int l,r;
    int nxl,nxr;
    int how;
}Node[200005];

long long count_swaps(std::vector<int> S)
{
    long long ans1=0,small,what,t;
    int i,j,k,N=S.size();
    for(i=0;i<N/2;i++) if(S[i]!=S[i+N/2]) break;
    if(i==N/2) return (N/2)*(N/2-1)/2;
    for(i=0;i<N/2;i++)
    {
        for(j=1;j<=N/2;j++)
        {
            a[j]=100000000;
            b[j]=100000000;
        }
        for(j=2*i;j<N;j++)
        {
            if(S[j]<0) b[0-S[j]]=min(b[0-S[j]],j);
            else a[S[j]]=min(a[S[j]],j);
        }
        small=1000000000;
        for(j=1;j<=N/2;j++)
        {
            t=a[j]+b[j];
            if(a[j]>b[j]) t++;
            if(t<small)
            {
                small=t;
                what=j;
            }
        }
        for(j=2*i;j<N;j++)
        {
            if(S[j]==0-what)
            {
                for(k=j;k>2*i;k--)
                {
                    swap(S[k],S[k-1]);
                    ans1++;
                }
                break;
            }
        }
        for(j=2*i+1;j<N;j++)
        {
            if(S[j]==what)
            {
                for(k=j;k>2*i+1;k--)
                {
                    swap(S[k],S[k-1]);
                    ans1++;
                }
                break;
            }
        }
    }


    return ans1;
}

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:27:13: error: 'a' was not declared in this scope
             a[j]=100000000;
             ^
shoes.cpp:28:13: error: 'b' was not declared in this scope
             b[j]=100000000;
             ^
shoes.cpp:32:24: error: 'b' was not declared in this scope
             if(S[j]<0) b[0-S[j]]=min(b[0-S[j]],j);
                        ^
shoes.cpp:33:18: error: 'a' was not declared in this scope
             else a[S[j]]=min(a[S[j]],j);
                  ^
shoes.cpp:38:15: error: 'a' was not declared in this scope
             t=a[j]+b[j];
               ^
shoes.cpp:38:20: error: 'b' was not declared in this scope
             t=a[j]+b[j];
                    ^