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,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