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,69 @@
package chelper;
import java.util.ArrayList;
import java.util.List;
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);
}
long get(List<Integer> a) {
long res = 0;
long t = 1;
for (int i : a) {
res += i * t;
t *= 2;
}
return res;
}
@Override
public void solve(int testNumber) {
long d = in.nextLong();
String s = in.nextString();
List<Integer> a = new ArrayList<>();
int t = 0;
for (char c : s.toCharArray()) {
if (c == 'C') {
a.add(t);
t = 0;
}
if (c == 'S') {
t++;
}
}
if (t > 0) {
a.add(t);
}
int c = 0;
while (get(a) > d) {
c++;
if (a.size() == 1) {
out.println("IMPOSSIBLE");
return;
}
a.set(a.size() - 1, a.get(a.size() - 1) - 1);
a.set(a.size() - 2, a.get(a.size() - 2) + 1);
if (a.get(a.size() - 1) == 0) {
a.remove(a.size() - 1);
}
}
out.println(c);
}
}

View File

@@ -0,0 +1,36 @@
5 TaskA
12 MULTI_NUMBER
8 STANDARD
9 input.txt
8 STANDARD
10 output.txt
1
0
38 6
1 CS
2 CS
1 SS
6 SCCSSC
2 CC
3 CSCSS
74 Case #1: 1
Case #2: 0
Case #3: IMPOSSIBLE
Case #4: 2
Case #5: 0
Case #6: 5
1
11 src/chelper
16 -Xmx256m -Xss64m
4 Main
13 chelper.TaskA
39 net.egork.chelper.checkers.TokenChecker
0
0
10 2018.04.07
0
1
14 io.InputReader
15 io.OutputWriter
0
0

View File

@@ -0,0 +1,50 @@
package chelper;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import io.InputReader;
import io.OutputWriter;
import misc.GCJSolution;
import misc.SimpleSavingChelperSolution;
public class TaskB 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);
List<Integer> even = new ArrayList<>();
List<Integer> odd = new ArrayList<>();
for (int i = 0; i < n; i++) {
if (i % 2 == 0) {
even.add(a[i]);
} else {
odd.add(a[i]);
}
}
Collections.sort(even);
Collections.sort(odd);
for (int i = 0; i < n - 1; i++) {
int x = i % 2 == 0 ? even.get(i / 2) : odd.get(i / 2);
int y = (i + 1) % 2 == 0 ? even.get((i + 1) / 2) : odd.get((i + 1) / 2);
if (x > y) {
out.println(i);
return;
}
}
out.println("OK");
}
}

View File

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

View File

@@ -0,0 +1,98 @@
package chelper;
import java.util.Objects;
import java.util.TreeSet;
import io.InputReader;
import io.OutputWriter;
public class TaskC {
class Point implements Comparable<Point> {
public final int x;
public final int y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Point point = (Point) o;
return x == point.x &&
y == point.y;
}
@Override
public int hashCode() {
return Objects.hash(x, y);
}
@Override
public int compareTo(Point o) {
int t = Integer.compare(x, o.x);
if (t != 0) {
return t;
}
return Integer.compare(y, o.y);
}
}
public void solve(int testNumber, InputReader in, OutputWriter out) {
int area = in.nextInt();
int w, h;
int offsetX = 100;
int offsetY = 100;
if (area == 20) {
w = 5;
h = 4;
} else {
w = 20;
h = 10;
}
TreeSet<Point> missing = new TreeSet<>();
for (int i = 0; i < w; i++) {
for (int j = 0; j < h; j++) {
missing.add(new Point(i, j));
}
}
while (!missing.isEmpty()) {
Point p = missing.first();
int x = p.x + 1;
int y = p.y;
x = Math.max(1, Math.min(w - 2, x)) + offsetX;
y = Math.max(1, Math.min(h - 2, y)) + offsetY;
out.println(x + " " + y);
out.flush();
int xi = in.nextInt();
int yi = in.nextInt();
if (xi == -1 && yi == -1) {
throw new RuntimeException("something's bad");
}
if (xi == 0 && yi == 0) {
break;
}
Point p2 = new Point(xi - offsetX, yi - offsetY);
missing.remove(p2);
}
}
}

View File

@@ -0,0 +1,26 @@
5 TaskC
12 MULTI_NUMBER
8 STANDARD
9 input.txt
8 STANDARD
10 output.txt
1
0
4 1
20
-1
1
11 src/chelper
16 -Xmx256m -Xss64m
4 Main
13 chelper.TaskC
39 net.egork.chelper.checkers.TokenChecker
0
0
10 2018.04.07
0
1
14 io.InputReader
15 io.OutputWriter
0
0

View File

@@ -0,0 +1,147 @@
package chelper;
import io.InputReader;
import io.OutputWriter;
import misc.GCJSolution;
public class TaskA extends GCJSolution {
private int n;
private int m;
private int cutsX;
private int cutsY;
private boolean[][] map;
private int[][] ps;
public void solve(int testNumber, InputReader in, OutputWriter out) {
wrapSolve(testNumber, in, out);
}
int sum(int x0, int y0, int x1, int y1) {
int res = ps[x1][y1];
if (x0 > 0) {
res -= ps[x0 - 1][y1];
}
if (y0 > 0) {
res -= ps[x1][y0 - 1];
}
if (x0 > 0 && y0 > 0) {
res += ps[x0 - 1][y0 - 1];
}
return res;
}
@Override
public void solve(int testNumber) {
n = in.nextInt();
m = in.nextInt();
cutsX = in.nextInt();
cutsY = in.nextInt();
map = new boolean[n][m];
for (int i = 0; i < n; i++) {
String s = in.nextString();
for (int j = 0; j < m; j++) {
map[i][j] = s.charAt(j) == '@';
}
}
ps = new int[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (i > 0) {
ps[i][j] += ps[i - 1][j];
}
if (j > 0) {
ps[i][j] += ps[i][j - 1];
}
if (i > 0 && j > 0) {
ps[i][j] -= ps[i - 1][j - 1];
}
if (map[i][j]) {
ps[i][j]++;
}
}
}
int[] cx0 = new int[cutsX + 1];
int[] cx1 = new int[cutsX + 1];
int[] cy0 = new int[cutsY + 1];
int[] cy1 = new int[cutsY + 1];
int total = sum(0, 0, n - 1, m - 1);
int cutC = (cutsX + 1) * (cutsY + 1);
if (total % cutC != 0) {
out.println("IMPOSSIBLE");
return;
}
int perC = total / cutC;
int cutStartX = 0;
int cutStartY = 0;
for (int i = 0; i < cutsX + 1; i++) {
boolean ok = false;
for (int cutEndX = cutStartX; cutEndX < n; cutEndX++) {
int s = sum(cutStartX, 0, cutEndX, m - 1);
if (s == perC * (cutsY + 1)) {
cx0[i] = cutStartX;
cx1[i] = cutEndX;
cutStartX = cutEndX + 1;
ok = true;
break;
}
}
if (!ok) {
out.println("IMPOSSIBLE");
return;
}
}
for (int i = 0; i < cutsY + 1; i++) {
boolean ok = false;
for (int cutEndY = cutStartY; cutEndY < m; cutEndY++) {
int s = sum(0, cutStartY, n - 1, cutEndY);
if (s == perC * (cutsX + 1)) {
cy0[i] = cutStartY;
cy1[i] = cutEndY;
cutStartY = cutEndY + 1;
ok = true;
break;
}
}
if (!ok) {
out.println("IMPOSSIBLE");
return;
}
}
for (int i = 0; i < cutsX + 1; i++) {
for (int j = 0; j < cutsY + 1; j++) {
int s = sum(cx0[i], cy0[j], cx1[i], cy1[j]);
if (s != perC) {
out.println("IMPOSSIBLE");
return;
}
}
}
out.println("POSSIBLE");
}
}

View File

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

View File

@@ -0,0 +1,74 @@
package chelper;
import java.util.Arrays;
import io.InputReader;
import io.OutputWriter;
import misc.GCJSolution;
import misc.SimpleSavingChelperSolution;
public class TaskB extends GCJSolution {
private int m;
private long total;
private int n;
private int[] cap;
private long[] per;
private long[] c;
public void solve(int testNumber, InputReader in, OutputWriter out) {
wrapSolve(testNumber, in, out);
}
long get(long time) {
long[] g = new long[n];
for (int i = 0; i < n; i++) {
g[i] = Math.min(Math.max(0, time - c[i]) / per[i], cap[i]);
}
Arrays.sort(g);
long res = 0;
for (int i = 0; i < m; i++) {
res += g[n - i - 1];
}
return res;
}
@Override
public void solve(int testNumber) {
m = in.nextInt();
total = in.nextLong();
n = in.nextInt();
cap = new int[n];
per = new long[n];
c = new long[n];
for (int i = 0; i < n; i++) {
cap[i] = in.nextInt();
per[i] = in.nextLong();
c[i] = in.nextLong();
}
long l = 0;
long r = Long.MAX_VALUE / 3;
while (r - l > 1) {
long m = (l + r + 1) / 2;
long x = get(m);
if (x < total) {
l = m;
} else {
r = m;
}
}
out.println(r);
}
}

View File

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

View File

@@ -0,0 +1,117 @@
package chelper;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.TreeSet;
import io.InputReader;
import io.OutputWriter;
import misc.GCJSolution;
public class TaskC extends GCJSolution {
private Comparator<double[]> comparator = new Comparator<double[]>() {
@Override
public int compare(double[] o1, double[] o2) {
int t = Double.compare(o1[0], o2[0]);
if (t != 0) {
return t;
}
return -Double.compare(o1[1], o2[1]);
}
};
private int n;
private double p;
private double[] w;
private double[] h;
public void solve(int testNumber, InputReader in, OutputWriter out) {
wrapSolve(testNumber, in, out);
}
void add(TreeSet<double[]> s, double l, double r) {
double[] x = {l, r};
if (s.contains(x)) {
return;
}
while (true) {
double[] y = s.floor(x);
if (y != null && x[0] <= y[1]) {
x[0] = Math.min(x[0], y[0]);
s.remove(y);
} else {
break;
}
}
while (true) {
double[] y = s.ceiling(x);
if (y != null && x[1] >= y[0]) {
x[1] = Math.max(x[1], y[1]);
s.remove(y);
} else {
break;
}
}
s.add(x);
}
@Override
public void solve(int testNumber) {
n = in.nextInt();
p = in.nextDouble();
w = new double[n];
h = new double[n];
for (int i = 0; i < n; i++) {
w[i] = in.nextDouble();
h[i] = in.nextDouble();
}
List<double[]> a = new ArrayList<>();
double min = 0;
for (int i = 0; i < n; i++) {
min += (w[i] + h[i]) * 2;
double[] j = {Math.min(w[i], h[i]) * 2, Math.hypot(w[i], h[i]) * 2};
a.add(j);
}
a.sort(comparator);
TreeSet<double[]> s = new TreeSet<>(comparator);
s.add(new double[]{0, 0});
for (double[] x : a) {
TreeSet<double[]> ns = new TreeSet<>(comparator);
add(ns, x[0], x[1]);
for (double[] y : s) {
add(ns, y[0], y[1]);
add(ns, x[0] + y[0], x[1] + y[1]);
}
s = ns;
}
double best = 0;
p -= min;
for (double[] x : s) {
if (x[0] <= p) {
best = Math.max(best, Math.min(p, x[1]));
}
}
out.println(best + min);
}
}

View File

@@ -0,0 +1,45 @@
5 TaskC
12 MULTI_NUMBER
8 STANDARD
9 input.txt
8 STANDARD
10 output.txt
2
0
62 4
1 7
1 1
2 920
50 120
50 120
1 32
7 4
3 240
10 20
20 30
30 10
76 Case #1: 6.828427
Case #2: 920.000000
Case #3: 32.000000
Case #4: 240.000000
1
1
9 1
1 5
1 1
10 Case #1: 4
1
11 src/chelper
16 -Xmx256m -Xss64m
4 Main
13 chelper.TaskC
39 net.egork.chelper.checkers.TokenChecker
0
0
10 2018.04.14
0
1
14 io.InputReader
15 io.OutputWriter
0
0