Submission #1140479

#TimeUsernameProblemLanguageResultExecution timeMemory
1140479tsengangArranging Shoes (IOI19_shoes)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define ertunt return
#define vodka void
#include "shoes.h"
long long count_swaps(vector<int> s) {
	n = s.size()/2;
    if(n == 1){
        if(s[0] < 0)ertunt 0;
        else ertunt 1;
    }
    vector<ll> adj[n+4][2];
    map<ll,ll>m;
    for(ll i = 0; i < s.size(); i++){
        m[abs(s[i])] = 1;
        if(s[i] < 0){
            adj[abs(s[i])][0].pb(i);
        }
        else adj[s[i]][1].pb(i);
    }
    ll cnt = 0;
    ll k = -1;
    ll ans = 0;
    for(auto x : m){
        cnt++;
        k = x;
        for(ll i = 0; i < adj[x][0]; i++){
            if(adj[x][0][i] > adj[x][1][i]){
                ans+=adj[x][0][i] - adj[x][1][i] - 1;
            }
            else{
                ans+=adj[x][1][i] - adj[x][0][i] - 2;
            }
        }
    }
    if(cnt == 0){
        ertunt ans;
    }
}

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:12:9: error: 'n' was not declared in this scope
   12 |         n = s.size()/2;
      |         ^
shoes.cpp:22:13: error: 'adj' was not declared in this scope
   22 |             adj[abs(s[i])][0].pb(i);
      |             ^~~
shoes.cpp:24:14: error: 'adj' was not declared in this scope
   24 |         else adj[s[i]][1].pb(i);
      |              ^~~
shoes.cpp:31:13: error: cannot convert 'std::pair<const long long int, long long int>' to 'long long int' in assignment
   31 |         k = x;
      |             ^
      |             |
      |             std::pair<const long long int, long long int>
shoes.cpp:32:27: error: 'adj' was not declared in this scope
   32 |         for(ll i = 0; i < adj[x][0]; i++){
      |                           ^~~
shoes.cpp:44:1: warning: control reaches end of non-void function [-Wreturn-type]
   44 | }
      | ^