Submission #244811

#TimeUsernameProblemLanguageResultExecution timeMemory
244811crossing0verArranging Shoes (IOI19_shoes)C++17
0 / 100
5 ms512 KiB
#include<bits/stdc++.h> #define ll long long #include "shoes.h" using namespace std; ll count_swaps(vector<int> a) { int n = a.size(); ll ans = 0; vector< vector<vector<int>> > v(2,vector< vector<int> >(n+1)); for (int i = 0;i < n; i++) { if (a[i] < 0) v[1][-a[i]].push_back(i); else v[0][a[i]].push_back(i); } vector<int> vis(n,1); for (int i = 1; i <= n; i++) for (int t = 0; t < 2; t++) reverse(v[t][i].begin(),v[t][i].end()); for (int i = 0; i < n;i++) { if (vis[i] == 0) continue; int x = a[i]; int val = abs(x); int t = (x < 0 ? 0 : 1); int ps = v[t][x].back(); vis[i] = 0; v[t][x].pop_back(); v[!t][x].pop_back(); for (int j = i + 1; j <= ps; j++) ans += vis[j]; if (t == 0) ans++; vis[ps] = 0; } return ans; }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:21:7: warning: unused variable 'val' [-Wunused-variable]
   int val = abs(x);
       ^~~
#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...