Submission #965378

#TimeUsernameProblemLanguageResultExecution timeMemory
965378akacool445kArranging Shoes (IOI19_shoes)C++14
10 / 100
1 ms348 KiB
#include <queue> #include "shoes.h" using namespace std; long long count_swaps(vector<int> s) { long long n = s.size(); long long ans = 0; queue<int> a[n / 2 + 1], b[n / 2 + 1]; for (int i = 0; i < n; i++) { if (s[i] < 0) a[-s[i]].push(i); else b[s[i]].push(i); } vector<int> c(n, 1); for (int i = 0; i < n; i++) { if (c[i] == 0) continue; int ss = 0; int x = s[i]; int j = i; if (x < 0) { int y = -x; j = b[y].front(); b[y].pop(); a[x].pop(); } else { j = a[x].front(); a[x].pop(); b[x].pop(); } for (int jj = i + 1; jj < j; jj++) { ss += c[jj]; } c[j] = 0; if (x > 0) ans++; } return ans; }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:25:7: warning: array subscript -1 is below array bounds of 'std::queue<int> [(<anonymous> + 1)]' [-Warray-bounds]
   25 |    a[x].pop();
      |    ~~~^
shoes.cpp:25:7: warning: array subscript -1 is below array bounds of 'std::queue<int> [(<anonymous> + 1)]' [-Warray-bounds]
shoes.cpp:25:7: warning: array subscript -1 is below array bounds of 'std::queue<int> [(<anonymous> + 1)]' [-Warray-bounds]
shoes.cpp:25:7: warning: array subscript -1 is below array bounds of 'std::queue<int> [(<anonymous> + 1)]' [-Warray-bounds]
shoes.cpp:25:7: warning: array subscript -1 is below array bounds of 'std::queue<int> [(<anonymous> + 1)]' [-Warray-bounds]
shoes.cpp:25:7: warning: array subscript -1 is below array bounds of 'std::queue<int> [(<anonymous> + 1)]' [-Warray-bounds]
#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...