git reimport
This commit is contained in:
41
archive/2017.09/2017.09.19 - unsorted/A.java
Normal file
41
archive/2017.09/2017.09.19 - unsorted/A.java
Normal file
@@ -0,0 +1,41 @@
|
||||
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) {
|
||||
int n = in.nextInt();
|
||||
int x = in.nextInt();
|
||||
int[] a = in.nextIntArray(n);
|
||||
|
||||
Set<Integer> set = new HashSet<>();
|
||||
for (int i = 0; i < n; i++) {
|
||||
set.add(a[i]);
|
||||
}
|
||||
|
||||
int ans = 0;
|
||||
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
if (i < x && !set.contains(i)) {
|
||||
ans++;
|
||||
}
|
||||
if (i == x && set.contains(i)) {
|
||||
ans++;
|
||||
}
|
||||
}
|
||||
|
||||
out.println(ans);
|
||||
}
|
||||
}
|
36
archive/2017.09/2017.09.19 - unsorted/A.task
Normal file
36
archive/2017.09/2017.09.19 - unsorted/A.task
Normal file
@@ -0,0 +1,36 @@
|
||||
1 A
|
||||
6 SINGLE
|
||||
8 STANDARD
|
||||
9 input.txt
|
||||
8 STANDARD
|
||||
10 output.txt
|
||||
3
|
||||
0
|
||||
13 5 3
|
||||
0 4 5 6 7
|
||||
1 2
|
||||
1
|
||||
1
|
||||
5 1 0
|
||||
0
|
||||
1 1
|
||||
1
|
||||
2
|
||||
13 5 0
|
||||
1 2 3 4 5
|
||||
1 0
|
||||
1
|
||||
11 src/chelper
|
||||
16 -Xmx256m -Xss64m
|
||||
4 Main
|
||||
9 chelper.A
|
||||
39 net.egork.chelper.checkers.TokenChecker
|
||||
0
|
||||
0
|
||||
10 2017.09.19
|
||||
0
|
||||
1
|
||||
14 io.InputReader
|
||||
15 io.OutputWriter
|
||||
0
|
||||
0
|
65
archive/2017.09/2017.09.19 - unsorted/B.java
Normal file
65
archive/2017.09/2017.09.19 - unsorted/B.java
Normal file
@@ -0,0 +1,65 @@
|
||||
package chelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
int n;
|
||||
List<List<Integer>> edges;
|
||||
long c1 = 0;
|
||||
long c2 = 0;
|
||||
Set<Integer> visited;
|
||||
|
||||
@Override
|
||||
public void solve(int testNumber) {
|
||||
n = in.nextInt();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
visited = new HashSet<>();
|
||||
dfs(0, true);
|
||||
|
||||
long total = c1 * c2 - (n - 1);
|
||||
out.println(total);
|
||||
}
|
||||
|
||||
void dfs(int v, boolean color) {
|
||||
visited.add(v);
|
||||
if (color) {
|
||||
c1++;
|
||||
} else {
|
||||
c2++;
|
||||
}
|
||||
|
||||
for (Integer o : edges.get(v)) {
|
||||
if (visited.contains(o)) {
|
||||
continue;
|
||||
}
|
||||
dfs(o, !color);
|
||||
}
|
||||
}
|
||||
}
|
45
archive/2017.09/2017.09.19 - unsorted/B.task
Normal file
45
archive/2017.09/2017.09.19 - unsorted/B.task
Normal file
@@ -0,0 +1,45 @@
|
||||
1 B
|
||||
6 SINGLE
|
||||
8 STANDARD
|
||||
9 input.txt
|
||||
8 STANDARD
|
||||
10 output.txt
|
||||
4
|
||||
0
|
||||
10
|
||||
3
|
||||
1 2
|
||||
1 3
|
||||
1 0
|
||||
1
|
||||
1
|
||||
17 5
|
||||
1 2
|
||||
2 3
|
||||
3 4
|
||||
4 5
|
||||
1 2
|
||||
1
|
||||
2
|
||||
1 1
|
||||
1 0
|
||||
1
|
||||
3
|
||||
5 2
|
||||
1 2
|
||||
1 0
|
||||
1
|
||||
11 src/chelper
|
||||
16 -Xmx256m -Xss64m
|
||||
4 Main
|
||||
9 chelper.B
|
||||
39 net.egork.chelper.checkers.TokenChecker
|
||||
0
|
||||
0
|
||||
10 2017.09.19
|
||||
0
|
||||
1
|
||||
14 io.InputReader
|
||||
15 io.OutputWriter
|
||||
0
|
||||
0
|
71
archive/2017.09/2017.09.19 - unsorted/C.java
Normal file
71
archive/2017.09/2017.09.19 - unsorted/C.java
Normal file
@@ -0,0 +1,71 @@
|
||||
package chelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
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) {
|
||||
int n = in.nextInt();
|
||||
int x = in.nextInt();
|
||||
|
||||
int M = 524288;
|
||||
|
||||
if (n == 1) {
|
||||
out.println("YES");
|
||||
out.println(x);
|
||||
return;
|
||||
}
|
||||
|
||||
if (n == 2) {
|
||||
if (x != 0) {
|
||||
out.println("YES");
|
||||
out.println(x + " 0");
|
||||
return;
|
||||
}
|
||||
|
||||
out.println("NO");
|
||||
return;
|
||||
}
|
||||
|
||||
int y = M - 1;
|
||||
int t = 0;
|
||||
|
||||
List<Integer> a = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < n - 2; i++) {
|
||||
a.add(y);
|
||||
t ^= y;
|
||||
y--;
|
||||
}
|
||||
|
||||
for (int i = y; i >= 0; i--) {
|
||||
int t1 = i;
|
||||
int t2 = t ^ i ^ x;
|
||||
if (t2 < i || t2 > M) {
|
||||
a.add(t1);
|
||||
a.add(t2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (a.size() != n) {
|
||||
System.err.println("NOOO");
|
||||
}
|
||||
|
||||
out.println("YES");
|
||||
for (Integer integer : a) {
|
||||
out.print(integer + " ");
|
||||
}
|
||||
}
|
||||
}
|
51
archive/2017.09/2017.09.19 - unsorted/C.task
Normal file
51
archive/2017.09/2017.09.19 - unsorted/C.task
Normal file
@@ -0,0 +1,51 @@
|
||||
1 C
|
||||
6 SINGLE
|
||||
8 STANDARD
|
||||
9 input.txt
|
||||
8 STANDARD
|
||||
10 output.txt
|
||||
7
|
||||
0
|
||||
3 5 5
|
||||
-1
|
||||
0
|
||||
1
|
||||
3 3 6
|
||||
-1
|
||||
0
|
||||
2
|
||||
3 1 0
|
||||
5 YES
|
||||
0
|
||||
0
|
||||
3
|
||||
4 1 10
|
||||
6 YES
|
||||
10
|
||||
0
|
||||
4
|
||||
3 2 0
|
||||
2 NO
|
||||
0
|
||||
5
|
||||
3 2 1
|
||||
-1
|
||||
0
|
||||
6
|
||||
8 100000 1
|
||||
-1
|
||||
1
|
||||
11 src/chelper
|
||||
16 -Xmx256m -Xss64m
|
||||
4 Main
|
||||
9 chelper.C
|
||||
39 net.egork.chelper.checkers.TokenChecker
|
||||
0
|
||||
0
|
||||
10 2017.09.19
|
||||
0
|
||||
1
|
||||
14 io.InputReader
|
||||
15 io.OutputWriter
|
||||
0
|
||||
0
|
60
archive/2017.09/2017.09.19 - unsorted/D.java
Normal file
60
archive/2017.09/2017.09.19 - unsorted/D.java
Normal file
@@ -0,0 +1,60 @@
|
||||
package chelper;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import io.InputReader;
|
||||
import io.OutputWriter;
|
||||
import misc.ComparableCouple;
|
||||
import misc.SimpleSavingChelperSolution;
|
||||
|
||||
|
||||
public class D 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 T = in.nextInt() - 1;
|
||||
|
||||
n = Math.min(n, T);
|
||||
|
||||
int[] a = in.nextIntArray(n);
|
||||
|
||||
int initWait = Math.max(T - n, 0);
|
||||
int leftToWait = T - initWait;
|
||||
|
||||
int[] needMore = new int[n];
|
||||
|
||||
int[] stats = new int[n + 10];
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
needMore[i] = Math.max(a[i] - (initWait + i + 1), 0);
|
||||
|
||||
needMore[i] = Math.min(needMore[i], leftToWait + 1);
|
||||
|
||||
stats[needMore[i]] += 1;
|
||||
}
|
||||
|
||||
int cur = stats[0];
|
||||
int best = cur;
|
||||
|
||||
for (int i = 1; i <= leftToWait; i++) {
|
||||
cur += stats[i];
|
||||
|
||||
int removed = needMore[n - i];
|
||||
if (removed <= i) {
|
||||
cur--;
|
||||
}
|
||||
stats[removed]--;
|
||||
|
||||
best = Math.max(best, cur);
|
||||
}
|
||||
|
||||
out.println(best);
|
||||
}
|
||||
}
|
46
archive/2017.09/2017.09.19 - unsorted/D.task
Normal file
46
archive/2017.09/2017.09.19 - unsorted/D.task
Normal file
@@ -0,0 +1,46 @@
|
||||
1 D
|
||||
6 SINGLE
|
||||
8 STANDARD
|
||||
9 input.txt
|
||||
8 STANDARD
|
||||
10 output.txt
|
||||
5
|
||||
0
|
||||
9 3 5
|
||||
1 5 3
|
||||
1 2
|
||||
1
|
||||
1
|
||||
5 1 2
|
||||
1
|
||||
1 1
|
||||
1
|
||||
2
|
||||
5 1 1
|
||||
1
|
||||
1 0
|
||||
1
|
||||
3
|
||||
11 4 5
|
||||
1 2 3 4
|
||||
1 4
|
||||
1
|
||||
4
|
||||
11 4 5
|
||||
1 2 3 5
|
||||
1 3
|
||||
1
|
||||
11 src/chelper
|
||||
16 -Xmx256m -Xss64m
|
||||
4 Main
|
||||
9 chelper.D
|
||||
39 net.egork.chelper.checkers.TokenChecker
|
||||
0
|
||||
0
|
||||
10 2017.09.19
|
||||
0
|
||||
1
|
||||
14 io.InputReader
|
||||
15 io.OutputWriter
|
||||
0
|
||||
0
|
105
archive/2017.09/2017.09.19 - unsorted/F.java
Normal file
105
archive/2017.09/2017.09.19 - unsorted/F.java
Normal file
@@ -0,0 +1,105 @@
|
||||
package chelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import io.InputReader;
|
||||
import io.OutputWriter;
|
||||
import misc.SimpleSavingChelperSolution;
|
||||
|
||||
|
||||
public class F 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 m = in.nextInt();
|
||||
int a = in.nextInt();
|
||||
|
||||
int votesLeft = m - a;
|
||||
|
||||
List<int[]> votes = new ArrayList<>();
|
||||
for (int i = 0; i < n; i++) {
|
||||
votes.add(new int[]{i, 0, 0});
|
||||
}
|
||||
|
||||
for (int i = 0; i < a; i++) {
|
||||
int vote = in.nextInt() - 1;
|
||||
votes.get(vote)[1] += 1;
|
||||
votes.get(vote)[2] += i;
|
||||
}
|
||||
|
||||
votes.sort(new Comparator<int[]>() {
|
||||
@Override
|
||||
public int compare(int[] o1, int[] o2) {
|
||||
int t = -Integer.compare(o1[1], o2[1]);
|
||||
if (t != 0) {
|
||||
return t;
|
||||
}
|
||||
return Integer.compare(o1[2], o2[2]);
|
||||
}
|
||||
});
|
||||
int[] places = new int[n];
|
||||
for (int i = 0; i < n; i++) {
|
||||
places[votes.get(i)[0]] = i;
|
||||
}
|
||||
|
||||
int[] answer = new int[n];
|
||||
for (int candidate = 0; candidate < n; candidate++) {
|
||||
int place = places[candidate];
|
||||
|
||||
int highestPossible = place;
|
||||
int highestVotes = votes.get(place)[1];
|
||||
|
||||
{
|
||||
int totalVotes = votes.get(place)[1] + votesLeft;
|
||||
highestVotes = totalVotes;
|
||||
|
||||
for (int j = place - 1; j >= 0; j--) {
|
||||
if (totalVotes > votes.get(j)[1]) {
|
||||
highestPossible = j;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int lowestPossible = place;
|
||||
|
||||
{
|
||||
int avail = votesLeft;
|
||||
int need = votes.get(place)[1] + 1;
|
||||
for (int j = place + 1; j < n; j++) {
|
||||
int cost = need - votes.get(j)[1];
|
||||
if (cost <= avail) {
|
||||
avail -= cost;
|
||||
lowestPossible = j;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boolean canWin = highestVotes > 0 && highestPossible < k;
|
||||
boolean canLose = votes.get(place)[1] == 0 || lowestPossible >= k;
|
||||
|
||||
if (canWin && !canLose) {
|
||||
answer[candidate] = 1;
|
||||
} else if (!canWin && canLose) {
|
||||
answer[candidate] = 3;
|
||||
} else {
|
||||
answer[candidate] = 2;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
out.print(answer[i] + " ");
|
||||
}
|
||||
}
|
||||
}
|
46
archive/2017.09/2017.09.19 - unsorted/F.task
Normal file
46
archive/2017.09/2017.09.19 - unsorted/F.task
Normal file
@@ -0,0 +1,46 @@
|
||||
1 F
|
||||
6 SINGLE
|
||||
8 STANDARD
|
||||
9 input.txt
|
||||
8 STANDARD
|
||||
10 output.txt
|
||||
5
|
||||
0
|
||||
15 3 1 5 4
|
||||
1 2 1 3
|
||||
5 1 3 3
|
||||
1
|
||||
1
|
||||
13 3 1 5 3
|
||||
1 3 1
|
||||
5 2 3 2
|
||||
1
|
||||
2
|
||||
13 3 2 5 3
|
||||
1 3 1
|
||||
5 1 2 2
|
||||
1
|
||||
3
|
||||
9 2 2 1 1
|
||||
1
|
||||
3 1 3
|
||||
1
|
||||
4
|
||||
9 2 2 3 1
|
||||
1
|
||||
3 1 2
|
||||
1
|
||||
11 src/chelper
|
||||
16 -Xmx256m -Xss64m
|
||||
4 Main
|
||||
9 chelper.F
|
||||
39 net.egork.chelper.checkers.TokenChecker
|
||||
0
|
||||
0
|
||||
10 2017.09.19
|
||||
0
|
||||
1
|
||||
14 io.InputReader
|
||||
15 io.OutputWriter
|
||||
0
|
||||
0
|
100
archive/2017.09/2017.09.19 - unsorted/K.java
Normal file
100
archive/2017.09/2017.09.19 - unsorted/K.java
Normal file
@@ -0,0 +1,100 @@
|
||||
package chelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import io.InputReader;
|
||||
import io.OutputWriter;
|
||||
import misc.Couple;
|
||||
import misc.Pair;
|
||||
import misc.SimpleSavingChelperSolution;
|
||||
|
||||
|
||||
public class K 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 = in.nextInt();
|
||||
int b = in.nextInt();
|
||||
int k = in.nextInt();
|
||||
int f = in.nextInt();
|
||||
|
||||
Map<String, Integer> nameToId = new HashMap<>();
|
||||
|
||||
List<Couple<Integer>> trips = new ArrayList<>();
|
||||
|
||||
Map<Couple<Integer>, Integer> costs = new HashMap<>();
|
||||
|
||||
int prev = -1;
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
String s1 = in.nextString();
|
||||
String s2 = in.nextString();
|
||||
|
||||
if (!nameToId.containsKey(s1)) {
|
||||
nameToId.put(s1, nameToId.size());
|
||||
}
|
||||
if (!nameToId.containsKey(s2)) {
|
||||
nameToId.put(s2, nameToId.size());
|
||||
}
|
||||
|
||||
int id1 = nameToId.get(s1);
|
||||
int id2 = nameToId.get(s2);
|
||||
|
||||
Couple<Integer> couple = new Couple<>(id1, id2);
|
||||
trips.add(couple);
|
||||
|
||||
int cost = a;
|
||||
|
||||
if (prev == id1) {
|
||||
cost = b;
|
||||
}
|
||||
prev = id2;
|
||||
|
||||
if (id1 > id2) {
|
||||
int t = id1;
|
||||
id1 = id2;
|
||||
id2 = t;
|
||||
}
|
||||
couple = new Couple<>(id1, id2);
|
||||
|
||||
costs.putIfAbsent(couple, 0);
|
||||
costs.put(couple, costs.get(couple) + cost);
|
||||
}
|
||||
|
||||
List<Pair<Couple<Integer>, Integer>> coupleCosts = new ArrayList<>();
|
||||
|
||||
int total = 0;
|
||||
|
||||
for (Map.Entry<Couple<Integer>, Integer> entry : costs.entrySet()) {
|
||||
coupleCosts.add(new Pair<>(entry.getKey(), entry.getValue()));
|
||||
total += entry.getValue();
|
||||
}
|
||||
|
||||
coupleCosts.sort(new Comparator<Pair<Couple<Integer>, Integer>>() {
|
||||
@Override
|
||||
public int compare(Pair<Couple<Integer>, Integer> o1, Pair<Couple<Integer>, Integer> o2) {
|
||||
return -Integer.compare(o1.second, o2.second);
|
||||
}
|
||||
});
|
||||
|
||||
for (int i = 0; i < Math.min(k, coupleCosts.size()); i++) {
|
||||
int orig = coupleCosts.get(i).second;
|
||||
if (orig > f) {
|
||||
total += f - orig;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
out.println(total);
|
||||
}
|
||||
}
|
36
archive/2017.09/2017.09.19 - unsorted/K.task
Normal file
36
archive/2017.09/2017.09.19 - unsorted/K.task
Normal file
@@ -0,0 +1,36 @@
|
||||
1 K
|
||||
6 SINGLE
|
||||
8 STANDARD
|
||||
9 input.txt
|
||||
8 STANDARD
|
||||
10 output.txt
|
||||
2
|
||||
0
|
||||
66 3 5 3 1 8
|
||||
BerBank University
|
||||
University BerMall
|
||||
University BerBank
|
||||
2 11
|
||||
1
|
||||
1
|
||||
34 4 2 1 300 1000
|
||||
a A
|
||||
A aa
|
||||
aa AA
|
||||
AA a
|
||||
1 5
|
||||
1
|
||||
11 src/chelper
|
||||
16 -Xmx256m -Xss64m
|
||||
4 Main
|
||||
9 chelper.K
|
||||
39 net.egork.chelper.checkers.TokenChecker
|
||||
0
|
||||
0
|
||||
10 2017.09.19
|
||||
0
|
||||
1
|
||||
14 io.InputReader
|
||||
15 io.OutputWriter
|
||||
0
|
||||
0
|
Reference in New Issue
Block a user