Submission #421125

# Submission time Handle Problem Language Result Execution time Memory
421125 2021-06-08T18:24:32 Z daanolav Arranging Shoes (IOI19_shoes) C++14
10 / 100
1 ms 280 KB
#include "shoes.h"
#include <vector>
#include <bitset>
#include <tuple>
#include <cmath>


using namespace std;

typedef vector<int> vi;
typedef pair<vi,vi> vivi;


int n,num,shoeSize,index;


long long count_swaps(std::vector<int> s) {
    n = s.size() / 2;
	vivi sizes[n + 1];

	for(index = 0; index < 2  * n; ++index) {
        num = s[index];
        //cerr << "shoe num " << index << " is " << num << endl;
        shoeSize = abs(num);
        if(num < 0) {
            sizes[shoeSize].first.push_back(index);
        } else {
            sizes[shoeSize].second.push_back(index);
        }
	}

	long long swapsNeeded = 0;


	for(vivi shoes : sizes) {
        //cerr << "lop" << endl;
        //cerr << shoes.first.size() << endl;
        for(index = 0; index < shoes.first.size(); ++index) {
            //cerr << "comparing " << shoes.first[index] << " and " << shoes.second[index] << endl;
            if(shoes.second[index] > shoes.first[index]) {
                swapsNeeded += shoes.second[index] - shoes.first[index] - 1;
            } else {
                swapsNeeded += shoes.first[index] - shoes.second[index];
            }
        }
	}

	return swapsNeeded;

}

Compilation message

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:38:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |         for(index = 0; index < shoes.first.size(); ++index) {
      |                        ~~~~~~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Incorrect 0 ms 276 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 0 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 1 ms 280 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Incorrect 0 ms 276 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Incorrect 0 ms 276 KB Output isn't correct
8 Halted 0 ms 0 KB -