git reimport

This commit is contained in:
2019-03-15 13:47:54 +04:00
commit 3b461f73de
489 changed files with 1631603 additions and 0 deletions

View File

@@ -0,0 +1,72 @@
package chelper;
import java.util.Arrays;
import io.InputReader;
import io.OutputWriter;
import misc.GCJSolution;
import misc.SimpleSavingChelperSolution;
public class TaskA extends GCJSolution {
public void solve(int testNumber, InputReader in, OutputWriter out) {
wrapSolve(testNumber, in, out);
}
@Override
public void solve(int testNumber) {
int n = in.nextInt();
int[] a = in.nextIntArray(n);
char[][] map = new char[n * 2][n];
for (int i = 0; i < n * 2; i++) {
Arrays.fill(map[i], '.');
}
int maxRowUsed = 0;
boolean ok = true;
for (int i = 0; i < n; i++) {
int src = i;
int dest = 0;
for (; dest < n; dest++) {
if (a[dest] > 0) {
a[dest]--;
break;
}
}
int y = 0;
while (src != dest) {
if (src == 0 || src == n - 1) {
ok = false;
}
boolean dir = src < dest;
map[y][src] = dir ? '\\' : '/';
src += dir ? 1 : -1;
y++;
maxRowUsed = Math.max(maxRowUsed, y);
}
}
maxRowUsed++;
if (!ok) {
out.println("IMPOSSIBLE");
return;
}
out.println(maxRowUsed);
for (int i = 0; i < maxRowUsed; i++) {
for (int j = 0; j < n; j++) {
out.print(map[i][j]);
}
out.println();
}
}
}

View File

@@ -0,0 +1,37 @@
5 TaskA
12 MULTI_NUMBER
8 STANDARD
9 input.txt
8 STANDARD
10 output.txt
1
0
33 3
4
1 1 1 1
3
0 2 1
6
3 0 0 2 0 1
67 Case #1: 1
....
Case #2: IMPOSSIBLE
Case #3: 3
.//\..
./\./.
......
1
11 src/chelper
16 -Xmx256m -Xss64m
4 Main
13 chelper.TaskA
39 net.egork.chelper.checkers.TokenChecker
0
0
10 2018.05.19
0
1
14 io.InputReader
15 io.OutputWriter
0
0

View File

@@ -0,0 +1,121 @@
package chelper;
import java.util.Arrays;
import io.InputReader;
import io.OutputWriter;
import misc.GCJSolution;
public class TaskB extends GCJSolution {
public void solve(int testNumber, InputReader in, OutputWriter out) {
wrapSolve(testNumber, in, out);
}
boolean ok(int a0, int b0, int a1, int b1) {
int t = Integer.compare(a0, a1);
if (t != 0) {
return t > 0;
}
return Integer.compare(b0, b1) > 0;
}
int[][] dp;
int n = 510;
void precalc() {
dp = new int[n][n];
int[][][] lastDelta = new int[n][n][2];
for (int i = 0; i < n; i++) {
Arrays.fill(dp[i], -1);
}
dp[0][0] = 0;
long sum = 0;
for (int a = 0; a < n; a++) {
for (int b = 0; b < n; b++) {
if (a > b) {
dp[a][b] = dp[b][a];
lastDelta[a][b] = lastDelta[b][a];
continue;
}
for (int aa = 0; aa <= a; aa++) {
for (int bb = 0; bb <= b; bb++) {
if (dp[a - aa][b - bb] * 1.1 + 5 < dp[a][b]) {
break;
}
if (dp[a - aa][b - bb] + 1 <= dp[a][b]) {
continue;
}
if (aa < lastDelta[a - aa][b - bb][0]) {
continue;
}
if (aa == lastDelta[a - aa][b - bb][0] && bb <= lastDelta[a - aa][b - bb][1]) {
continue;
}
dp[a][b] = dp[a - aa][b - bb] + 1;
lastDelta[a][b][0] = aa;
lastDelta[a][b][1] = bb;
}
}
}
}
for (int a = 0; a < n; a++) {
for (int b = 0; b < n; b++) {
sum += dp[a][b];
}
}
// System.out.println(dp[88][53]);
// System.out.println((sum - 16727938));
// System.out.flush();
}
{
precalc();
}
@Override
public void solve(int testNumber) {
int a = in.nextInt();
int b = in.nextInt();
out.println(dp[a][b]);
// try {
// OutputWriter log = new OutputWriter("precalc.txt");
// for (int i = 0; i < n; i++) {
// for (int j = 0; j < n; j++) {
// log.print(String.format("%4d ", dp[i][j]));
//
// double x = Math.pow(i + j, 0.7);
//
// out.println(String.format("%4d %4d: %4d %.2f", i, j, dp[i][j], x));
// }
// log.println();
// }
// } catch (FileNotFoundException e) {
// throw new RuntimeException(e);
// }
}
}

View File

@@ -0,0 +1,29 @@
5 TaskB
12 MULTI_NUMBER
8 STANDARD
9 input.txt
8 STANDARD
10 output.txt
1
0
9 2
2 0
4 5
22 Case #1: 1
Case #2: 5
1
11 src/chelper
16 -Xmx256m -Xss64m
4 Main
13 chelper.TaskB
39 net.egork.chelper.checkers.TokenChecker
0
0
10 2018.05.19
0
1
14 io.InputReader
15 io.OutputWriter
0
0

View File

@@ -0,0 +1,105 @@
package chelper;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import io.InputReader;
import io.OutputWriter;
import misc.GCJSolution;
public class TaskC extends GCJSolution {
public void solve(int testNumber, InputReader in, OutputWriter out) {
wrapSolve(testNumber, in, out);
}
@Override
public void solve(int testNumber) {
int n = in.nextInt();
int[][] a = new int[n][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
a[i][j] = in.nextInt();
}
}
Map<Integer, Set<Integer>> mxs1 = new HashMap<>();
Map<Integer, Set<Integer>> mys1 = new HashMap<>();
Map<Integer, Set<Integer>> mxs2 = new HashMap<>();
Map<Integer, Set<Integer>> mys2 = new HashMap<>();
Map<Integer, Integer> counts1 = new HashMap<>();
Map<Integer, Integer> counts2 = new HashMap<>();
Map<Integer, Integer> total = new HashMap<>();
int changes = 0;
for (int i = -n; i <= n; i++) {
mxs1.put(i, new HashSet<>());
mys1.put(i, new HashSet<>());
counts1.put(i, 0);
mxs2.put(i, new HashSet<>());
mys2.put(i, new HashSet<>());
counts2.put(i, 0);
total.put(i, 0);
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
int f = a[i][j];
total.put(f, total.get(f) + 1);
if (!mxs1.get(f).contains(i) && !mys1.get(f).contains(j)) {
counts1.put(f, counts1.get(f) + 1);
mxs1.get(f).add(i);
mys1.get(f).add(j);
} else {
if (!mxs2.get(f).contains(i) && !mys2.get(f).contains(j)) {
counts2.put(f, counts2.get(f) + 1);
mxs2.get(f).add(i);
mys2.get(f).add(j);
}
}
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
int f = a[i][j];
if (!mxs1.get(f).contains(i) && !mys1.get(f).contains(j)) {
counts1.put(f, counts1.get(f) + 1);
mxs1.get(f).add(i);
mys1.get(f).add(j);
} else {
if (!mxs2.get(f).contains(i) && !mys2.get(f).contains(j)) {
counts2.put(f, counts2.get(f) + 1);
mxs2.get(f).add(i);
mys2.get(f).add(j);
}
}
}
}
for (int f = -n; f <= n; f++) {
int maxLeft = Math.max(counts1.get(f), counts2.get(f));
changes += total.get(f) - maxLeft;
}
out.println(changes);
}
}

View File

@@ -0,0 +1,102 @@
5 TaskC
12 MULTI_NUMBER
8 STANDARD
9 input.txt
8 STANDARD
10 output.txt
8
0
42 4
2
1 2
2 1
2
1 1
2 1
2
1 2
1 2
2
2 2
-2 2
43 Case #1: 0
Case #2: 1
Case #3: 2
Case #4: 1
1
1
11 1
2
1 1
1 1
10 Case #1: 2
1
2
21 1
3
1 1 1
2 1 1
3 2 1
10 Case #1: 3
1
3
59 2
3
1 1 1
-1 2 -2
3 -3 -1
4
1 2 3 4
1 2 3 4
1 2 3 4
4 3 2 1
21 Case #1: 2
Case #2: 8
1
4
35 1
4
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
11 Case #1: 12
1
5
51 1
4
-2 1 3 4
4 1 2 3
1 1 1 1
2 1 4 -3
10 Case #1: 5
0
6
21 1
3
2 1 3
1 1 1
3 1 2
10 Case #1: 3
1
7
11 1
2
1 1
1 2
10 Case #1: 1
1
11 src/chelper
16 -Xmx256m -Xss64m
4 Main
13 chelper.TaskC
39 net.egork.chelper.checkers.TokenChecker
0
0
10 2018.05.19
0
1
14 io.InputReader
15 io.OutputWriter
0
0