Submission #289840

#TimeUsernameProblemLanguageResultExecution timeMemory
289840NicolaAbusaad2014Arranging Shoes (IOI19_shoes)C++14
10 / 100
1 ms256 KiB
#include "shoes.h" #include <bits/stdc++.h> using namespace std; long long count_swaps(vector<int> s) { long long ans=0,z=0,dp[s.size()+1]; dp[0]=0; map<long,vector<long> >m; map<long,long>now,vis; for(long i=0;i<s.size();i++){ vis[s[i]]++; m[s[i]].push_back(i); z++; if(vis[s[i]]&&vis[-s[i]]){ if(s[i]<0){ ans+=m[s[i]][now[abs(s[i])]]-m[-s[i]][now[abs(s[i])]]; } else{ ans+=m[s[i]][now[abs(s[i])]]-m[-s[i]][now[abs(s[i])]]-1; } ans+=m[s[i]][now[abs(s[i])]]-m[-s[i]][now[abs(s[i])]]-1; ans-=dp[m[-s[i]][now[abs(s[i])]]]*2; vis[s[i]]--; vis[-s[i]]--; now[abs(s[i])]++; z-=2; } dp[i+1]=z; } return ans; }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:9:19: warning: comparison of integer expressions of different signedness: 'long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 |     for(long i=0;i<s.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...