Submission #829385

#TimeUsernameProblemLanguageResultExecution timeMemory
829385JoksimKaktusArranging Shoes (IOI19_shoes)C++17
70 / 100
1073 ms1876 KiB
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <set>

using namespace std;

long long count_swaps(vector <int> S){
    bool s3 = true;
    bool s4 = true;
    for(int i = 1;i < S.size();i++){
        if(abs(S[i]) != abs(S[i-1])){
            s3 = false;
        }
        if(i < S.size()/2 && i > 0){
            s4 = false;
        }
    }
    if(s3 || s4) {
        long long res = 0;
        int next = 0;
        for (int i = 0; i < S.size(); i++) {
            if (S[i] < 0) {
                res += abs(i - next);
                next += 2;
            }
        }
        return res;
    }else{
        long long res = 0;
        for(int i = 0;i < S.size();i++){
            if(S[i] == 0){
                continue;
            }else if(S[i] < 0){
                int zero = 0;
                for(int j = i+1;j < S.size();j++){
                    if(S[j] == -S[i]){
                        res += j-(i+1) - zero;
                        S[j] = 0;
                        S[i] = 0;
                        break;
                    }else if(S[j] == 0){
                        zero++;
                    }
                }
            }else{
                int zero = 0;
                for(int j = i+1;j < S.size();j++){
                    if(-S[j] == S[i]){
                        res += j-(i) - zero;
                        S[j] = 0;
                        S[i] = 0;
                        break;
                    }else if(S[j] == 0){
                        zero++;
                    }
                }
            }
        }
        return res;
    }
}

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:16:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |     for(int i = 1;i < S.size();i++){
      |                   ~~^~~~~~~~~~
shoes.cpp:20:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |         if(i < S.size()/2 && i > 0){
      |            ~~^~~~~~~~~~~~
shoes.cpp:27:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |         for (int i = 0; i < S.size(); i++) {
      |                         ~~^~~~~~~~~~
shoes.cpp:36:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |         for(int i = 0;i < S.size();i++){
      |                       ~~^~~~~~~~~~
shoes.cpp:41:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |                 for(int j = i+1;j < S.size();j++){
      |                                 ~~^~~~~~~~~~
shoes.cpp:53:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |                 for(int j = i+1;j < S.size();j++){
      |                                 ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...