제출 #1307769

#제출 시각아이디문제언어결과실행 시간메모리
1307769lufychopArranging Shoes (IOI19_shoes)C++20
컴파일 에러
0 ms0 KiB
#include "shoes.h"
#include <bits/stdc++.h>

using namespace std;


long long count_swaps(vector<int> s)
{
    n=s.size();
    long long ans=0;
    long long LL=0,RR=n-1;
    for(int i=0;i<n;i++)
    {
        mp[s[i]].push_back(i);
    }
    while(LL<RR)
    {
        if(s[LL]!=0)
        {
            long long tmp=0;
            long long L=LL+1;
            long long R=mp[-s[LL]].front();
            mp[s[LL]].pop_front();
            mp[-s[LL]].pop_front();
            for(int i=L;i<=R;i++)
            {
                if(s[i]==0)
                {
                    tmp++;
                }
            }
            ans=ans+R-LL-1-tmp;
            // cout<<LL<<R<<"\n";
            if(s[R]<0)
            {
                ans++;
            }
            s[R]=0;
            s[LL]=0;
        }
        if(s[RR]!=0)
        {
            long long tmp=0;
            long long L=mp[-s[RR]].back();
            long long R=RR-1;
            mp[-s[RR]].pop_back();
            mp[s[RR]].pop_back();
            for(int i=L;i<=R;i++)
            {
                if(s[i]==0)
                {
                    tmp++;
                }
            }
            ans=ans+RR-L-1-tmp;
            // cout<<L<<RR<<"\n";
            if(s[L]>0)
            {
                ans++;
            }
            s[L]=0;
            s[RR]=0;
        }
        // cout<<LL<<RR;
        LL++;
        RR--;
    }
	return ans;
}

컴파일 시 표준 에러 (stderr) 메시지

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:9:5: error: 'n' was not declared in this scope
    9 |     n=s.size();
      |     ^
shoes.cpp:14:9: error: 'mp' was not declared in this scope
   14 |         mp[s[i]].push_back(i);
      |         ^~
shoes.cpp:22:25: error: 'mp' was not declared in this scope; did you mean 'tmp'?
   22 |             long long R=mp[-s[LL]].front();
      |                         ^~
      |                         tmp
shoes.cpp:44:25: error: 'mp' was not declared in this scope; did you mean 'tmp'?
   44 |             long long L=mp[-s[RR]].back();
      |                         ^~
      |                         tmp