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