Submission #312790

#TimeUsernameProblemLanguageResultExecution timeMemory
312790BasilhijazArranging Shoes (IOI19_shoes)C++17
10 / 100
1138 ms543092 KiB
#include "shoes.h" #include <bits/stdc++.h> using namespace std; #define pb push_back vector<pair<int, int> > pairs; long long count_swaps(vector<int> s) { int n = s.size(); queue<int> left[2*n + 1]; queue<int> right[2*n + 1]; for(int i = 0; i < n; i++){ if(s[i] < 0){ if(!right[abs(s[i])].empty()){ pairs.pb({right[abs(s[i])].front(), i}); right[abs(s[i])].pop(); } else{ left[abs(s[i])].push(i); } } else{ if(!left[s[i]].empty()){ pairs.pb({left[s[i]].front(), i}); left[s[i]].pop(); } else{ right[s[i]].push(i); } } } int ans = 0; for(int i = 0; i < pairs.size(); i++){ if(s[pairs[i].first] > 0){ ans++; } } bool done[n]; memset(done, 0, sizeof(done)); for(int i = 0; i < pairs.size(); i++){ done[pairs[i].second] = 1; for(int j = pairs[i].first + 1; j < pairs[i].second; j++){ if(!done[j])ans++; } } return ans; }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:34:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |     for(int i = 0; i < pairs.size(); i++){
      |                    ~~^~~~~~~~~~~~~~
shoes.cpp:41:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |     for(int i = 0; i < pairs.size(); i++){
      |                    ~~^~~~~~~~~~~~~~
#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...