Submission #829004

#TimeUsernameProblemLanguageResultExecution timeMemory
829004TrunktyArranging Shoes (IOI19_shoes)C++14
10 / 100
1081 ms13984 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; //#define int ll #include "shoes.h" ll ans; vector<int> lef[100005],rit[100005]; int mat[200005]; int curr[200005]; ll count_swaps(vector<int> s){ for(int i=0;i<s.size();i++){ if(s[i]<0){ lef[-s[i]].push_back(i+1); } else{ rit[s[i]].push_back(i+1); } curr[i+1] = i+1; } for(int i=1;i<=1e5;i++){ for(int j=0;j<lef[i].size();j++){ mat[lef[i][j]] = rit[i][j]; } } for(int i=1;i<=2*s.size();i++){ if(mat[i]){ int pa,pb; for(int j=1;j<=2*s.size();j++){ if(curr[j]==i){ pa = j; } if(curr[j]==mat[i]){ pb = j; } } if(pa<pb){ while(pb>pa+1){ swap(curr[pb],curr[pb-1]); pb--; ans++; } } else{ while(pa>pb){ swap(curr[pa],curr[pa-1]); pa--; ans++; } } } } return ans; }

Compilation message (stderr)

shoes.cpp: In function 'll count_swaps(std::vector<int>)':
shoes.cpp:14:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |  for(int i=0;i<s.size();i++){
      |              ~^~~~~~~~~
shoes.cpp:24:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |         for(int j=0;j<lef[i].size();j++){
      |                     ~^~~~~~~~~~~~~~
shoes.cpp:28:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     for(int i=1;i<=2*s.size();i++){
      |                 ~^~~~~~~~~~~~
shoes.cpp:31:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |             for(int j=1;j<=2*s.size();j++){
      |                         ~^~~~~~~~~~~~
shoes.cpp:30:20: warning: 'pb' may be used uninitialized in this function [-Wmaybe-uninitialized]
   30 |             int pa,pb;
      |                    ^~
shoes.cpp:30:17: warning: 'pa' may be used uninitialized in this function [-Wmaybe-uninitialized]
   30 |             int pa,pb;
      |                 ^~
#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...