Submission #736979

#TimeUsernameProblemLanguageResultExecution timeMemory
736979tvladm2009Arranging Shoes (IOI19_shoes)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #include "shoes.h" using namespace std; typedef long long ll; const int N_MAX = 100000; int A[2 * N_MAX + 2]; deque <int> Minus[N_MAX + 2], Plus[N_MAX + 2]; int nxt[2 * N_MAX + 2]; bool used[N_MAX + 2]; int BIT[2 * N_MAX + 2]; void update(int pos, int val) { for (int i = pos; i <= 2 * N_MAX; i += i & -i) { BIT[i] += val; } } int query(int pos) { int answer = 0; for (int i = pos; i >= 1; i -= i & -i) { answer += BIT[i]; } return answer; } int count_swaps(int S[]) { int N = sizeof(S) / sizeof(int); N /= 2; for (int i = 1; i <= 2 * N; i++) { A[i] = S[i - 1]; } for (int i = 1; i <= 2 * N; i++) { if (A[i] < 0) { Minus[A[i] * -1].push_back(i); } else { Plus[A[i]].push_back(i); } } for (int i = 1; i <= 2 * N; i++) { if (A[i] < 0) { if (Plus[A[i] * -1].empty() == false) { nxt[i] = Plus[A[i] * -1].front(); } Minus[A[i] * -1].pop_front(); } else { if (Minus[A[i]].empty() == false) { nxt[i] = Minus[A[i]].front(); } Plus[A[i]].pop_front(); } } ll answer = 0; for (int i = 1; i <= 2 * N; i++) { if (used[i] == false) { int j = nxt[i]; int between = query(j - 1) - query(i); int swaps = (j - i - 1) - between; if (A[i] > 0) { swaps++; } answer += swaps; used[i] = true; used[j] = true; update(i, +1); update(j, +1); } } return answer; }

Compilation message (stderr)

shoes.cpp: In function 'int count_swaps(int*)':
shoes.cpp:30:20: warning: 'sizeof' on array function parameter 'S' will return size of 'int*' [-Wsizeof-array-argument]
   30 |     int N = sizeof(S) / sizeof(int);
      |                   ~^~
shoes.cpp:29:21: note: declared here
   29 | int count_swaps(int S[]) {
      |                 ~~~~^~~
/usr/bin/ld: /tmp/ccmG5eBP.o: in function `main':
grader.cpp:(.text.startup+0x2a8): undefined reference to `count_swaps(std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status