Submission #1145673

#TimeUsernameProblemLanguageResultExecution timeMemory
1145673MunkhturErdenebatArranging Shoes (IOI19_shoes)C++20
50 / 100
1095 ms2632 KiB

 #include "shoes.h"
 #include <bits/stdc++.h>
using namespace std;

long long count_swaps(vector<int> s) {
    int a = s.size();
    vector<int> maa(a, 0); // Initialize array with 0
    long long h = 0;
    
    for(int i = 0; i < a; i++) {
        if(maa[i] == 1) continue;
        
        int g = -1;
        for(int j = i + 1; j < a; j++) {
            if(s[j] + s[i] == 0 && maa[j] == 0) {
                g = j;
                break;
            }
        }
        
        if (g == -1) continue;
        if(s[i]>0){
            h++;
        }
        for(int j = g - 1; j > i; j--) {
            if(maa[j] == 0) h++;
        }

        maa[g] = 1; // Mark the index as used
    }
    return h;
}
#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...