Submission #349835

#TimeUsernameProblemLanguageResultExecution timeMemory
349835negiempireArranging Shoes (IOI19_shoes)Java
Compilation error
0 ms0 KiB
public class Solution { public static void main(String[] args) { int testData[] = { -1, 1, -2, 2 }; System.out.println("total count: " +count_swaps(testData)); } int[] a; public Solution(int n) { a = new int[n]; } int count(int right) { int cnt = 0; for (; right >= 0; right = (right & (right + 1)) - 1) { cnt += a[right]; } return cnt; } int count(int left, int right) { return count(right) - count(left - 1); } void put(int index) { for (; index < a.length; index = index | (index + 1)) { a[index]++; } } static int[] change(int[] v) { int n = v.length / 2; int cnt[] = new int[n]; for (int i = 0; i < 2 * n; i++) if (v[i] > 0) cnt[v[i] - 1]++; for (int i = 1; i < n; i++) cnt[i] += cnt[i - 1]; int[] cntl = cnt, cntr = cnt; for (int i = 0; i < 2 * n; i++) if (v[i] > 0) v[i] = (--cntr[v[i] - 1]) + 1; else v[i] = -((--cntl[-v[i] - 1]) + 1); return v; } static int[] create_index(int n, int[] S) { int[] index = new int[2 * n + 1]; for (int i = 0; i < 2 * n; i++) { index[S[i] + n] = i; } return index; } static long count_adjacent(int n, int[] S) { int[] index = create_index(n, S); Solution f = new Solution(2 * n); long ans = 0; for (int i = 0; i < 2 * n; i++) { if (S[i] != 0) { int pos = index[-S[i] + n]; ans += pos - i - f.count(i, pos) - (S[i] < 0 ? 1 : 0); S[pos] = 0; f.put(pos); } } return ans; } static long count_swaps(int[] S) { S = change(S); int n = S.length / 2; return count_adjacent(n, S); } }

Compilation message (stderr)

shoes.java:1: error: class Solution is public, should be declared in a file named Solution.java
public class Solution {
       ^
grader.java:22: error: cannot find symbol
		shoes solver = new shoes();
		^
  symbol:   class shoes
  location: class grader
grader.java:22: error: cannot find symbol
		shoes solver = new shoes();
		                   ^
  symbol:   class shoes
  location: class grader
3 errors