-
-
Save tanzaku/cc3db8684b09d571965027c356b3a614 to your computer and use it in GitHub Desktop.
TCO17 Round 2C Easy CanidsSeesaw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
public class CanidsSeesaw { | |
int count(int[] w, int[] f, int[] ps) { | |
int s1 = 0, s2 = 0; | |
int p = 0; | |
for (int i = 0; i < w.length; i++) { | |
s1 += w[i]; | |
s2 += f[ps[i]]; | |
if (s1 < s2) p++; | |
} | |
return p; | |
} | |
public int[] construct(int[] wolf, int[] fox, int k) { | |
int[] res = new int[fox.length]; | |
for (int i = 0; i < fox.length; i++) { | |
res[i] = i; | |
} | |
for (int i = 0; i < fox.length; i++) { | |
int[] unused = Arrays.copyOfRange(res, i, fox.length); | |
for (int j = 0; j < unused.length; j++) { | |
for (int l = unused.length - 1; l > j; l--) { | |
if (fox[unused[l]] < fox[unused[l-1]]) { | |
int t = unused[l]; | |
unused[l] = unused[l-1]; | |
unused[l-1] = t; | |
} | |
} | |
} | |
for (int j = 0; j < unused.length; j++) { | |
res[i] = unused[j]; | |
for (int l = i + 1, m = unused.length - 1; l < fox.length; m--) { | |
if (m != j) { | |
res[l++] = unused[m]; | |
} | |
} | |
// dump(count(wolf, fox, res), res, i, j); | |
if (count(wolf, fox, res) >= k) break; | |
} | |
} | |
// dump(count(wolf, fox, res), res, k); | |
if (count(wolf, fox, res) != k) { | |
return new int[0]; | |
} | |
return res; | |
} | |
static void dump(Object... o) { System.err.println(Arrays.deepToString(o)); } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment