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,54 @@
package chelper;
import java.util.SortedSet;
import java.util.TreeSet;
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);
}
@Override
public void solve(int testNumber) {
int l = in.nextInt();
SortedSet<Pair> team = new TreeSet<>();
for (int i = 0; i < l; i++) {
long count = in.nextLong();
int exp = in.nextInt();
team.add(new Pair(count, exp));
}
long leftovers = 0;
for (Pair manager : team) {
long capacity = manager.count * manager.experience;
long canAttach = Math.min(leftovers, capacity);
leftovers = manager.count + leftovers - canAttach;
}
int maxExp = team.last().experience;
out.println(Math.max(leftovers, maxExp));
}
class Pair implements Comparable<Pair> {
long count;
int experience;
public Pair(long count, int experience) {
this.count = count;
this.experience = experience;
}
@Override
public int compareTo(Pair o) {
return Integer.compare(this.experience, o.experience);
}
}
}

View File

@@ -0,0 +1,32 @@
5 TaskB
6 SINGLE
8 STANDARD
9 input.txt
8 STANDARD
10 output.txt
1
0
21 2
3
2 0
2 2
1 3
1
5 0
21 Case #1: 4
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.02.17
0
1
14 io.InputReader
15 io.OutputWriter
0
0

View File

@@ -0,0 +1,54 @@
package chelper;
import java.util.SortedSet;
import java.util.TreeSet;
import io.InputReader;
import io.OutputWriter;
import misc.SimpleSavingChelperSolution;
public class TaskB2 extends SimpleSavingChelperSolution {
public void solve(int testNumber, InputReader in, OutputWriter out) {
wrapSolve(testNumber, in, out);
}
@Override
public void solve(int testNumber) {
int l = in.nextInt();
SortedSet<Pair> team = new TreeSet<>();
for (int i = 0; i < l; i++) {
long count = in.nextLong();
int exp = in.nextInt();
team.add(new Pair(count, exp));
}
long leftovers = 0;
for (Pair manager : team) {
long capacity = manager.count * manager.experience;
long canAttach = Math.min(leftovers, capacity);
leftovers = manager.count + leftovers - canAttach;
}
int maxExp = team.last().experience;
out.println(Math.max(leftovers, maxExp + 1));
}
class Pair implements Comparable<Pair> {
long count;
int experience;
public Pair(long count, int experience) {
this.count = count;
this.experience = experience;
}
@Override
public int compareTo(Pair o) {
return Integer.compare(this.experience, o.experience);
}
}
}

View File

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

View File

@@ -0,0 +1,102 @@
package chelper;
import io.InputReader;
import io.OutputWriter;
import misc.GCJSolution;
import misc.SimpleSavingChelperSolution;
public class TaskD extends GCJSolution {
public void solve(int testNumber, InputReader in, OutputWriter out) {
wrapSolve(testNumber, in, out);
}
double[][][] dp;
public TaskD() {
super();
dp = new double[101][101][101];
for (int c = 0; c <= 100; c++) {
for (int b = 0; b <= 100; b++) {
for (int a = 0; a <= 100; a++) {
dp[a][b][c] = Double.NaN;
}
}
}
dp[0][0][0] = 0;
get(0, 0, 100);
// for (int c = 0; c <= 2; c++) {
// for (int b = 0; b <= 2; b++) {
// for (int a = 0; a <= 2; a++) {
// System.out.println(a + " " + b + " " + c + " " + dp[a][b][c]);
// }
// }
// }
}
@Override
public void solve(int testNumber) {
int n = in.nextInt();
out.println(get(0, 0, n));
}
double get(int a, int b, int c) {
if (a < 0 || b < 0 || c < 0) {
return 0;
}
if (Double.isNaN(dp[a][b][c])) {
calc(a, b, c);
}
return dp[a][b][c];
}
void calc(int a, int b, int c) {
double aa = a;
double bb = 2 * b;
double cc = 3 * c;
double n = aa + bb + cc;
//////////////
dp[a][b][c] = 0;
if (n >= 3) {
dp[a][b][c] += (cc / n) * (2 / (n - 1)) * (1 / (n - 2)) * (get(a + 0, b + 0, c - 1) + 1 + 0);
dp[a][b][c] += (cc / n) * (2 / (n - 1)) * (aa / (n - 2)) * (get(a + 0, b + 0, c - 1) + 1 + 1);
dp[a][b][c] += (cc / n) * (2 / (n - 1)) * (bb / (n - 2)) * (get(a + 2, b - 1, c - 1) + 1 + 0);
dp[a][b][c] += (cc / n) * (2 / (n - 1)) * ((cc - 3) / (n - 2)) * (get(a + 1, b + 1, c - 2) + 1 + 0);
}
if (n >= 2) {
dp[a][b][c] += (cc / n) * (aa / (n - 1)) * (get(a - 1, b + 1, c - 1) + 1 + 1);
dp[a][b][c] += (cc / n) * (bb / (n - 1)) * (get(a + 1, b + 0, c - 1) + 1 + 0);
dp[a][b][c] += (cc / n) * ((cc - 3) / (n - 1)) * (get(a + 0, b + 2, c - 2) + 1 + 0);
}
//////////////
if (n >= 2) {
dp[a][b][c] += (bb / n) * (1 / (n - 1)) * (get(a + 0, b - 1, c + 0) + 1 + 0);
dp[a][b][c] += (bb / n) * (aa / (n - 1)) * (get(a + 0, b - 1, c + 0) + 1 + 1);
dp[a][b][c] += (bb / n) * ((bb - 2) / (n - 1)) * (get(a + 2, b - 2, c + 0) + 1 + 0);
dp[a][b][c] += (bb / n) * (cc / (n - 1)) * (get(a + 1, b + 0, c - 1) + 1 + 0);
}
//////////////
dp[a][b][c] += (aa / n) * (get(a - 1, b + 0, c + 0) + 1);
}
}

View File

@@ -0,0 +1,150 @@
5 TaskD
12 MULTI_NUMBER
8 STANDARD
9 input.txt
8 STANDARD
10 output.txt
4
0
7 3
1
2
5
53 Case #1: 1.000000
Case #2: 3.400000
Case #3: 9.842024
1
1
3 1
1
-1
0
2
12 5
1
2
5
3
4
-1
1
3
296 100
1
2
5
100
86
7
45
34
89
49
91
35
3
76
79
75
53
70
95
14
72
69
8
10
36
18
28
16
73
63
33
44
55
32
98
50
65
97
21
30
78
59
22
60
74
19
88
52
66
77
29
26
82
42
12
90
61
23
48
62
56
83
51
58
15
46
67
87
13
25
4
20
43
41
68
93
27
38
84
6
24
39
47
80
85
99
37
40
17
54
92
57
31
64
71
81
11
9
94
96
-1
1
11 src/chelper
16 -Xmx256m -Xss64m
4 Main
13 chelper.TaskD
39 net.egork.chelper.checkers.TokenChecker
0
0
10 2018.02.17
0
1
14 io.InputReader
15 io.OutputWriter
0
0

View File

@@ -0,0 +1,74 @@
package chelper;
import java.util.ArrayList;
import java.util.List;
import io.InputReader;
import io.OutputWriter;
import misc.GCJSolution;
import misc.SimpleSavingChelperSolution;
public class TaskС extends GCJSolution {
public void solve(int testNumber, InputReader in, OutputWriter out) {
wrapSolve(testNumber, in, out);
}
int l;
@Override
public void solve(int testNumber) {
l = in.nextInt();
char[] ac = in.nextString().toCharArray();
char[] bc = in.nextString().toCharArray();
char[] cc = in.nextString().toCharArray();
int[] a = new int[l];
int[] b = new int[l];
int[] c = new int[l];
for (int i = 0; i < l; i++) {
a[i] = ac[i] - 'A';
b[i] = bc[i] - 'A';
c[i] = cc[i] - 'A';
}
boolean ok1 = possible(b, a, c) || possible(c, a, b);
boolean ok2 = possible(a, b, c) || possible(c, b, a);
boolean ok3 = possible(a, c, b) || possible(b, c, a);
out.print(ok1 ? "YES" : "NO");
out.print(" ");
out.print(ok2 ? "YES" : "NO");
out.print(" ");
out.print(ok3 ? "YES" : "NO");
out.println();
}
boolean possible(int[] a, int[] b, int[] c) {
int a0 = -1;
int a1 = -1;
int b0 = -1;
int b1 = -1;
for (int i = 0; i < l; i++) {
if (a[i] != b[i]) {
a0 = a[i];
a1 = b[i];
break;
}
}
for (int i = 0; i < l; i++) {
if (b[i] != c[i]) {
b0 = b[i];
b1 = c[i];
break;
}
}
return !(a0 == b1 && a1 == b0);
}
}

View File

@@ -0,0 +1,33 @@
6 TaskС
12 MULTI_NUMBER
8 STANDARD
9 input.txt
8 STANDARD
10 output.txt
1
0
49 3
3
BCB CAB CBC
2
CC CA AA
6
MEDIAN MEDIAL MEDIAS
59 Case #1: NO YES YES
Case #2: NO YES NO
Case #3: YES YES YES
1
11 src/chelper
16 -Xmx256m -Xss64m
4 Main
14 chelper.TaskС
39 net.egork.chelper.checkers.TokenChecker
0
0
10 2018.02.17
0
1
14 io.InputReader
15 io.OutputWriter
0
0

View File

@@ -0,0 +1,39 @@
package chelper;
import java.util.HashSet;
import java.util.Set;
import io.InputReader;
import io.OutputWriter;
import misc.SimpleSavingChelperSolution;
public class A extends SimpleSavingChelperSolution {
public void solve(int testNumber, InputReader in, OutputWriter out) {
wrapSolve(testNumber, in, out);
}
@Override
public void solve(int testNumber) {
Set<Integer> lucky = new HashSet<>();
for (int i = 0; i < 10; i++) {
lucky.add(in.nextInt());
}
int n = in.nextInt();
for (int i = 0; i < n; i++) {
int luckyCount = 0;
for (int j = 0; j < 6; j++) {
if (lucky.contains(in.nextInt())) {
luckyCount++;
}
}
out.println(luckyCount >= 3 ? "Lucky" : "Unlucky");
}
}
}

View File

@@ -0,0 +1,31 @@
1 A
6 SINGLE
8 STANDARD
9 input.txt
8 STANDARD
10 output.txt
1
0
69 1 2 3 4 5 6 7 8 9 32
3
1 2 10 11 12 13
1 2 3 10 11 12
32 1 10 20 30 3
19 Unlucky
Lucky
Lucky
1
11 src/chelper
16 -Xmx256m -Xss64m
4 Main
9 chelper.A
39 net.egork.chelper.checkers.TokenChecker
0
0
10 2018.02.18
0
1
14 io.InputReader
15 io.OutputWriter
0
0

View File

@@ -0,0 +1,84 @@
package chelper;
import io.InputReader;
import io.OutputWriter;
import misc.SimpleSavingChelperSolution;
public class B extends SimpleSavingChelperSolution {
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[2 * n][n];
for (int i = 0; i < 2 * n; i++) {
for (int j = 0; j < n; j++) {
a[i][j] = in.nextInt();
}
}
int p1 = -1;
int p2 = -1;
for (int i = 0; i < 2 * n; i++) {
for (int j = i + 1; j < 2 * n; j++) {
if (a[i][0] == a[j][0]) {
p1 = i;
p2 = j;
}
}
}
int[][] res = new int[n][n];
for (int i = 0; i < n; i++) {
res[0][i] = a[p1][i];
res[i][0] = a[p2][i];
}
for (int i = 0; i < 2 * n; i++) {
if (i == p1 || i == p2) {
continue;
}
int p = -1;
for (int j = 0; j < n; j++) {
if (res[0][j] == a[i][0]) {
p = j;
break;
}
}
if (p >= 0) {
for (int j = 0; j < n; j++) {
res[j][p] = a[i][j];
}
continue;
}
for (int j = 0; j < n; j++) {
if (res[j][0] == a[i][0]) {
p = j;
break;
}
}
for (int j = 0; j < n; j++) {
res[p][j] = a[i][j];
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
out.print(res[i][j] + " ");
}
}
}
}

View File

@@ -0,0 +1,41 @@
1 B
6 SINGLE
8 STANDARD
9 input.txt
8 STANDARD
10 output.txt
2
0
17 2
1 2
1 3
2 4
3 4
7 1 2 3 4
0
1
79 4
1 6 14 7
5 4 1 13
13 16 12 10
8 3 6 16
11 2 7 10
15 9 14 12
4 3 9 2
5 8 15 11
38 5 4 1 13 8 3 6 16 15 9 14 12 11 2 7 10
1
11 src/chelper
16 -Xmx256m -Xss64m
4 Main
9 chelper.B
39 net.egork.chelper.checkers.TokenChecker
0
0
10 2018.02.18
0
1
14 io.InputReader
15 io.OutputWriter
0
0

View File

@@ -0,0 +1,28 @@
package chelper;
import io.InputReader;
import io.OutputWriter;
import misc.SimpleSavingChelperSolution;
public class C extends SimpleSavingChelperSolution {
public void solve(int testNumber, InputReader in, OutputWriter out) {
wrapSolve(testNumber, in, out);
}
@Override
public void solve(int testNumber) {
long mod = 1000000007;
int n = in.nextInt();
long res = 1;
for (int i = 0; i < (n - 1) * (n - 1); i++) {
res = (res * n) % mod;
}
out.println(res);
}
}

View File

@@ -0,0 +1,29 @@
1 C
6 SINGLE
8 STANDARD
9 input.txt
8 STANDARD
10 output.txt
2
0
1 2
1 2
1
1
1 3
2 81
1
11 src/chelper
16 -Xmx256m -Xss64m
4 Main
9 chelper.C
39 net.egork.chelper.checkers.TokenChecker
0
0
10 2018.02.18
0
1
14 io.InputReader
15 io.OutputWriter
0
0

View File

@@ -0,0 +1,119 @@
package chelper;
import java.util.Arrays;
import java.util.Comparator;
import io.InputReader;
import io.OutputWriter;
import misc.SimpleSavingChelperSolution;
public class D extends SimpleSavingChelperSolution {
public void solve(int testNumber, InputReader in, OutputWriter out) {
wrapSolve(testNumber, in, out);
}
class Pair implements Comparable<Pair> {
public final long first;
public final int second;
public Pair(long first, int second) {
this.first = first;
this.second = second;
}
@Override
public int compareTo(Pair o) {
return Long.compare(first, o.first);
}
}
@Override
public void solve(int testNumber) {
int n = in.nextInt();
int q = in.nextInt();
long[] allVal = new long[n];
for (int i = 0; i < n; i++) {
allVal[i] = in.nextLong();
}
int[][] requests = new int[q][3];
int[][] answers = new int[q][3];
for (int i = 0; i < q; i++) {
requests[i][0] = in.nextInt() - 1;
requests[i][1] = in.nextInt();
requests[i][2] = i;
}
Arrays.sort(requests, Comparator.comparingInt(o -> o[0]));
int N = 110;
long[] set;
for (int[] i : requests) {
int l = i[0];
int r = i[1];
int m = Math.min(N, r - l);
set = Arrays.copyOfRange(allVal, l, l + m);
Arrays.sort(set);
boolean ok = false;
long a1 = -1;
int b1 = -1;
long a2 = -1;
int b2 = -1;
long a3 = -1;
int b3 = -1;
for (int j = 0; j < m - 2; j++) {
if (set[j] + set[j + 1] > set[j + 2]) {
ok = true;
a1 = set[j];
a2 = set[j + 1];
a3 = set[j + 2];
break;
}
}
if (ok) {
for (int j = 0; j < m && (b1 == -1 || b2 == -1 || b3 == -1); j++) {
if (allVal[l + j] == a1 && b1 == -1) {
b1 = l + j + 1;
continue;
}
if (allVal[l + j] == a2 && b2 == -1) {
b2 = l + j + 1;
continue;
}
if (allVal[l + j] == a3 && b3 == -1) {
b3 = l + j + 1;
}
}
answers[i[2]][0] = b1;
answers[i[2]][1] = b2;
answers[i[2]][2] = b3;
}
}
for (int i = 0; i < q; i++) {
if (answers[i][0] == 0) {
out.println(-1);
} else {
out.println(answers[i][0] + " " + answers[i][1] + " " + answers[i][2]);
}
}
}
}

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,44 @@
package chelper;
import java.util.List;
import java.util.Random;
import io.InputReader;
import io.OutputWriter;
import misc.SimpleSavingChelperSolution;
public class Dgen extends SimpleSavingChelperSolution {
public void solve(int testNumber, InputReader in, OutputWriter out) {
wrapSolve(testNumber, in, out);
}
@Override
public void solve(int testNumber) {
int n = 300000;
int q = 300000;
out.println(n + " " + q);
long[] a = new long[n];
long p = 1;
for (int i = 0; i < n; i++) {
a[i] = p;
out.print(a[i] + " ");
p = (p * 2) % 1000000000000000000L;
}
out.println();
Random random = new Random();
for (int i = 0; i < q; i++) {
int l = random.nextInt(250000) + 1;
out.println(l + " " + (l + 1000));
}
}
}

View File

@@ -0,0 +1,25 @@
4 Dgen
6 SINGLE
8 STANDARD
9 input.txt
8 STANDARD
10 output.txt
1
0
0
-1
1
11 src/chelper
16 -Xmx256m -Xss64m
4 Main
12 chelper.Dgen
39 net.egork.chelper.checkers.TokenChecker
0
0
10 2018.02.18
0
1
14 io.InputReader
15 io.OutputWriter
0
0

View File

@@ -0,0 +1,45 @@
package chelper;
import io.InputReader;
import io.OutputWriter;
import misc.SimpleSavingChelperSolution;
public class B extends SimpleSavingChelperSolution {
public void solve(int testNumber, InputReader in, OutputWriter out) {
wrapSolve(testNumber, in, out);
}
@Override
public void solve(int testNumber) {
int n = in.nextInt();
int k = in.nextInt();
int[] link = new int[n];
for (int i = 0; i < n; i++) {
link[i] = in.nextInt() - 1;
}
int[] dp = new int[n];
for (int i = 0; i < n; i++) {
int l = Math.max(0, i - k);
int r = Math.min(i + k, n - 1);
dp[i] = r - l + 1;
if (link[i] != -1) {
int ll = Math.max(0, link[i] - k);
int rr = Math.min(link[i] + k, n - 1);
dp[i] += dp[link[i]] - Math.max(0, rr - l + 1);
}
}
for (int i = 0; i < n; i++) {
out.print(dp[i] + " ");
}
}
}

View File

@@ -0,0 +1,36 @@
1 B
6 SINGLE
8 STANDARD
9 input.txt
8 STANDARD
10 output.txt
3
0
15 6 0
0 1 1 2 3 2
12 1 2 2 3 3 3
1
1
24 10 1
0 1 0 3 4 5 2 3 7 0
20 2 3 3 4 5 6 6 6 8 2
1
2
7 2 2
0 1
4 2 2
1
11 src/chelper
16 -Xmx256m -Xss64m
4 Main
9 chelper.B
39 net.egork.chelper.checkers.TokenChecker
0
0
10 2018.02.25
0
1
14 io.InputReader
15 io.OutputWriter
0
0

View File

@@ -0,0 +1,124 @@
package chelper;
import java.util.ArrayList;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.TreeSet;
import io.InputReader;
import io.OutputWriter;
import misc.SimpleSavingChelperSolution;
public class C extends SimpleSavingChelperSolution {
public void solve(int testNumber, InputReader in, OutputWriter out) {
wrapSolve(testNumber, in, out);
}
class Project implements Comparable<Project> {
final String name;
final int version;
final List<Project> dependencies = new ArrayList<>();
public Project(String name, int version) {
this.name = name;
this.version = version;
}
@Override
public int compareTo(Project o) {
if (!name.equals(o.name)) {
return name.compareTo(o.name);
}
return -Integer.compare(version, o.version);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Project project = (Project) o;
return version == project.version &&
Objects.equals(name, project.name);
}
@Override
public int hashCode() {
return Objects.hash(name, version);
}
@Override
public String toString() {
return String.format("%s %d", name, version);
}
}
Map<String, Map<Integer, Project>> allProjects = new HashMap<>();
Project getProject(String name, int version) {
allProjects.putIfAbsent(name, new HashMap<>());
allProjects.get(name).putIfAbsent(version, new Project(name, version));
return allProjects.get(name).get(version);
}
@Override
public void solve(int testNumber) {
int n = in.nextInt();
List<Project> projects = new ArrayList<>();
for (int i = 0; i < n; i++) {
Project project = getProject(in.nextString(), in.nextInt());
projects.add(project);
int depCount = in.nextInt();
for (int j = 0; j < depCount; j++) {
Project depProject = getProject(in.nextString(), in.nextInt());
project.dependencies.add(depProject);
}
}
Set<Project> dependencies = new TreeSet<>();
Set<String> dependencyNames = new TreeSet<>();
Set<Project> neighbors = new TreeSet<>();
neighbors.add(projects.get(0));
while (!neighbors.isEmpty()) {
Set<Project> nextNeighbors = new TreeSet<>();
for (Project neighbor : neighbors) {
if (dependencyNames.contains(neighbor.name)) {
continue;
}
dependencyNames.add(neighbor.name);
dependencies.add(neighbor);
nextNeighbors.addAll(neighbor.dependencies);
}
neighbors = nextNeighbors;
}
dependencies.remove(projects.get(0));
out.println(dependencies.size());
for (Project dependency : dependencies) {
out.println(dependency);
}
}
}

View File

@@ -0,0 +1,102 @@
1 C
6 SINGLE
8 STANDARD
9 input.txt
8 STANDARD
10 output.txt
3
0
45 4
a 3
2
b 1
c 1
b 2
0
b 1
1
b 2
c 1
1
b 2
9 2
b 1
c 1
1
1
189 9
codehorses 5
3
webfrmk 6
mashadb 1
mashadb 2
commons 2
0
mashadb 3
0
webfrmk 6
2
mashadb 3
commons 2
extra 4
1
extra 3
extra 3
0
extra 1
0
mashadb 1
1
extra 3
mashadb 2
1
extra 1
39 4
commons 2
extra 1
mashadb 2
webfrmk 6
1
2
40 3
abc 1
2
abc 3
cba 2
abc 3
0
cba 2
0
7 1
cba 2
1
11 src/chelper
16 -Xmx256m -Xss64m
4 Main
9 chelper.C
39 net.egork.chelper.checkers.TokenChecker
0
0
10 2018.02.25
0
1
14 io.InputReader
15 io.OutputWriter
0
0

View File

@@ -0,0 +1,127 @@
package chelper;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import java.util.regex.MatchResult;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import io.InputReader;
import io.OutputWriter;
import misc.SimpleSavingChelperSolution;
public class D extends SimpleSavingChelperSolution {
public void solve(int testNumber, InputReader in, OutputWriter out) {
wrapSolve(testNumber, in, out);
}
@SuppressWarnings({"unchecked", "rawtypes"})
class Tree {
Node root = new Node();
public int add(char[] s) {
int cheatStart = 1;
int cheatEnd = s.length;
boolean typedNew = false;
boolean canCheat = true;
Node node = root;
node.children.putIfAbsent(s[0], new Node());
node = node.children.get(s[0]);
for (int i = 1; i < s.length; i++) {
char c = s[i];
if (node.children.containsKey(c)) {
if (node.children.size() > 1 || node.finishedHere) {
cheatStart = i + 1;
}
} else {
if (!typedNew) {
typedNew = true;
canCheat = node.children.size() == 0;
cheatEnd = i;
}
node.children.put(c, new Node());
}
node = node.children.get(c);
}
canCheat &= node.children.size() == 0;
node.finishedHere = true;
int total = cheatStart + Math.min(cheatEnd - cheatStart, 1) + s.length - cheatEnd;
if (!canCheat) {
total = s.length;
}
debug.println();
debug.printlns(new String(s));
debug.println(canCheat);
debug.printlns(cheatStart, cheatEnd, total, '|', s.length - total);
return total;
}
}
class Node {
Map<Character, Node> children = new HashMap<>();
boolean finishedHere = false;
}
@Override
public void solve(int testNumber) {
int ans = 0;
List<String> words = new ArrayList<>();
int nonWordLength = 0;
Pattern pattern = Pattern.compile("\\w+");
while (true) {
String line = in.nextLine();
if (line == null) {
break;
}
int l = line.length();
Matcher matcher = pattern.matcher(line);
while (matcher.find()) {
l -= matcher.end() - matcher.start();
words.add(matcher.group());
}
nonWordLength += l + 1;
}
int totalLength = nonWordLength;
Tree tree = new Tree();
for (String word : words) {
int add = tree.add(word.toCharArray());
totalLength += add;
}
out.println(totalLength);
}
}

View File

@@ -0,0 +1,63 @@
1 D
6 SINGLE
8 STANDARD
9 input.txt
8 STANDARD
10 output.txt
7
0
148 snow affects sports such as skiing, snowboarding, and snowmachine travel.
snowboarding is a recreational activity and olympic and paralympic sport.
3 141
1
1
25 'co-co-co, codeforces?!'
2 25
1
2
209 thun-thun-thunder, thunder, thunder
thunder, thun-, thunder
thun-thun-thunder, thunder
thunder, feel the thunder
lightning then the thunder
thunder, feel the thunder
lightning then the thunder
thunder, thunder
3 183
1
3
8 aaa aaaa
1 8
1
4
3 a a
1 4
1
5
17 ac
abcde
abcdefgh
2 16
1
6
12 aaaa
a
aaaaa
2 12
1
11 src/chelper
16 -Xmx256m -Xss64m
4 Main
9 chelper.D
39 net.egork.chelper.checkers.TokenChecker
0
0
10 2018.02.25
0
1
14 io.InputReader
15 io.OutputWriter
0
0