Submission #827959

#TimeUsernameProblemLanguageResultExecution timeMemory
827959smatcsuArranging Shoes (IOI19_shoes)C++17
Compilation error
0 ms0 KiB
#include<bits/stdc++.h>
#define ll long long
using namespace std;
 
ll count_swaps(vector<int> v){
    if(v.size()==2){
        if(abs(v[0])==v[1] and v[0]<=0 and v[1]>=0) return 0;
        else{
            if(abs(v[1])==v[0] and v[1]<=0 and v[0]>=0) return 1;
            else return -1;
        }
    }
    else{
        ll ans=0;
        ll ans1=0;
        for(int i=0;i<n;i++){
            if(v[i]>0) ans++;
            else ans1++;
        }
        if(ans!=ans1) return -1;
        else{
            ll res=0;
            for(int i=0;i<n;i++){
                if(v[i]>0) res++;
                if(v[i+1]<0) res++;
            }
            ll a=res/2;
            return a;
        }
    }
}

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:16:23: error: 'n' was not declared in this scope
   16 |         for(int i=0;i<n;i++){
      |                       ^
shoes.cpp:23:27: error: 'n' was not declared in this scope
   23 |             for(int i=0;i<n;i++){
      |                           ^