git reimport
This commit is contained in:
64
archive/2017.03/2017.03.04 - unsorted/B.java
Normal file
64
archive/2017.03/2017.03.04 - unsorted/B.java
Normal file
@@ -0,0 +1,64 @@
|
||||
package chelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import io.InputReader;
|
||||
import io.OutputWriter;
|
||||
|
||||
public class B {
|
||||
public void solve(int testNumber, InputReader in, OutputWriter out) {
|
||||
int n = in.nextInt();
|
||||
int pol = in.nextInt();
|
||||
if (pol == 0) {
|
||||
out.print(-1);
|
||||
return;
|
||||
}
|
||||
|
||||
List<Chelik> cheliki = new ArrayList<>();
|
||||
for (int i = 2; i <= n; i++) {
|
||||
cheliki.add(new Chelik(i, in.nextInt()));
|
||||
}
|
||||
Collections.sort(cheliki);
|
||||
cheliki.add(0, new Chelik(1, pol));
|
||||
|
||||
List<String> answer = new ArrayList<>();
|
||||
|
||||
int left = 0;
|
||||
for (int right = 1; right < n; right++) {
|
||||
if (left == right) {
|
||||
out.print(-1);
|
||||
return;
|
||||
}
|
||||
if (cheliki.get(left).dzun > 0) {
|
||||
answer.add(cheliki.get(left).index + " " + cheliki.get(right).index);
|
||||
cheliki.get(left).dzun--;
|
||||
} else {
|
||||
left++;
|
||||
right--;
|
||||
}
|
||||
}
|
||||
|
||||
out.println(answer.size());
|
||||
for (String s : answer) {
|
||||
out.println(s);
|
||||
}
|
||||
}
|
||||
|
||||
class Chelik implements Comparable<Chelik> {
|
||||
int index;
|
||||
int dzun;
|
||||
|
||||
public Chelik(int index, int dzun) {
|
||||
this.index = index;
|
||||
this.dzun = dzun;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Chelik o) {
|
||||
return Integer.compare(o.dzun, dzun);
|
||||
}
|
||||
}
|
||||
}
|
37
archive/2017.03/2017.03.04 - unsorted/B.task
Normal file
37
archive/2017.03/2017.03.04 - unsorted/B.task
Normal file
@@ -0,0 +1,37 @@
|
||||
1 B
|
||||
6 SINGLE
|
||||
8 STANDARD
|
||||
9 input.txt
|
||||
8 STANDARD
|
||||
10 output.txt
|
||||
3
|
||||
0
|
||||
10
|
||||
4
|
||||
1 2 1 0
|
||||
-1
|
||||
1
|
||||
1
|
||||
13 6
|
||||
2 0 1 3 2 0
|
||||
-1
|
||||
1
|
||||
2
|
||||
7 3
|
||||
0 2 2
|
||||
-1
|
||||
1
|
||||
11 src/chelper
|
||||
16 -Xmx256m -Xss64m
|
||||
4 Main
|
||||
9 chelper.B
|
||||
39 net.egork.chelper.checkers.TokenChecker
|
||||
0
|
||||
0
|
||||
10 2017.03.04
|
||||
0
|
||||
1
|
||||
14 io.InputReader
|
||||
15 io.OutputWriter
|
||||
0
|
||||
0
|
121
archive/2017.03/2017.03.04 - unsorted/C.java
Normal file
121
archive/2017.03/2017.03.04 - unsorted/C.java
Normal file
@@ -0,0 +1,121 @@
|
||||
package chelper;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Queue;
|
||||
|
||||
import io.InputReader;
|
||||
import io.OutputWriter;
|
||||
|
||||
public class C {
|
||||
char[] dirsOrderLabels = {'D', 'L', 'R', 'U'};
|
||||
int[][] dirsOrder = {
|
||||
{1, 0}, //D
|
||||
{0, -1}, //L
|
||||
{0, 1}, //R
|
||||
{-1, 0}, //U
|
||||
};
|
||||
|
||||
public void solve(int testNumber, InputReader in, OutputWriter out) {
|
||||
int n = in.nextInt();
|
||||
int m = in.nextInt();
|
||||
int k = in.nextInt();
|
||||
|
||||
int startX = -1;
|
||||
int startY = -1;
|
||||
|
||||
boolean[][] map = new boolean[n][m];
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
String s = in.nextLine();
|
||||
for (int j = 0; j < m; j++) {
|
||||
map[i][j] = s.charAt(j) != '*';
|
||||
if (s.charAt(j) == 'X') {
|
||||
startX = i;
|
||||
startY = j;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int[][] distances = new int[n][m];
|
||||
for (int i = 0; i < n; i++) {
|
||||
Arrays.fill(distances[i], Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
Queue<int[]> queue = new LinkedList<>();
|
||||
queue.add(new int[]{startX, startY});
|
||||
distances[startX][startY] = 0;
|
||||
|
||||
while (!queue.isEmpty()) {
|
||||
int[] posAr = queue.poll();
|
||||
int x = posAr[0];
|
||||
int y = posAr[1];
|
||||
|
||||
for (int[] dir : dirsOrder) {
|
||||
int xx = x + dir[0];
|
||||
int yy = y + dir[1];
|
||||
|
||||
if (xx < 0 || xx >= n || yy < 0 || yy >= m) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!map[xx][yy]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (distances[xx][yy] <= distances[x][y] + 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
distances[xx][yy] = distances[x][y] + 1;
|
||||
queue.add(new int[]{xx, yy});
|
||||
}
|
||||
}
|
||||
|
||||
StringBuilder answer = new StringBuilder();
|
||||
|
||||
int x = startX;
|
||||
int y = startY;
|
||||
int timeLeft = k;
|
||||
|
||||
while (timeLeft >= distances[x][y] && timeLeft > 0) {
|
||||
boolean ok = false;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
int[] dir = dirsOrder[i];
|
||||
int xx = x + dir[0];
|
||||
int yy = y + dir[1];
|
||||
|
||||
if (xx < 0 || xx >= n || yy < 0 || yy >= m) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!map[xx][yy]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (timeLeft == distances[x][y] && distances[xx][yy] >= distances[x][y]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ok = true;
|
||||
x = xx;
|
||||
y = yy;
|
||||
timeLeft--;
|
||||
answer.append(dirsOrderLabels[i]);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!ok) {
|
||||
out.println("IMPOSSIBLE");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (timeLeft != 0 || x != startX || y != startY) {
|
||||
out.println("IMPOSSIBLE");
|
||||
return;
|
||||
}
|
||||
|
||||
out.println(answer);
|
||||
}
|
||||
}
|
81
archive/2017.03/2017.03.04 - unsorted/C.task
Normal file
81
archive/2017.03/2017.03.04 - unsorted/C.task
Normal file
@@ -0,0 +1,81 @@
|
||||
1 C
|
||||
6 SINGLE
|
||||
8 STANDARD
|
||||
9 input.txt
|
||||
8 STANDARD
|
||||
10 output.txt
|
||||
9
|
||||
0
|
||||
13 2 3 2
|
||||
.**
|
||||
X..
|
||||
2 RL
|
||||
1
|
||||
1
|
||||
41 5 6 14
|
||||
..***.
|
||||
*...X.
|
||||
..*...
|
||||
..*.**
|
||||
....*.
|
||||
14 DLDDLLLRRRUURU
|
||||
1
|
||||
2
|
||||
17 3 3 4
|
||||
***
|
||||
*X*
|
||||
***
|
||||
11 IMPOSSIBLE
|
||||
|
||||
1
|
||||
3
|
||||
13 2 3 4
|
||||
.**
|
||||
X..
|
||||
-1
|
||||
1
|
||||
4
|
||||
29 4 5 5
|
||||
*****
|
||||
*X***
|
||||
*.***
|
||||
*.***
|
||||
-1
|
||||
1
|
||||
5
|
||||
11 2 2 1
|
||||
.X
|
||||
..
|
||||
10 IMPOSSIBLE
|
||||
1
|
||||
6
|
||||
11 2 2 4
|
||||
.X
|
||||
..
|
||||
4 DLRU
|
||||
1
|
||||
7
|
||||
7 1 1 2
|
||||
X
|
||||
10 IMPOSSIBLE
|
||||
1
|
||||
8
|
||||
9 2 1 2
|
||||
X
|
||||
.
|
||||
2 DU
|
||||
1
|
||||
11 src/chelper
|
||||
16 -Xmx256m -Xss64m
|
||||
4 Main
|
||||
9 chelper.C
|
||||
39 net.egork.chelper.checkers.TokenChecker
|
||||
0
|
||||
0
|
||||
10 2017.03.04
|
||||
0
|
||||
1
|
||||
14 io.InputReader
|
||||
15 io.OutputWriter
|
||||
0
|
||||
0
|
45
archive/2017.03/2017.03.05 - unsorted/D.java
Normal file
45
archive/2017.03/2017.03.05 - unsorted/D.java
Normal file
@@ -0,0 +1,45 @@
|
||||
package chelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import io.InputReader;
|
||||
import io.OutputWriter;
|
||||
|
||||
public class D {
|
||||
public void solve(int testNumber, InputReader in, OutputWriter out) {
|
||||
int n = in.nextInt();
|
||||
int k = in.nextInt();
|
||||
int M = 1 << 16;
|
||||
int[] a = new int[M];
|
||||
for (int i = 0; i < n; i++) {
|
||||
int x = in.nextInt();
|
||||
a[x]++;
|
||||
}
|
||||
|
||||
List<Integer> masks = new ArrayList<>();
|
||||
for (int i = 0; i < M; i++) {
|
||||
if (Integer.bitCount(i) == k) {
|
||||
masks.add(i);
|
||||
}
|
||||
}
|
||||
|
||||
long answer = 0;
|
||||
for (int i = 0; i < M; i++) {
|
||||
if (a[i] == 0) {
|
||||
continue;
|
||||
}
|
||||
for (int mask : masks) {
|
||||
if ((i ^ mask) < i) {
|
||||
answer += a[i] * a[i ^ mask];
|
||||
}
|
||||
if ((i ^ mask) == i) {
|
||||
answer += a[i] * (a[i] - 1) / 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
out.println(answer);
|
||||
}
|
||||
|
||||
}
|
31
archive/2017.03/2017.03.05 - unsorted/D.task
Normal file
31
archive/2017.03/2017.03.05 - unsorted/D.task
Normal file
@@ -0,0 +1,31 @@
|
||||
1 D
|
||||
6 SINGLE
|
||||
8 STANDARD
|
||||
9 input.txt
|
||||
8 STANDARD
|
||||
10 output.txt
|
||||
2
|
||||
0
|
||||
11 4 1
|
||||
0 3 2 1
|
||||
1 4
|
||||
1
|
||||
1
|
||||
27 6 0
|
||||
200 100 100 100 200 200
|
||||
1 6
|
||||
1
|
||||
11 src/chelper
|
||||
16 -Xmx256m -Xss64m
|
||||
4 Main
|
||||
9 chelper.D
|
||||
39 net.egork.chelper.checkers.TokenChecker
|
||||
0
|
||||
0
|
||||
10 2017.03.05
|
||||
0
|
||||
1
|
||||
14 io.InputReader
|
||||
15 io.OutputWriter
|
||||
0
|
||||
0
|
62
archive/2017.03/2017.03.11 - unsorted/D.java
Normal file
62
archive/2017.03/2017.03.11 - unsorted/D.java
Normal file
@@ -0,0 +1,62 @@
|
||||
package chelper;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import io.InputReader;
|
||||
import io.OutputWriter;
|
||||
|
||||
public class D {
|
||||
public void solve(int testNumber, InputReader in, OutputWriter out) {
|
||||
int n = in.nextInt();
|
||||
char[] seq = in.nextLine().toCharArray();
|
||||
|
||||
int x[] = new int[n];
|
||||
int y[] = new int[n];
|
||||
int currentDepth = 0;
|
||||
int maxDepth = 0;
|
||||
|
||||
int w = 0;
|
||||
for (int i = 0; i < n; i++) {
|
||||
if (seq[i] == '[') {
|
||||
currentDepth++;
|
||||
w++;
|
||||
}
|
||||
maxDepth = Math.max(maxDepth, currentDepth);
|
||||
y[i] = currentDepth;
|
||||
if (seq[i] == ']') {
|
||||
currentDepth--;
|
||||
w++;
|
||||
if (seq[i - 1] == '[') {
|
||||
w += 3;
|
||||
}
|
||||
}
|
||||
x[i] = w - 1;
|
||||
}
|
||||
|
||||
int h = maxDepth * 2 + 1;
|
||||
|
||||
char[][] answer = new char[h][w];
|
||||
|
||||
for (int i = 0; i < h; i++) {
|
||||
Arrays.fill(answer[i], ' ');
|
||||
}
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
for (int j = 0; j <= maxDepth - y[i]; j++) {
|
||||
answer[h / 2 - j][x[i]] = '|';
|
||||
answer[h / 2 + j][x[i]] = '|';
|
||||
}
|
||||
answer[h / 2 - (maxDepth - y[i] + 1)][x[i]] = '+';
|
||||
answer[h / 2 + (maxDepth - y[i] + 1)][x[i]] = '+';
|
||||
|
||||
int dx = seq[i] == '[' ? 1 : -1;
|
||||
|
||||
answer[h / 2 - (maxDepth - y[i] + 1)][x[i] + dx] = '-';
|
||||
answer[h / 2 + (maxDepth - y[i] + 1)][x[i] + dx] = '-';
|
||||
}
|
||||
|
||||
for (int i = 0; i < h; i++) {
|
||||
out.println(new String(answer[i]));
|
||||
}
|
||||
}
|
||||
}
|
74
archive/2017.03/2017.03.11 - unsorted/D.task
Normal file
74
archive/2017.03/2017.03.11 - unsorted/D.task
Normal file
@@ -0,0 +1,74 @@
|
||||
1 D
|
||||
6 SINGLE
|
||||
8 STANDARD
|
||||
9 input.txt
|
||||
8 STANDARD
|
||||
10 output.txt
|
||||
7
|
||||
0
|
||||
10 8
|
||||
[[][]][]
|
||||
89 +- -++- -+
|
||||
|+- -++- -+|| |
|
||||
|| || ||| |
|
||||
|+- -++- -+|| |
|
||||
+- -++- -+
|
||||
1
|
||||
1
|
||||
8 6
|
||||
[[[]]]
|
||||
69 +- -+
|
||||
|+- -+|
|
||||
||+- -+||
|
||||
||| |||
|
||||
||+- -+||
|
||||
|+- -+|
|
||||
+- -+
|
||||
1
|
||||
2
|
||||
8 6
|
||||
[[][]]
|
||||
64 +- -+
|
||||
|+- -++- -+|
|
||||
|| || ||
|
||||
|+- -++- -+|
|
||||
+- -+
|
||||
1
|
||||
3
|
||||
4 2
|
||||
[]
|
||||
17 +- -+
|
||||
| |
|
||||
+- -+
|
||||
1
|
||||
4
|
||||
6 4
|
||||
[][]
|
||||
32 +- -++- -+
|
||||
| || |
|
||||
+- -++- -+
|
||||
1
|
||||
5
|
||||
19 16
|
||||
[[[[[][]][]][]]]
|
||||
-1
|
||||
1
|
||||
6
|
||||
104 100
|
||||
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
|
||||
-1
|
||||
1
|
||||
11 src/chelper
|
||||
16 -Xmx256m -Xss64m
|
||||
4 Main
|
||||
9 chelper.D
|
||||
39 net.egork.chelper.checkers.TokenChecker
|
||||
0
|
||||
0
|
||||
10 2017.03.11
|
||||
0
|
||||
1
|
||||
14 io.InputReader
|
||||
15 io.OutputWriter
|
||||
0
|
||||
0
|
@@ -0,0 +1,58 @@
|
||||
33 A - Bear and Friendship Condition
|
||||
6 SINGLE
|
||||
8 STANDARD
|
||||
-1
|
||||
8 STANDARD
|
||||
-1
|
||||
4
|
||||
0
|
||||
16 4 3
|
||||
1 3
|
||||
3 4
|
||||
1 4
|
||||
|
||||
4 YES
|
||||
|
||||
1
|
||||
1
|
||||
20 4 4
|
||||
3 1
|
||||
2 3
|
||||
3 4
|
||||
1 2
|
||||
|
||||
3 NO
|
||||
|
||||
1
|
||||
2
|
||||
22 10 4
|
||||
4 3
|
||||
5 10
|
||||
8 9
|
||||
1 2
|
||||
|
||||
4 YES
|
||||
|
||||
1
|
||||
3
|
||||
12 3 2
|
||||
1 2
|
||||
2 3
|
||||
|
||||
3 NO
|
||||
|
||||
1
|
||||
11 src/chelper
|
||||
8 -Xmx256M
|
||||
4 Main
|
||||
13 chelper.TaskA
|
||||
39 net.egork.chelper.checkers.TokenChecker
|
||||
0
|
||||
0
|
||||
10 2017.03.18
|
||||
21 VK Cup 2017 - Round 1
|
||||
1
|
||||
14 io.InputReader
|
||||
15 io.OutputWriter
|
||||
0
|
||||
0
|
@@ -0,0 +1,39 @@
|
||||
28 B - Bear and Different Names
|
||||
6 SINGLE
|
||||
8 STANDARD
|
||||
-1
|
||||
8 STANDARD
|
||||
-1
|
||||
3
|
||||
0
|
||||
25 8 3
|
||||
NO NO YES YES YES NO
|
||||
|
||||
42 Adam Bob Bob Cpqepqwer Limak Adam Bob Adam
|
||||
1
|
||||
1
|
||||
11 9 8
|
||||
YES NO
|
||||
|
||||
45 R Q Ccccccccc Ccocc Ccc So Strong Samples Ccc
|
||||
1
|
||||
2
|
||||
10 3 2
|
||||
NO NO
|
||||
|
||||
8 Na Na Na
|
||||
1
|
||||
11 src/chelper
|
||||
8 -Xmx256M
|
||||
4 Main
|
||||
13 chelper.TaskB
|
||||
39 net.egork.chelper.checkers.TokenChecker
|
||||
0
|
||||
0
|
||||
10 2017.03.18
|
||||
21 VK Cup 2017 - Round 1
|
||||
1
|
||||
14 io.InputReader
|
||||
15 io.OutputWriter
|
||||
0
|
||||
0
|
@@ -0,0 +1,58 @@
|
||||
23 C - Bear and Tree Jumps
|
||||
6 SINGLE
|
||||
8 STANDARD
|
||||
-1
|
||||
8 STANDARD
|
||||
-1
|
||||
3
|
||||
0
|
||||
24 6 2
|
||||
1 2
|
||||
1 3
|
||||
2 4
|
||||
2 5
|
||||
4 6
|
||||
|
||||
3 20
|
||||
|
||||
1
|
||||
1
|
||||
58 13 3
|
||||
1 2
|
||||
3 2
|
||||
4 2
|
||||
5 2
|
||||
3 6
|
||||
10 6
|
||||
6 7
|
||||
6 13
|
||||
5 8
|
||||
5 9
|
||||
9 11
|
||||
11 12
|
||||
|
||||
4 114
|
||||
|
||||
1
|
||||
2
|
||||
12 3 5
|
||||
2 1
|
||||
3 1
|
||||
|
||||
2 3
|
||||
|
||||
1
|
||||
11 src/chelper
|
||||
8 -Xmx256M
|
||||
4 Main
|
||||
13 chelper.TaskC
|
||||
39 net.egork.chelper.checkers.TokenChecker
|
||||
0
|
||||
0
|
||||
10 2017.03.18
|
||||
21 VK Cup 2017 - Round 1
|
||||
1
|
||||
14 io.InputReader
|
||||
15 io.OutputWriter
|
||||
0
|
||||
0
|
@@ -0,0 +1,56 @@
|
||||
20 D - Bear and Company
|
||||
6 SINGLE
|
||||
8 STANDARD
|
||||
-1
|
||||
8 STANDARD
|
||||
-1
|
||||
5
|
||||
0
|
||||
7 4
|
||||
VKVK
|
||||
|
||||
2 3
|
||||
|
||||
1
|
||||
1
|
||||
8 5
|
||||
BVVKV
|
||||
|
||||
2 2
|
||||
|
||||
1
|
||||
2
|
||||
10 7
|
||||
VVKEVKK
|
||||
|
||||
2 3
|
||||
|
||||
1
|
||||
3
|
||||
24 20
|
||||
VKVKVVVKVOVKVQKKKVVK
|
||||
|
||||
2 8
|
||||
|
||||
1
|
||||
4
|
||||
8 5
|
||||
LIMAK
|
||||
|
||||
2 0
|
||||
|
||||
1
|
||||
11 src/chelper
|
||||
8 -Xmx256M
|
||||
4 Main
|
||||
13 chelper.TaskD
|
||||
39 net.egork.chelper.checkers.TokenChecker
|
||||
0
|
||||
0
|
||||
10 2017.03.18
|
||||
21 VK Cup 2017 - Round 1
|
||||
1
|
||||
14 io.InputReader
|
||||
15 io.OutputWriter
|
||||
0
|
||||
0
|
@@ -0,0 +1,45 @@
|
||||
29 E - Bear and Rectangle Strips
|
||||
6 SINGLE
|
||||
8 STANDARD
|
||||
-1
|
||||
8 STANDARD
|
||||
-1
|
||||
3
|
||||
0
|
||||
42 6
|
||||
70 70 70 70 70 -15
|
||||
90 -60 -30 30 -30 15
|
||||
|
||||
2 3
|
||||
|
||||
1
|
||||
1
|
||||
19 4
|
||||
0 -1 0 0
|
||||
0 0 1 0
|
||||
|
||||
2 6
|
||||
|
||||
1
|
||||
2
|
||||
68 3
|
||||
1000000000 999999999 -1000000000
|
||||
999999999 -1000000000 -999999998
|
||||
|
||||
2 1
|
||||
|
||||
1
|
||||
11 src/chelper
|
||||
8 -Xmx256M
|
||||
4 Main
|
||||
13 chelper.TaskE
|
||||
39 net.egork.chelper.checkers.TokenChecker
|
||||
0
|
||||
0
|
||||
10 2017.03.18
|
||||
21 VK Cup 2017 - Round 1
|
||||
1
|
||||
14 io.InputReader
|
||||
15 io.OutputWriter
|
||||
0
|
||||
0
|
@@ -0,0 +1,49 @@
|
||||
30 F - Bear and Isomorphic Points
|
||||
6 SINGLE
|
||||
8 STANDARD
|
||||
-1
|
||||
8 STANDARD
|
||||
-1
|
||||
1
|
||||
0
|
||||
109 4
|
||||
4
|
||||
5 3
|
||||
0 1
|
||||
10 1
|
||||
3 51
|
||||
3
|
||||
-999123 700000
|
||||
-950000 123456
|
||||
-950000 987654
|
||||
3
|
||||
2 3
|
||||
10 -1
|
||||
-4 6
|
||||
5
|
||||
1 3
|
||||
5 2
|
||||
6 1
|
||||
4 4
|
||||
-3 3
|
||||
|
||||
73 250.000000000000
|
||||
100000000000.000000000000
|
||||
0.000000000000
|
||||
6.562500000000
|
||||
|
||||
1
|
||||
11 src/chelper
|
||||
8 -Xmx256M
|
||||
4 Main
|
||||
13 chelper.TaskF
|
||||
39 net.egork.chelper.checkers.TokenChecker
|
||||
0
|
||||
0
|
||||
10 2017.03.18
|
||||
21 VK Cup 2017 - Round 1
|
||||
1
|
||||
14 io.InputReader
|
||||
15 io.OutputWriter
|
||||
0
|
||||
0
|
@@ -0,0 +1,9 @@
|
||||
package chelper;
|
||||
|
||||
import io.InputReader;
|
||||
import io.OutputWriter;
|
||||
|
||||
public class TaskA {
|
||||
public void solve(int testNumber, InputReader in, OutputWriter out) {
|
||||
}
|
||||
}
|
@@ -0,0 +1,9 @@
|
||||
package chelper;
|
||||
|
||||
import io.InputReader;
|
||||
import io.OutputWriter;
|
||||
|
||||
public class TaskB {
|
||||
public void solve(int testNumber, InputReader in, OutputWriter out) {
|
||||
}
|
||||
}
|
128
archive/2017.03/2017.03.18 - VK Cup 2017 - Round 1/TaskC.java
Normal file
128
archive/2017.03/2017.03.18 - VK Cup 2017 - Round 1/TaskC.java
Normal file
@@ -0,0 +1,128 @@
|
||||
package chelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import io.InputReader;
|
||||
import io.OutputWriter;
|
||||
|
||||
public class TaskC {
|
||||
int n, k;
|
||||
List<List<Integer>> edges;
|
||||
|
||||
long ans = 0;
|
||||
|
||||
long[] rotCount(long[] x) {
|
||||
long[] res = new long[k];
|
||||
for (int i = 0; i < k; i++) {
|
||||
res[i] = x[(i - 1 + k) % k];
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
long[] rotAcc(long[] x) {
|
||||
long[] res = new long[k];
|
||||
for (int i = 0; i < k; i++) {
|
||||
res[i] = x[(i - 1 + k) % k];
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
long[] copy(long[] x) {
|
||||
return Arrays.copyOf(x, k);
|
||||
}
|
||||
|
||||
void add(long[] a, long[] b) {
|
||||
for (int i = 0; i < k; i++) {
|
||||
a[i] += b[i];
|
||||
}
|
||||
}
|
||||
|
||||
public void solve(int testNumber, InputReader in, OutputWriter out) {
|
||||
n = in.nextInt();
|
||||
k = in.nextInt();
|
||||
|
||||
visited = new boolean[n];
|
||||
|
||||
edges = new ArrayList<>();
|
||||
for (int i = 0; i < n; i++) {
|
||||
edges.add(new ArrayList<>());
|
||||
}
|
||||
|
||||
for (int i = 0; i < n - 1; i++) {
|
||||
int a = in.nextInt() - 1;
|
||||
int b = in.nextInt() - 1;
|
||||
|
||||
edges.get(a).add(b);
|
||||
edges.get(b).add(a);
|
||||
}
|
||||
|
||||
// long[] count = new long[k];
|
||||
long[] acc = new long[k];
|
||||
|
||||
Result ans = dfs(0, 0, acc);
|
||||
|
||||
out.println(ans.cost / 2);
|
||||
}
|
||||
|
||||
class Result {
|
||||
long cost;
|
||||
long[] acc;
|
||||
|
||||
public Result(long cost, long[] acc) {
|
||||
this.cost = cost;
|
||||
this.acc = acc;
|
||||
}
|
||||
}
|
||||
|
||||
boolean[] visited;
|
||||
|
||||
// void addComp(long[] a, long[] b) {
|
||||
// for (int i = 0; i < k; i++) {
|
||||
// for (int j = 0; j < k; j++) {
|
||||
// if (i == j) {
|
||||
// continue;
|
||||
// }
|
||||
// long t = a[i] + b[j];
|
||||
// if (i + j >= k) {
|
||||
// ans += ;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
Result dfs(int v, long parentCost, long[] accParent) {
|
||||
visited[v] = true;
|
||||
|
||||
long costParentChildren = parentCost;
|
||||
long costChildren = 0;
|
||||
|
||||
long[] accParentChildren = new long[k];
|
||||
costParentChildren += rot(accParentChildren, accParent);
|
||||
accParentChildren[0] += 1;
|
||||
|
||||
long[] accChildren = new long[k];
|
||||
accChildren[0] += 1;
|
||||
|
||||
for (Integer child : edges.get(v)) {
|
||||
if (visited[child]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Result atChild = dfs(child, costParentChildren, accParentChildren);
|
||||
|
||||
long[] childAcc = new long[k];
|
||||
|
||||
costChildren += atChild.cost;
|
||||
costChildren += rot(childAcc, atChild.acc);
|
||||
costParentChildren += atChild.cost;
|
||||
costParentChildren += rot(childAcc, atChild.acc);
|
||||
|
||||
add(accParentChildren, childAcc);
|
||||
add(accChildren, childAcc);
|
||||
}
|
||||
|
||||
return new Result(costChildren, accChildren);
|
||||
}
|
||||
}
|
@@ -0,0 +1,43 @@
|
||||
package chelper;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import io.InputReader;
|
||||
import io.OutputWriter;
|
||||
|
||||
public class TaskD {
|
||||
public void solve(int testNumber, InputReader in, OutputWriter out) {
|
||||
int n = in.nextInt();
|
||||
char[] a = in.nextString().toCharArray();
|
||||
|
||||
char c1 = 'V';
|
||||
char c2 = 'K';
|
||||
|
||||
int[][] dp = new int[n][3];
|
||||
for (int i = 0; i < n; i++) {
|
||||
Arrays.fill(dp[i], 100000);
|
||||
}
|
||||
|
||||
if (a[0] == c1) {
|
||||
dp[0][0] = 0;
|
||||
} else if (a[0] == c2) {
|
||||
dp[0][1] = 0;
|
||||
} else {
|
||||
dp[0][2] = 0;
|
||||
}
|
||||
|
||||
for (int i = 1; i < n; i++) {
|
||||
if (a[i] == c1) {
|
||||
dp[i][2] = Math.min(dp[i][2], dp[i - 1][0]);
|
||||
dp[i][2] = Math.min(dp[i][2], dp[i - 1][1]);
|
||||
dp[i][2] = Math.min(dp[i][2], dp[i - 1][2]);
|
||||
} else if (a[i] == c2) {
|
||||
|
||||
} else {
|
||||
dp[i][2] = Math.min(dp[i][2], dp[i - 1][0]);
|
||||
dp[i][2] = Math.min(dp[i][2], dp[i - 1][1]);
|
||||
dp[i][2] = Math.min(dp[i][2], dp[i - 1][2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,9 @@
|
||||
package chelper;
|
||||
|
||||
import io.InputReader;
|
||||
import io.OutputWriter;
|
||||
|
||||
public class TaskE {
|
||||
public void solve(int testNumber, InputReader in, OutputWriter out) {
|
||||
}
|
||||
}
|
@@ -0,0 +1,9 @@
|
||||
package chelper;
|
||||
|
||||
import io.InputReader;
|
||||
import io.OutputWriter;
|
||||
|
||||
public class TaskF {
|
||||
public void solve(int testNumber, InputReader in, OutputWriter out) {
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user