Submission #312795

#TimeUsernameProblemLanguageResultExecution timeMemory
312795BasilhijazArranging Shoes (IOI19_shoes)C++17
50 / 100
1136 ms541936 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]; bool done[n]; memset(done, 0, sizeof(done)); /*for(int i = 0; i < n; i++){ if(s[i] < 0){ if(!right[abs(s[i])].empty()){ pairs.pb({right[abs(s[i])].top(), i}); right[abs(s[i])].pop(); } else{ left[abs(s[i])].push(i); } } else{ if(!left[s[i]].empty()){ pairs.pb({left[s[i]].top(), i}); left[s[i]].pop(); } else{ right[s[i]].push(i); } } } /**/ for(int i = 0; i < n; i++){ if(!done[i]){ int serach = s[i]*-1; int first = -1; int second = -1; first = i; for(int j = i + 1; j < n; j++){ if(s[j] == serach && !done[j]){ second = j; done[j] = 1; break; } } pairs.pb({first, second}); } } int ans = 0; for(int i = 0; i < pairs.size(); i++){ if(s[pairs[i].first] > 0){ ans++; } } 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:35:5: warning: "/*" within comment [-Wcomment]
   35 |     /**/
      |      
shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:52: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]
   52 |     for(int i = 0; i < pairs.size(); i++){
      |                    ~~^~~~~~~~~~~~~~
shoes.cpp:58: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]
   58 |     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...