git reimport
This commit is contained in:
188
archive/2017.10/2017.10.06 - unsorted/E.java
Normal file
188
archive/2017.10/2017.10.06 - unsorted/E.java
Normal file
@@ -0,0 +1,188 @@
|
||||
package chelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import io.InputReader;
|
||||
import io.OutputWriter;
|
||||
import misc.SimpleSavingChelperSolution;
|
||||
|
||||
|
||||
public class E extends SimpleSavingChelperSolution {
|
||||
|
||||
private int[][] colors;
|
||||
private int[][] colorsH;
|
||||
private int[][] colorsV;
|
||||
private int sqrt;
|
||||
private int n;
|
||||
private int m;
|
||||
private int q;
|
||||
|
||||
public void solve(int testNumber, InputReader in, OutputWriter out) {
|
||||
wrapSolve(testNumber, in, out);
|
||||
}
|
||||
|
||||
class Node1 {
|
||||
int l, r, m;
|
||||
|
||||
Node1 childLeft, childRight;
|
||||
|
||||
Set<Integer> propagateSet = new HashSet<>();
|
||||
Set<Integer> propagateRemove = new HashSet<>();
|
||||
|
||||
Node1(int l, int r) {
|
||||
this.l = l;
|
||||
this.r = r;
|
||||
|
||||
m = (l + r) / 2;
|
||||
|
||||
if (r - l != 1) {
|
||||
childLeft = new Node1(l, m);
|
||||
childRight = new Node1(m, r);
|
||||
}
|
||||
}
|
||||
|
||||
void prop() {
|
||||
if (r - l <= 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
childLeft.propagateSet.addAll(propagateSet);
|
||||
childLeft.propagateSet.removeAll(propagateRemove);
|
||||
childLeft.propagateRemove.addAll(propagateRemove);
|
||||
childLeft.propagateRemove.removeAll(propagateSet);
|
||||
|
||||
childRight.propagateSet.addAll(propagateSet);
|
||||
childRight.propagateSet.removeAll(propagateRemove);
|
||||
childRight.propagateRemove.addAll(propagateRemove);
|
||||
childRight.propagateRemove.removeAll(propagateSet);
|
||||
|
||||
propagateSet.clear();
|
||||
propagateRemove.clear();
|
||||
}
|
||||
|
||||
Set<Integer> get(int x) {
|
||||
if (l == x && r == x + 1) {
|
||||
return propagateSet;
|
||||
}
|
||||
|
||||
prop();
|
||||
|
||||
if (x < m) {
|
||||
return childLeft.get(x);
|
||||
}
|
||||
return childRight.get(x);
|
||||
}
|
||||
|
||||
void add(int ll, int rr, int val) {
|
||||
if (l == ll && r == rr) {
|
||||
propagateSet.add(val);
|
||||
propagateRemove.remove(val);
|
||||
return;
|
||||
}
|
||||
|
||||
prop();
|
||||
|
||||
if (ll < m) {
|
||||
childLeft.add(ll, Math.min(m, rr), val);
|
||||
}
|
||||
if (rr > m) {
|
||||
childRight.add(Math.max(m, ll), rr, val);
|
||||
}
|
||||
}
|
||||
|
||||
void remove(int ll, int rr, int val) {
|
||||
if (l == ll && r == rr) {
|
||||
propagateSet.remove(val);
|
||||
propagateRemove.add(val);
|
||||
return;
|
||||
}
|
||||
|
||||
prop();
|
||||
|
||||
if (ll < m) {
|
||||
childLeft.remove(ll, Math.min(m, rr), val);
|
||||
}
|
||||
if (rr > m) {
|
||||
childRight.remove(Math.max(m, ll), rr, val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Node2 {
|
||||
int l, in
|
||||
}
|
||||
|
||||
@Override
|
||||
public void solve(int testNumber) {
|
||||
sqrt = 50;
|
||||
n = in.nextInt();
|
||||
m = in.nextInt();
|
||||
q = in.nextInt();
|
||||
|
||||
// int[][] node = new int[n][m];
|
||||
colors = new int[n][m];
|
||||
colorsH = new int[n][sqrt];
|
||||
colorsV = new int[sqrt][m];
|
||||
|
||||
for (int i = 0; i < q; i++) {
|
||||
int type = in.nextInt();
|
||||
int x1 = in.nextInt() - 1;
|
||||
int y1 = in.nextInt() - 1;
|
||||
int x2 = in.nextInt() - 1;
|
||||
int y2 = in.nextInt() - 1;
|
||||
|
||||
// if (type)
|
||||
}
|
||||
|
||||
Node1 root = new Node1(0, 10);
|
||||
Random random = new Random();
|
||||
List<Set<Integer>> underlying = new ArrayList<>();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
underlying.add(new HashSet<>());
|
||||
}
|
||||
for (int i = 0; i < 500; i++) {
|
||||
int l = random.nextInt(10);
|
||||
int r = random.nextInt(10);
|
||||
if (r < l) {
|
||||
int t = l;
|
||||
l = r;
|
||||
r = t;
|
||||
}
|
||||
r++;
|
||||
int c = random.nextInt(10);
|
||||
boolean add = random.nextBoolean();
|
||||
|
||||
// int l = 1;
|
||||
// int r = 6;
|
||||
// int c = 1;
|
||||
// boolean add = true;
|
||||
|
||||
|
||||
for (int j = l; j < r; j++) {
|
||||
if (add) {
|
||||
underlying.get(j).add(c);
|
||||
} else {
|
||||
underlying.get(j).remove(c);
|
||||
}
|
||||
}
|
||||
if (add) {
|
||||
root.add(l, r, c);
|
||||
} else {
|
||||
root.remove(l, r, c);
|
||||
}
|
||||
// out.println((add ? "+" : "-") + " " + l + " " + r + " " + c);
|
||||
}
|
||||
out.println();
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
out.println(i + " 1 " + underlying.get(i));
|
||||
out.println(i + " 2 " + root.get(i));
|
||||
out.println();
|
||||
}
|
||||
}
|
||||
}
|
31
archive/2017.10/2017.10.06 - unsorted/E.task
Normal file
31
archive/2017.10/2017.10.06 - unsorted/E.task
Normal file
@@ -0,0 +1,31 @@
|
||||
1 E
|
||||
6 SINGLE
|
||||
8 STANDARD
|
||||
9 input.txt
|
||||
8 STANDARD
|
||||
10 output.txt
|
||||
1
|
||||
0
|
||||
55 5 6 5
|
||||
1 2 2 4 5
|
||||
1 3 3 3 3
|
||||
3 4 4 1 1
|
||||
2 2 2 4 5
|
||||
3 1 1 4 4
|
||||
6 No
|
||||
Yes
|
||||
1
|
||||
11 src/chelper
|
||||
16 -Xmx256m -Xss64m
|
||||
4 Main
|
||||
9 chelper.E
|
||||
39 net.egork.chelper.checkers.TokenChecker
|
||||
0
|
||||
0
|
||||
10 2017.10.06
|
||||
0
|
||||
1
|
||||
14 io.InputReader
|
||||
15 io.OutputWriter
|
||||
0
|
||||
0
|
40
archive/2017.10/2017.10.15 - unsorted/A.java
Normal file
40
archive/2017.10/2017.10.15 - unsorted/A.java
Normal file
@@ -0,0 +1,40 @@
|
||||
package chelper;
|
||||
|
||||
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 m = in.nextInt();
|
||||
int[] a = in.nextIntArray(n);
|
||||
int[] b = in.nextIntArray(m);
|
||||
|
||||
for (int i = 1; i < 1000; i++) {
|
||||
String s = Integer.toString(i);
|
||||
|
||||
boolean ok1 = false;
|
||||
for (int j : a) {
|
||||
ok1 |= s.contains(Integer.toString(j));
|
||||
}
|
||||
|
||||
boolean ok2 = false;
|
||||
for (int j : b) {
|
||||
ok2 |= s.contains(Integer.toString(j));
|
||||
}
|
||||
|
||||
if (ok1 && ok2) {
|
||||
out.println(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
33
archive/2017.10/2017.10.15 - unsorted/A.task
Normal file
33
archive/2017.10/2017.10.15 - unsorted/A.task
Normal file
@@ -0,0 +1,33 @@
|
||||
1 A
|
||||
6 SINGLE
|
||||
8 STANDARD
|
||||
9 input.txt
|
||||
8 STANDARD
|
||||
10 output.txt
|
||||
2
|
||||
0
|
||||
13 2 3
|
||||
4 2
|
||||
5 7 6
|
||||
2 25
|
||||
1
|
||||
1
|
||||
35 8 8
|
||||
1 2 3 4 5 6 7 8
|
||||
8 7 6 5 4 3 2 1
|
||||
1 1
|
||||
1
|
||||
11 src/chelper
|
||||
16 -Xmx256m -Xss64m
|
||||
4 Main
|
||||
9 chelper.A
|
||||
39 net.egork.chelper.checkers.TokenChecker
|
||||
0
|
||||
0
|
||||
10 2017.10.15
|
||||
0
|
||||
1
|
||||
14 io.InputReader
|
||||
15 io.OutputWriter
|
||||
0
|
||||
0
|
39
archive/2017.10/2017.10.15 - unsorted/B.java
Normal file
39
archive/2017.10/2017.10.15 - unsorted/B.java
Normal file
@@ -0,0 +1,39 @@
|
||||
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[] a = in.nextIntArray(n);
|
||||
|
||||
int globalMin = a[0];
|
||||
int globalMax = a[0];
|
||||
|
||||
for (int i : a) {
|
||||
globalMax = Math.max(globalMax, i);
|
||||
globalMin = Math.min(globalMin, i);
|
||||
}
|
||||
|
||||
int twoMax = Math.max(a[0], a[n - 1]);
|
||||
|
||||
if (k == 1) {
|
||||
out.println(globalMin);
|
||||
} else if (k == 2) {
|
||||
out.println(twoMax);
|
||||
} else {
|
||||
out.println(globalMax);
|
||||
}
|
||||
}
|
||||
}
|
31
archive/2017.10/2017.10.15 - unsorted/B.task
Normal file
31
archive/2017.10/2017.10.15 - unsorted/B.task
Normal file
@@ -0,0 +1,31 @@
|
||||
1 B
|
||||
6 SINGLE
|
||||
8 STANDARD
|
||||
9 input.txt
|
||||
8 STANDARD
|
||||
10 output.txt
|
||||
2
|
||||
0
|
||||
13 5 2
|
||||
1 2 3 4 5
|
||||
1 5
|
||||
1
|
||||
1
|
||||
18 5 1
|
||||
-4 -5 -3 -2 -1
|
||||
2 -5
|
||||
1
|
||||
11 src/chelper
|
||||
16 -Xmx256m -Xss64m
|
||||
4 Main
|
||||
9 chelper.B
|
||||
39 net.egork.chelper.checkers.TokenChecker
|
||||
0
|
||||
0
|
||||
10 2017.10.15
|
||||
0
|
||||
1
|
||||
14 io.InputReader
|
||||
15 io.OutputWriter
|
||||
0
|
||||
0
|
131
archive/2017.10/2017.10.15 - unsorted/E.java
Normal file
131
archive/2017.10/2017.10.15 - unsorted/E.java
Normal file
@@ -0,0 +1,131 @@
|
||||
package chelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import io.InputReader;
|
||||
import io.OutputWriter;
|
||||
import misc.SimpleSavingChelperSolution;
|
||||
|
||||
|
||||
public class E extends SimpleSavingChelperSolution {
|
||||
|
||||
private int[] x;
|
||||
private int[] y;
|
||||
private int n;
|
||||
private Map<Integer, Integer> xMap;
|
||||
private Map<Integer, Integer> yMap;
|
||||
private List<Set<Integer>> edges;
|
||||
private boolean[] visited;
|
||||
private long MOD;
|
||||
|
||||
public void solve(int testNumber, InputReader in, OutputWriter out) {
|
||||
wrapSolve(testNumber, in, out);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void solve(int testNumber) {
|
||||
n = in.nextInt();
|
||||
|
||||
x = new int[n];
|
||||
y = new int[n];
|
||||
|
||||
xMap = new TreeMap<>();
|
||||
yMap = new TreeMap<>();
|
||||
|
||||
edges = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
edges.add(new HashSet<>());
|
||||
}
|
||||
|
||||
Map<Integer, Integer> prevX = new HashMap<>();
|
||||
Map<Integer, Integer> prevY = new HashMap<>();
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
x[i] = in.nextInt();
|
||||
y[i] = in.nextInt();
|
||||
|
||||
xMap.put(x[i], xMap.getOrDefault(x[i], 0) + 1);
|
||||
yMap.put(y[i], yMap.getOrDefault(y[i], 0) + 1);
|
||||
|
||||
Integer pX = prevX.get(x[i]);
|
||||
Integer pY = prevY.get(y[i]);
|
||||
|
||||
if (pX != null) {
|
||||
edges.get(pX).add(i);
|
||||
edges.get(i).add(pX);
|
||||
}
|
||||
if (pY != null) {
|
||||
edges.get(pY).add(i);
|
||||
edges.get(i).add(pY);
|
||||
}
|
||||
|
||||
prevX.put(x[i], i);
|
||||
prevY.put(y[i], i);
|
||||
}
|
||||
|
||||
visited = new boolean[n];
|
||||
|
||||
long ans = 1;
|
||||
|
||||
MOD = 1000000007;
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
if (visited[i]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
List<Integer> res = new ArrayList<>();
|
||||
dfs(i, res);
|
||||
|
||||
Set<Integer> usedX = new HashSet<>();
|
||||
Set<Integer> usedY = new HashSet<>();
|
||||
|
||||
for (Integer j : res) {
|
||||
usedX.add(x[j]);
|
||||
usedY.add(y[j]);
|
||||
}
|
||||
|
||||
int K = usedX.size() + usedY.size();
|
||||
if (res.size() >= K) {
|
||||
ans = ans * twopow(K) % MOD;
|
||||
} else {
|
||||
ans = ans * ((twopow(K) - 1 + MOD) % MOD) % MOD;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
out.println(ans);
|
||||
}
|
||||
|
||||
long twopow(int n) {
|
||||
if (n == 0) {
|
||||
return 1;
|
||||
}
|
||||
if (n % 2 == 0) {
|
||||
long t = twopow(n / 2);
|
||||
return t * t % MOD;
|
||||
}
|
||||
return twopow(n - 1) * 2 % MOD;
|
||||
}
|
||||
|
||||
void dfs(int v, List<Integer> res) {
|
||||
if (visited[v]) {
|
||||
return;
|
||||
}
|
||||
visited[v] = true;
|
||||
res.add(v);
|
||||
|
||||
for (int j : edges.get(v)) {
|
||||
dfs(j, res);
|
||||
}
|
||||
}
|
||||
}
|
35
archive/2017.10/2017.10.15 - unsorted/E.task
Normal file
35
archive/2017.10/2017.10.15 - unsorted/E.task
Normal file
@@ -0,0 +1,35 @@
|
||||
1 E
|
||||
6 SINGLE
|
||||
8 STANDARD
|
||||
9 input.txt
|
||||
8 STANDARD
|
||||
10 output.txt
|
||||
2
|
||||
0
|
||||
17 4
|
||||
1 1
|
||||
1 2
|
||||
2 1
|
||||
2 2
|
||||
2 16
|
||||
1
|
||||
1
|
||||
11 2
|
||||
-1 -1
|
||||
0 1
|
||||
1 9
|
||||
1
|
||||
11 src/chelper
|
||||
16 -Xmx256m -Xss64m
|
||||
4 Main
|
||||
9 chelper.E
|
||||
39 net.egork.chelper.checkers.TokenChecker
|
||||
0
|
||||
0
|
||||
10 2017.10.15
|
||||
0
|
||||
1
|
||||
14 io.InputReader
|
||||
15 io.OutputWriter
|
||||
0
|
||||
0
|
58
archive/2017.10/2017.10.15 - unsorted/С.java
Normal file
58
archive/2017.10/2017.10.15 - unsorted/С.java
Normal file
@@ -0,0 +1,58 @@
|
||||
package chelper;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import io.InputReader;
|
||||
import io.OutputWriter;
|
||||
import misc.SimpleSavingChelperSolution;
|
||||
|
||||
|
||||
public class С extends SimpleSavingChelperSolution {
|
||||
|
||||
public void solve(int testNumber, InputReader in, OutputWriter out) {
|
||||
wrapSolve(testNumber, in, out);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void solve(int testNumber) {
|
||||
int q = in.nextInt();
|
||||
|
||||
int M = 1000;
|
||||
boolean[] primes = new boolean[M];
|
||||
Arrays.fill(primes, true);
|
||||
primes[0] = false;
|
||||
primes[1] = true;
|
||||
for (int i = 2; i < M; i++) {
|
||||
if (!primes[i]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int j = i * 2; j < M; j += i) {
|
||||
primes[j] = false;
|
||||
}
|
||||
}
|
||||
|
||||
int[] dp = new int[M];
|
||||
Arrays.fill(dp, -1);
|
||||
|
||||
for (int i = 1; i < M; i++) {
|
||||
if (!primes[i]) {
|
||||
dp[i] = 1;
|
||||
}
|
||||
for (int j = 1; j < i; j++) {
|
||||
if (!primes[j] && !primes[i - j]) {
|
||||
dp[i] = Math.max(dp[i], dp[j] + dp[i - j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < q; i++) {
|
||||
int n = in.nextInt();
|
||||
if (n < M) {
|
||||
out.println(dp[n]);
|
||||
} else {
|
||||
out.println(n / 4 - n % 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
42
archive/2017.10/2017.10.15 - unsorted/С.task
Normal file
42
archive/2017.10/2017.10.15 - unsorted/С.task
Normal file
@@ -0,0 +1,42 @@
|
||||
2 С
|
||||
6 SINGLE
|
||||
8 STANDARD
|
||||
9 input.txt
|
||||
8 STANDARD
|
||||
10 output.txt
|
||||
3
|
||||
0
|
||||
4 1
|
||||
12
|
||||
1 3
|
||||
1
|
||||
1
|
||||
5 2
|
||||
6
|
||||
8
|
||||
3 1
|
||||
2
|
||||
1
|
||||
2
|
||||
7 3
|
||||
1
|
||||
2
|
||||
3
|
||||
8 -1
|
||||
-1
|
||||
-1
|
||||
1
|
||||
11 src/chelper
|
||||
16 -Xmx256m -Xss64m
|
||||
4 Main
|
||||
10 chelper.С
|
||||
39 net.egork.chelper.checkers.TokenChecker
|
||||
0
|
||||
0
|
||||
10 2017.10.15
|
||||
0
|
||||
1
|
||||
14 io.InputReader
|
||||
15 io.OutputWriter
|
||||
0
|
||||
0
|
31
archive/2017.10/2017.10.16 - unsorted/A.java
Normal file
31
archive/2017.10/2017.10.16 - unsorted/A.java
Normal file
@@ -0,0 +1,31 @@
|
||||
package chelper;
|
||||
|
||||
import static misc.Stuff.min;
|
||||
|
||||
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() - 1;
|
||||
int a = in.nextInt();
|
||||
int b = in.nextInt();
|
||||
int c = in.nextInt();
|
||||
|
||||
long ans = min(a * n, b * n);
|
||||
|
||||
if (n >= 1) {
|
||||
ans = min(ans, a + c * (n - 1), b + c * (n - 1));
|
||||
}
|
||||
|
||||
out.println(ans);
|
||||
}
|
||||
}
|
35
archive/2017.10/2017.10.16 - unsorted/A.task
Normal file
35
archive/2017.10/2017.10.16 - unsorted/A.task
Normal file
@@ -0,0 +1,35 @@
|
||||
1 A
|
||||
6 SINGLE
|
||||
8 STANDARD
|
||||
9 input.txt
|
||||
8 STANDARD
|
||||
10 output.txt
|
||||
2
|
||||
0
|
||||
7 3
|
||||
2
|
||||
3
|
||||
1
|
||||
1 3
|
||||
1
|
||||
1
|
||||
7 1
|
||||
2
|
||||
3
|
||||
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.10.16
|
||||
0
|
||||
1
|
||||
14 io.InputReader
|
||||
15 io.OutputWriter
|
||||
0
|
||||
0
|
48
archive/2017.10/2017.10.16 - unsorted/B.java
Normal file
48
archive/2017.10/2017.10.16 - unsorted/B.java
Normal file
@@ -0,0 +1,48 @@
|
||||
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 m = in.nextInt();
|
||||
|
||||
int[] a = in.nextIntArray(n);
|
||||
|
||||
int[] mods = new int[m];
|
||||
|
||||
boolean ok = false;
|
||||
int goodMod = -1;
|
||||
|
||||
for (int i : a) {
|
||||
mods[i % m]++;
|
||||
if (mods[i % m] >= k) {
|
||||
ok = true;
|
||||
goodMod = i % m;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ok) {
|
||||
out.println("No");
|
||||
return;
|
||||
}
|
||||
out.println("Yes");
|
||||
|
||||
for (int i : a) {
|
||||
if (i % m == goodMod && k > 0) {
|
||||
k--;
|
||||
out.print(i + " ");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
38
archive/2017.10/2017.10.16 - unsorted/B.task
Normal file
38
archive/2017.10/2017.10.16 - unsorted/B.task
Normal file
@@ -0,0 +1,38 @@
|
||||
1 B
|
||||
6 SINGLE
|
||||
8 STANDARD
|
||||
9 input.txt
|
||||
8 STANDARD
|
||||
10 output.txt
|
||||
3
|
||||
0
|
||||
11 3 2 3
|
||||
1 8 4
|
||||
8 Yes
|
||||
1 4
|
||||
1
|
||||
1
|
||||
11 3 3 3
|
||||
1 8 4
|
||||
2 No
|
||||
1
|
||||
2
|
||||
13 4 3 5
|
||||
2 7 7 7
|
||||
10 Yes
|
||||
2 7 7
|
||||
1
|
||||
11 src/chelper
|
||||
16 -Xmx256m -Xss64m
|
||||
4 Main
|
||||
9 chelper.B
|
||||
39 net.egork.chelper.checkers.TokenChecker
|
||||
0
|
||||
0
|
||||
10 2017.10.16
|
||||
0
|
||||
1
|
||||
14 io.InputReader
|
||||
15 io.OutputWriter
|
||||
0
|
||||
0
|
44
archive/2017.10/2017.10.16 - unsorted/C.java
Normal file
44
archive/2017.10/2017.10.16 - unsorted/C.java
Normal file
@@ -0,0 +1,44 @@
|
||||
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);
|
||||
}
|
||||
|
||||
int sum(int x) {
|
||||
int res = 0;
|
||||
|
||||
while (x > 0) {
|
||||
res += x % 10;
|
||||
x /= 10;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void solve(int testNumber) {
|
||||
int n = in.nextInt();
|
||||
|
||||
List<Integer> ans = new ArrayList<>();
|
||||
for (int i = Math.max(0, n - 1000); i < n; i++) {
|
||||
if (i + sum(i) == n) {
|
||||
ans.add(i);
|
||||
}
|
||||
}
|
||||
|
||||
out.println(ans.size());
|
||||
for (int i : ans) {
|
||||
out.println(i);
|
||||
}
|
||||
}
|
||||
}
|
30
archive/2017.10/2017.10.16 - unsorted/C.task
Normal file
30
archive/2017.10/2017.10.16 - unsorted/C.task
Normal file
@@ -0,0 +1,30 @@
|
||||
1 C
|
||||
6 SINGLE
|
||||
8 STANDARD
|
||||
9 input.txt
|
||||
8 STANDARD
|
||||
10 output.txt
|
||||
2
|
||||
0
|
||||
2 21
|
||||
4 1
|
||||
15
|
||||
1
|
||||
1
|
||||
2 20
|
||||
1 0
|
||||
1
|
||||
11 src/chelper
|
||||
16 -Xmx256m -Xss64m
|
||||
4 Main
|
||||
9 chelper.C
|
||||
39 net.egork.chelper.checkers.TokenChecker
|
||||
0
|
||||
0
|
||||
10 2017.10.16
|
||||
0
|
||||
1
|
||||
14 io.InputReader
|
||||
15 io.OutputWriter
|
||||
0
|
||||
0
|
91
archive/2017.10/2017.10.16 - unsorted/D.java
Normal file
91
archive/2017.10/2017.10.16 - unsorted/D.java
Normal file
@@ -0,0 +1,91 @@
|
||||
package chelper;
|
||||
|
||||
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 Node {
|
||||
int l, r, m;
|
||||
|
||||
int sum;
|
||||
|
||||
Node cl, cr;
|
||||
|
||||
Node(int l, int r) {
|
||||
this.l = l;
|
||||
this.r = r;
|
||||
|
||||
m = (l + r) / 2;
|
||||
sum = 0;
|
||||
|
||||
if (r - l > 1) {
|
||||
cl = new Node(l, m);
|
||||
cr = new Node(m, r);
|
||||
}
|
||||
}
|
||||
|
||||
void add(int x) {
|
||||
sum++;
|
||||
if (r - l > 1) {
|
||||
if (x < m) {
|
||||
cl.add(x);
|
||||
} else {
|
||||
cr.add(x);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int sum(int ll, int rr) {
|
||||
if (ll == l && rr == r) {
|
||||
return sum;
|
||||
}
|
||||
|
||||
int ans = 0;
|
||||
if (ll < m) {
|
||||
ans += cl.sum(ll, Math.min(m, rr));
|
||||
}
|
||||
if (rr > m) {
|
||||
ans += cr.sum(Math.max(m, ll), rr);
|
||||
}
|
||||
return ans;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void solve(int testNumber) {
|
||||
int n = in.nextInt();
|
||||
|
||||
out.print(1 + " ");
|
||||
|
||||
Node root = new Node(0, n);
|
||||
|
||||
for (int totalSum = 1; totalSum <= n; totalSum++) {
|
||||
root.add(in.nextInt() - 1);
|
||||
|
||||
|
||||
int l = 0;
|
||||
int r = n + 1;
|
||||
|
||||
while (r - l > 1) {
|
||||
int m = (l + r) / 2;
|
||||
int x = root.sum(n - m, n);
|
||||
if (x == m) {
|
||||
l = m;
|
||||
} else {
|
||||
r = m;
|
||||
}
|
||||
}
|
||||
|
||||
out.print((totalSum - l + 1) + " ");
|
||||
|
||||
// out.println(root.sum(0, n));
|
||||
}
|
||||
}
|
||||
}
|
31
archive/2017.10/2017.10.16 - unsorted/D.task
Normal file
31
archive/2017.10/2017.10.16 - 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
|
||||
9 4
|
||||
1 3 4 2
|
||||
9 1 2 3 2 1
|
||||
1
|
||||
1
|
||||
17 8
|
||||
6 8 3 4 7 2 1 5
|
||||
17 1 2 2 3 4 3 4 5 1
|
||||
1
|
||||
11 src/chelper
|
||||
16 -Xmx256m -Xss64m
|
||||
4 Main
|
||||
9 chelper.D
|
||||
39 net.egork.chelper.checkers.TokenChecker
|
||||
0
|
||||
0
|
||||
10 2017.10.16
|
||||
0
|
||||
1
|
||||
14 io.InputReader
|
||||
15 io.OutputWriter
|
||||
0
|
||||
0
|
156
archive/2017.10/2017.10.16 - unsorted/E.java
Normal file
156
archive/2017.10/2017.10.16 - unsorted/E.java
Normal file
@@ -0,0 +1,156 @@
|
||||
package chelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import io.InputReader;
|
||||
import io.OutputWriter;
|
||||
import misc.SimpleSavingChelperSolution;
|
||||
|
||||
|
||||
public class E extends SimpleSavingChelperSolution {
|
||||
|
||||
private int n;
|
||||
private int k;
|
||||
private int m;
|
||||
private int[] a;
|
||||
private int[] length;
|
||||
private int[] pos;
|
||||
private int[] next;
|
||||
private boolean[] fixed;
|
||||
private boolean[] changed;
|
||||
private int first;
|
||||
private boolean[] same;
|
||||
|
||||
public void solve(int testNumber, InputReader in, OutputWriter out) {
|
||||
wrapSolve(testNumber, in, out);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void solve(int testNumber) {
|
||||
n = in.nextInt();
|
||||
k = in.nextInt();
|
||||
|
||||
m = 100100;
|
||||
|
||||
a = new int[m];
|
||||
length = new int[n];
|
||||
pos = new int[n];
|
||||
|
||||
int t = 0;
|
||||
next = new int[n];
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
length[i] = in.nextInt();
|
||||
pos[i] = t;
|
||||
for (int j = 0; j < length[i]; j++) {
|
||||
a[t++] = in.nextInt() - 1;
|
||||
}
|
||||
next[i] = i + 1;
|
||||
}
|
||||
|
||||
fixed = new boolean[k];
|
||||
changed = new boolean[k];
|
||||
|
||||
first = 0;
|
||||
|
||||
same = new boolean[n];
|
||||
Arrays.fill(same, true);
|
||||
|
||||
if (stuff()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Arrays.fill(same, true);
|
||||
for (int i = 0; i < n; i++) {
|
||||
next[i] = i + 1;
|
||||
}
|
||||
first = 0;
|
||||
|
||||
if (stuff()) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<Integer> ans = new ArrayList<>();
|
||||
for (int i = 0; i < k; i++) {
|
||||
if (changed[i]) {
|
||||
ans.add(i);
|
||||
}
|
||||
}
|
||||
|
||||
out.println("Yes");
|
||||
out.println(ans.size());
|
||||
for (int i : ans) {
|
||||
out.print((i + 1) + " ");
|
||||
}
|
||||
}
|
||||
|
||||
private boolean stuff() {
|
||||
for (int i = 0; i < m; i++) {
|
||||
for (int p1 = first; p1 < n; p1 = next[p1]) {
|
||||
int p2 = next[p1];
|
||||
|
||||
if (p2 >= n) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (!same[p1]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int o1 = a[pos[p1] + i];
|
||||
int l1 = changed[o1] ? o1 - k : o1;
|
||||
|
||||
int o2 = a[pos[p2] + i];
|
||||
int l2 = changed[o2] ? o2 - k : o2;
|
||||
|
||||
if (l1 < l2) {
|
||||
same[p1] = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (l1 == l2) {
|
||||
if (length[p1] > i + 1 && length[p2] == i + 1) {
|
||||
out.println("No");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (l1 > l2) {
|
||||
same[p1] = false;
|
||||
if (o1 < o2) {
|
||||
if (fixed[o1]) {
|
||||
out.println("No");
|
||||
return true;
|
||||
}
|
||||
fixed[o1] = true;
|
||||
changed[o1] = true;
|
||||
}
|
||||
if (o1 > o2) {
|
||||
if ((!changed[o1] && fixed[o1]) || (changed[o2] && fixed[o2])) {
|
||||
out.println("No");
|
||||
return true;
|
||||
}
|
||||
changed[o1] = true;
|
||||
changed[o2] = false;
|
||||
fixed[o1] = true;
|
||||
fixed[o2] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while (first < n && length[first] - 1 == i) {
|
||||
first = next[first];
|
||||
}
|
||||
|
||||
for (int j = first; j < n; j = next[j]) {
|
||||
while (next[j] < n && length[next[j]] - 1 == i) {
|
||||
same[j] = false;
|
||||
next[j] = next[next[j]];
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
158
archive/2017.10/2017.10.16 - unsorted/E.task
Normal file
158
archive/2017.10/2017.10.16 - unsorted/E.task
Normal file
@@ -0,0 +1,158 @@
|
||||
1 E
|
||||
6 SINGLE
|
||||
8 STANDARD
|
||||
9 input.txt
|
||||
8 STANDARD
|
||||
10 output.txt
|
||||
17
|
||||
0
|
||||
25 4 3
|
||||
1 2
|
||||
1 1
|
||||
3 1 3 2
|
||||
2 1 1
|
||||
10 Yes
|
||||
2
|
||||
2 3
|
||||
1
|
||||
1
|
||||
41 6 5
|
||||
2 1 2
|
||||
2 1 2
|
||||
3 1 2 3
|
||||
2 1 5
|
||||
2 4 4
|
||||
2 4 4
|
||||
5 Yes
|
||||
0
|
||||
1
|
||||
2
|
||||
35 4 3
|
||||
4 3 2 2 1
|
||||
3 1 1 3
|
||||
3 2 3 3
|
||||
2 3 1
|
||||
2 No
|
||||
1
|
||||
3
|
||||
19 2 2
|
||||
3 2 1 1
|
||||
3 1 1 1
|
||||
7 Yes
|
||||
1
|
||||
2
|
||||
1
|
||||
4
|
||||
15 2 2
|
||||
1 2
|
||||
3 1 1 1
|
||||
7 Yes
|
||||
1
|
||||
2
|
||||
1
|
||||
5
|
||||
19 2 2
|
||||
3 2 1 2
|
||||
3 2 2 2
|
||||
5 Yes
|
||||
0
|
||||
1
|
||||
6
|
||||
25 3 4
|
||||
2 2 4
|
||||
3 2 3 2
|
||||
3 2 2 2
|
||||
2 No
|
||||
1
|
||||
7
|
||||
15 3 3
|
||||
1 3
|
||||
1 2
|
||||
1 1
|
||||
2 No
|
||||
1
|
||||
8
|
||||
21 3 1
|
||||
3 1 1 1
|
||||
2 1 1
|
||||
1 1
|
||||
2 No
|
||||
1
|
||||
9
|
||||
13 2 1
|
||||
2 1 1
|
||||
1 1
|
||||
2 No
|
||||
1
|
||||
10
|
||||
25 3 2
|
||||
3 1 1 1
|
||||
2 2 1
|
||||
3 2 1 1
|
||||
5 Yes
|
||||
0
|
||||
1
|
||||
11
|
||||
19 3 2
|
||||
1 1
|
||||
2 1 2
|
||||
2 1 1
|
||||
7 Yes
|
||||
1
|
||||
2
|
||||
1
|
||||
12
|
||||
25 3 2
|
||||
2 1 1
|
||||
3 1 1 2
|
||||
3 1 1 1
|
||||
7 Yes
|
||||
1
|
||||
2
|
||||
1
|
||||
13
|
||||
31 3 2
|
||||
3 1 1 1
|
||||
4 1 1 1 2
|
||||
4 1 1 1 1
|
||||
7 Yes
|
||||
1
|
||||
2
|
||||
1
|
||||
14
|
||||
19 3 2
|
||||
1 1
|
||||
2 2 2
|
||||
2 2 1
|
||||
2 No
|
||||
1
|
||||
15
|
||||
19 4 4
|
||||
1 2
|
||||
1 1
|
||||
1 4
|
||||
1 3
|
||||
-1
|
||||
1
|
||||
16
|
||||
13 2 3
|
||||
2 3 2
|
||||
1 2
|
||||
7 Yes
|
||||
1
|
||||
3
|
||||
1
|
||||
11 src/chelper
|
||||
16 -Xmx256m -Xss64m
|
||||
4 Main
|
||||
9 chelper.E
|
||||
39 net.egork.chelper.checkers.TokenChecker
|
||||
0
|
||||
0
|
||||
10 2017.10.16
|
||||
0
|
||||
1
|
||||
14 io.InputReader
|
||||
15 io.OutputWriter
|
||||
0
|
||||
0
|
155
archive/2017.10/2017.10.18 - unsorted/Brute.java
Normal file
155
archive/2017.10/2017.10.18 - unsorted/Brute.java
Normal file
@@ -0,0 +1,155 @@
|
||||
package chelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import io.InputReader;
|
||||
import io.OutputWriter;
|
||||
import misc.SimpleSavingChelperSolution;
|
||||
|
||||
|
||||
public class Brute extends SimpleSavingChelperSolution {
|
||||
|
||||
private int condCount;
|
||||
private List<List<List<Integer>>> X;
|
||||
private List<List<Long>> multipliers;
|
||||
private List<Long> consts;
|
||||
private long[] values;
|
||||
private boolean[] set;
|
||||
private int[] termCounts;
|
||||
private int[] bruteOrder;
|
||||
|
||||
public void solve(int testNumber, InputReader in, OutputWriter out) {
|
||||
wrapSolve(testNumber, in, out);
|
||||
}
|
||||
|
||||
long minValue = 33;
|
||||
long maxValue = 126;
|
||||
|
||||
@Override
|
||||
public void solve(int testNumber) {
|
||||
condCount = in.nextInt();
|
||||
X = new ArrayList<>();
|
||||
multipliers = new ArrayList<>();
|
||||
consts = new ArrayList<>();
|
||||
|
||||
set = new boolean[condCount];
|
||||
values = new long[condCount];
|
||||
termCounts = new int[condCount];
|
||||
|
||||
for (int i = 0; i < condCount; i++) {
|
||||
X.add(new ArrayList<>());
|
||||
multipliers.add(new ArrayList<>());
|
||||
termCounts[i] = in.nextInt();
|
||||
|
||||
for (int j = 0; j < termCounts[i]; j++) {
|
||||
int multCount = in.nextInt();
|
||||
X.get(i).add(new ArrayList<>());
|
||||
for (int k = 0; k < multCount; k++) {
|
||||
int mult = in.nextInt();
|
||||
X.get(i).get(j).add(mult);
|
||||
}
|
||||
}
|
||||
|
||||
for (int j = 0; j < termCounts[i]; j++) {
|
||||
multipliers.get(i).add(in.nextLong());
|
||||
}
|
||||
|
||||
consts.add(in.nextLong());
|
||||
}
|
||||
|
||||
bruteOrder = in.nextIntArray(condCount);
|
||||
|
||||
System.out.println("test");
|
||||
|
||||
for (int i = 0; i < condCount; i++) {
|
||||
System.out.printf(
|
||||
"%12d %12d %12d\n",
|
||||
estimate(i, false), consts.get(i), estimate(i, true));
|
||||
}
|
||||
|
||||
System.out.println(okEstimates());
|
||||
|
||||
brute(0);
|
||||
}
|
||||
|
||||
long estimate(int cond, boolean max) {
|
||||
long res = 0;
|
||||
for (int i = 0; i < termCounts[cond]; i++) {
|
||||
long term = 1;
|
||||
long m = multipliers.get(cond).get(i);
|
||||
|
||||
boolean localMax = max == m > 0;
|
||||
|
||||
for (int x : X.get(cond).get(i)) {
|
||||
if (set[x]) {
|
||||
term *= values[x];
|
||||
} else {
|
||||
if (localMax) {
|
||||
term *= maxValue;
|
||||
} else {
|
||||
term *= minValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
res += term * m;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
boolean okEstimates() {
|
||||
for (int cond = 0; cond < condCount; cond++) {
|
||||
long min = estimate(cond, false);
|
||||
long max = estimate(cond, true);
|
||||
if (min > consts.get(cond) || max < consts.get(cond)) {
|
||||
// System.out.println("bad " + cond);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
long iters = 0;
|
||||
|
||||
void brute(int depth) {
|
||||
if (depth >= condCount) {
|
||||
System.out.println("Found " + Arrays.toString(values));
|
||||
System.out.flush();
|
||||
return;
|
||||
}
|
||||
|
||||
int var = bruteOrder[depth];
|
||||
|
||||
for (long value = minValue; value <= maxValue; value++) {
|
||||
values[var] = value;
|
||||
set[var] = true;
|
||||
|
||||
if (okEstimates()) {
|
||||
iters++;
|
||||
|
||||
if (iters % 10000 == 0) {
|
||||
System.out.printf("iter = %10d\n", iters);
|
||||
System.out.printf("depth = %5d\n", depth);
|
||||
|
||||
System.out.print("i = ");
|
||||
for (int i : bruteOrder) {
|
||||
System.out.printf("%3d ", i);
|
||||
}
|
||||
System.out.println();
|
||||
System.out.print("a = ");
|
||||
for (int i : bruteOrder) {
|
||||
System.out.printf("%3d ", values[i]);
|
||||
}
|
||||
System.out.println();
|
||||
System.out.flush();
|
||||
}
|
||||
|
||||
|
||||
brute(depth + 1);
|
||||
}
|
||||
|
||||
set[var] = false;
|
||||
}
|
||||
}
|
||||
}
|
420
archive/2017.10/2017.10.18 - unsorted/Brute.task
Normal file
420
archive/2017.10/2017.10.18 - unsorted/Brute.task
Normal file
@@ -0,0 +1,420 @@
|
||||
5 Brute
|
||||
6 SINGLE
|
||||
8 STANDARD
|
||||
9 input.txt
|
||||
8 STANDARD
|
||||
10 output.txt
|
||||
1
|
||||
0
|
||||
2750 40
|
||||
8
|
||||
1 38
|
||||
1 12
|
||||
1 30
|
||||
1 18
|
||||
1 23
|
||||
1 16
|
||||
2 2 24
|
||||
1 11
|
||||
1 1 -1 -1 -1 -1 -1 1
|
||||
-9009
|
||||
8
|
||||
1 9
|
||||
1 28
|
||||
1 35
|
||||
1 17
|
||||
1 27
|
||||
1 27
|
||||
3 19 19 23
|
||||
1 21
|
||||
1 1 -1 -1 -1 1 -1 1
|
||||
-580705
|
||||
7
|
||||
1 26
|
||||
1 24
|
||||
1 14
|
||||
2 29 32
|
||||
2 12 19
|
||||
2 5 11
|
||||
1 31
|
||||
1 -1 -125 1 -1 -1 1
|
||||
-19297
|
||||
6
|
||||
1 19
|
||||
1 27
|
||||
1 9
|
||||
1 11
|
||||
2 30 33
|
||||
3 0 1 12
|
||||
1 1 1 1 -1 67
|
||||
8858058
|
||||
8
|
||||
1 13
|
||||
1 13
|
||||
1 16
|
||||
2 3 24
|
||||
1 20
|
||||
2 14 36
|
||||
1 33
|
||||
1 22
|
||||
1 -1 1 -1 1 1 -1 1
|
||||
-4973
|
||||
7
|
||||
1 15
|
||||
1 21
|
||||
1 3
|
||||
2 13 26
|
||||
1 21
|
||||
1 22
|
||||
4 22 28 30 39
|
||||
1 -1 1 1 1 -1 -1
|
||||
-12805567
|
||||
7
|
||||
1 5
|
||||
1 8
|
||||
1 4
|
||||
1 9
|
||||
1 30
|
||||
4 0 7 14 15
|
||||
1 35
|
||||
1 1 1 -1 1 -1 -1
|
||||
-27732588
|
||||
7
|
||||
1 38
|
||||
1 33
|
||||
1 6
|
||||
1 35
|
||||
3 0 11 29
|
||||
1 16
|
||||
1 29
|
||||
-1 -1 1 1 1 1 1
|
||||
257196
|
||||
7
|
||||
1 24
|
||||
1 7
|
||||
2 31 39
|
||||
1 5
|
||||
1 20
|
||||
1 14
|
||||
1 33
|
||||
1 1 84 1 1 1 -1
|
||||
490112
|
||||
4
|
||||
2 4 10
|
||||
2 1 22
|
||||
1 25
|
||||
3 0 13 19
|
||||
1 -70 -125 -88
|
||||
-34045542
|
||||
5
|
||||
1 28
|
||||
1 31
|
||||
2 0 30
|
||||
1 27
|
||||
2 3 4
|
||||
1 -8610 1 -1 1
|
||||
-938912
|
||||
8
|
||||
2 4 8
|
||||
1 27
|
||||
2 24 29
|
||||
1 6
|
||||
1 22
|
||||
1 26
|
||||
2 0 5
|
||||
1 34
|
||||
1 -1 1 -1 -1 -1 -1 -1
|
||||
7589
|
||||
9
|
||||
1 33
|
||||
1 20
|
||||
1 34
|
||||
1 12
|
||||
1 33
|
||||
2 6 28
|
||||
1 27
|
||||
1 16
|
||||
1 5
|
||||
1 1 -1 -1 -1 1 -1 1 1
|
||||
11473
|
||||
7
|
||||
1 1
|
||||
2 1 16
|
||||
1 15
|
||||
1 32
|
||||
1 36
|
||||
2 22 27
|
||||
2 15 20
|
||||
1 1 -1 -1 1 1 1
|
||||
13944
|
||||
5
|
||||
1 17
|
||||
2 0 10
|
||||
1 24
|
||||
2 13 33
|
||||
1 23
|
||||
1 1 -1 4900 1
|
||||
37520490
|
||||
7
|
||||
1 38
|
||||
2 27 34
|
||||
1 1
|
||||
1 4
|
||||
1 32
|
||||
2 3 21
|
||||
1 32
|
||||
1 -1 1 -1 1 -1 -1
|
||||
-23809
|
||||
9
|
||||
1 18
|
||||
2 10 20
|
||||
1 8
|
||||
1 4
|
||||
1 10
|
||||
1 19
|
||||
1 18
|
||||
1 2
|
||||
1 34
|
||||
1 73 1 1 -1 -1 1 -1 -1
|
||||
832009
|
||||
7
|
||||
1 24
|
||||
1 0
|
||||
1 16
|
||||
1 1
|
||||
1 34
|
||||
1 3
|
||||
1 11
|
||||
-1 1 84 -1 1 -1 -1
|
||||
4318
|
||||
7
|
||||
1 15
|
||||
1 26
|
||||
1 10
|
||||
1 5
|
||||
2 14 33
|
||||
1 24
|
||||
1 17
|
||||
1 -84 125 1 -1 -1 1
|
||||
-2401
|
||||
8
|
||||
1 4
|
||||
1 24
|
||||
1 12
|
||||
2 5 15
|
||||
2 1 26
|
||||
1 18
|
||||
1 36
|
||||
1 12
|
||||
1 1 -1 -1 70 -1 1 -1
|
||||
165790
|
||||
9
|
||||
1 14
|
||||
2 7 9
|
||||
1 16
|
||||
1 19
|
||||
1 12
|
||||
1 27
|
||||
1 33
|
||||
1 20
|
||||
1 11
|
||||
1 1 -1 -1 -1 -1 70 -1 -1
|
||||
12685
|
||||
5
|
||||
1 33
|
||||
2 18 28
|
||||
1 6
|
||||
4 1 5 7 12
|
||||
1 35
|
||||
1 1 -1 1 -1
|
||||
26088083
|
||||
7
|
||||
1 34
|
||||
1 9
|
||||
1 16
|
||||
2 24 32
|
||||
1 30
|
||||
2 17 31
|
||||
2 8 37
|
||||
1 -1 1 1 1 -1 -1
|
||||
-14712
|
||||
6
|
||||
2 12 24
|
||||
2 26 28
|
||||
3 3 17 26
|
||||
1 10
|
||||
1 10
|
||||
1 18
|
||||
1 1 -1 -1 -1 1
|
||||
-518496
|
||||
8
|
||||
1 27
|
||||
2 16 38
|
||||
1 36
|
||||
1 16
|
||||
1 10
|
||||
1 31
|
||||
1 32
|
||||
1 1
|
||||
1 1 -1 -1 1 70 -84 -1
|
||||
9479
|
||||
6
|
||||
1 18
|
||||
2 7 37
|
||||
1 38
|
||||
2 12 37
|
||||
1 39
|
||||
2 22 35
|
||||
1 1 1 1 -1 -1
|
||||
13529
|
||||
5
|
||||
1 22
|
||||
1 31
|
||||
1 20
|
||||
2 3 24
|
||||
4 3 11 16 26
|
||||
1 -1 -1 123 -73
|
||||
-1052607271
|
||||
8
|
||||
1 15
|
||||
1 38
|
||||
1 1
|
||||
1 36
|
||||
1 4
|
||||
1 13
|
||||
1 17
|
||||
2 25 36
|
||||
1 -1 -1 84 -1 1 -1 -1
|
||||
-1076
|
||||
6
|
||||
1 23
|
||||
1 31
|
||||
2 6 25
|
||||
1 27
|
||||
1 1
|
||||
1 9
|
||||
67 70 1 1 -1 -1
|
||||
23277
|
||||
5
|
||||
2 27 32
|
||||
2 26 36
|
||||
4 2 22 22 24
|
||||
1 17
|
||||
1 7
|
||||
1 -1 -1 1 1
|
||||
-25347227
|
||||
8
|
||||
1 31
|
||||
1 29
|
||||
1 38
|
||||
1 3
|
||||
1 29
|
||||
1 15
|
||||
1 14
|
||||
2 8 12
|
||||
1 -73 1 -1 1 1 1 1
|
||||
-2380
|
||||
7
|
||||
2 6 17
|
||||
1 29
|
||||
1 7
|
||||
1 13
|
||||
1 38
|
||||
1 22
|
||||
1 29
|
||||
1 -1 -1 1 1 -125 125
|
||||
17233
|
||||
9
|
||||
1 7
|
||||
1 18
|
||||
1 34
|
||||
1 0
|
||||
1 17
|
||||
1 15
|
||||
1 20
|
||||
1 31
|
||||
1 11
|
||||
1 1 -70 1 1 1 1 1 1
|
||||
-7375
|
||||
5
|
||||
2 14 32
|
||||
2 9 38
|
||||
1 14
|
||||
2 10 38
|
||||
2 21 35
|
||||
123 -1 1 -1 1
|
||||
689844
|
||||
6
|
||||
1 4
|
||||
1 17
|
||||
3 3 8 33
|
||||
1 28
|
||||
2 16 20
|
||||
1 13
|
||||
1 -1 -1 -1 125 1
|
||||
-424956
|
||||
4
|
||||
2 31 32
|
||||
2 0 4
|
||||
3 27 32 37
|
||||
2 18 25
|
||||
1 1 1 125
|
||||
1365356
|
||||
6
|
||||
1 14
|
||||
1 13
|
||||
3 7 35 35
|
||||
1 26
|
||||
1 38
|
||||
2 11 36
|
||||
123 1 -1 -1 1 -1
|
||||
-245866
|
||||
7
|
||||
3 17 27 39
|
||||
1 26
|
||||
1 3
|
||||
1 26
|
||||
2 27 38
|
||||
1 32
|
||||
1 22
|
||||
1 -1 -86 -1 1 -1 -1
|
||||
603387
|
||||
8
|
||||
1 9
|
||||
1 17
|
||||
1 32
|
||||
1 39
|
||||
1 30
|
||||
1 19
|
||||
1 28
|
||||
1 21
|
||||
1 -1 -1 1 -1 -1 1 1
|
||||
-11
|
||||
8
|
||||
2 8 31
|
||||
2 16 19
|
||||
1 35
|
||||
1 37
|
||||
1 18
|
||||
1 9
|
||||
1 25
|
||||
1 7
|
||||
1 1 1 -1 1 -1 -1 -1
|
||||
15035
|
||||
2 22 24 3 11 16 26 1 5 7 12 0 14 15 28 30 39 17 27 35 32 37 8 33 13 19 29 23 31 38 36 18 25 4 20 21 10 9 6 34
|
||||
-1
|
||||
1
|
||||
11 src/chelper
|
||||
16 -Xmx256m -Xss64m
|
||||
4 Main
|
||||
13 chelper.Brute
|
||||
39 net.egork.chelper.checkers.TokenChecker
|
||||
0
|
||||
0
|
||||
10 2017.10.18
|
||||
0
|
||||
1
|
||||
14 io.InputReader
|
||||
15 io.OutputWriter
|
||||
0
|
||||
0
|
117
archive/2017.10/2017.10.21 - unsorted/G.java
Normal file
117
archive/2017.10/2017.10.21 - unsorted/G.java
Normal file
@@ -0,0 +1,117 @@
|
||||
package chelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
|
||||
import io.InputReader;
|
||||
import io.OutputWriter;
|
||||
import misc.SimpleSavingChelperSolution;
|
||||
|
||||
|
||||
public class G extends SimpleSavingChelperSolution {
|
||||
|
||||
private List<List<Integer>> directedEdges;
|
||||
private List<List<Integer>> undirectedEdgeIds;
|
||||
private int[][] undirectedEdges;
|
||||
private int n;
|
||||
private int m;
|
||||
private int s;
|
||||
|
||||
public void solve(int testNumber, InputReader in, OutputWriter out) {
|
||||
wrapSolve(testNumber, in, out);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void solve(int testNumber) {
|
||||
n = in.nextInt();
|
||||
m = in.nextInt();
|
||||
s = in.nextInt() - 1;
|
||||
|
||||
directedEdges = new ArrayList<>();
|
||||
undirectedEdgeIds = new ArrayList<>();
|
||||
|
||||
int M = 0;
|
||||
undirectedEdges = new int[m][2];
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
directedEdges.add(new ArrayList<>());
|
||||
undirectedEdgeIds.add(new ArrayList<>());
|
||||
}
|
||||
|
||||
for (int i = 0; i < m; i++) {
|
||||
int t = in.nextInt();
|
||||
int a = in.nextInt() - 1;
|
||||
int b = in.nextInt() - 1;
|
||||
|
||||
if (t == 1) { // directed
|
||||
directedEdges.get(a).add(b);
|
||||
} else {
|
||||
undirectedEdges[M][0] = a;
|
||||
undirectedEdges[M][1] = b;
|
||||
|
||||
undirectedEdgeIds.get(a).add(M);
|
||||
undirectedEdgeIds.get(b).add(M);
|
||||
|
||||
M++;
|
||||
}
|
||||
}
|
||||
|
||||
boolean[] maxDirs = new boolean[M];
|
||||
int maxCount = bfs(maxDirs, true);
|
||||
out.println(maxCount);
|
||||
for (int i = 0; i < M; i++) {
|
||||
out.print(maxDirs[i] ? '+' : '-');
|
||||
}
|
||||
out.println();
|
||||
|
||||
boolean[] minDirs = new boolean[M];
|
||||
int minCount = bfs(minDirs, false);
|
||||
out.println(minCount);
|
||||
for (int i = 0; i < M; i++) {
|
||||
out.print(minDirs[i] ? '+' : '-');
|
||||
}
|
||||
out.println();
|
||||
}
|
||||
|
||||
int bfs(boolean[] dirs, boolean invade) {
|
||||
Queue<Integer> queue = new LinkedList<>();
|
||||
queue.add(s);
|
||||
|
||||
boolean[] visited = new boolean[n];
|
||||
visited[s] = true;
|
||||
|
||||
int count = 1;
|
||||
|
||||
while (!queue.isEmpty()) {
|
||||
int v = queue.poll();
|
||||
|
||||
for (int i : undirectedEdgeIds.get(v)) {
|
||||
int u = undirectedEdges[i][0] == v ? undirectedEdges[i][1] : undirectedEdges[i][0];
|
||||
|
||||
if (!invade) {
|
||||
dirs[i] = undirectedEdges[i][0] != v;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!visited[u]) {
|
||||
dirs[i] = undirectedEdges[i][0] == v;
|
||||
visited[u] = true;
|
||||
queue.add(u);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
for (int u : directedEdges.get(v)) {
|
||||
if (!visited[u]) {
|
||||
visited[u] = true;
|
||||
queue.add(u);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
}
|
37
archive/2017.10/2017.10.21 - unsorted/G.task
Normal file
37
archive/2017.10/2017.10.21 - unsorted/G.task
Normal file
@@ -0,0 +1,37 @@
|
||||
1 G
|
||||
6 SINGLE
|
||||
8 STANDARD
|
||||
9 input.txt
|
||||
8 STANDARD
|
||||
10 output.txt
|
||||
2
|
||||
0
|
||||
17 2 2 1
|
||||
1 1 2
|
||||
2 2 1
|
||||
-1
|
||||
0
|
||||
1
|
||||
41 6 6 3
|
||||
2 2 6
|
||||
1 4 5
|
||||
2 3 4
|
||||
1 4 1
|
||||
1 3 1
|
||||
2 2 3
|
||||
-1
|
||||
1
|
||||
11 src/chelper
|
||||
16 -Xmx256m -Xss64m
|
||||
4 Main
|
||||
9 chelper.G
|
||||
39 net.egork.chelper.checkers.TokenChecker
|
||||
0
|
||||
0
|
||||
10 2017.10.21
|
||||
0
|
||||
1
|
||||
14 io.InputReader
|
||||
15 io.OutputWriter
|
||||
0
|
||||
0
|
71
archive/2017.10/2017.10.26 - unsorted/С.java
Normal file
71
archive/2017.10/2017.10.26 - unsorted/С.java
Normal file
@@ -0,0 +1,71 @@
|
||||
package chelper;
|
||||
|
||||
import io.InputReader;
|
||||
import io.OutputWriter;
|
||||
import misc.SimpleSavingChelperSolution;
|
||||
|
||||
|
||||
public class С 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[] states = new int[10];
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
char op = in.nextString().charAt(0);
|
||||
int x = in.nextInt();
|
||||
|
||||
if (op == '&') {
|
||||
x ^= 1023;
|
||||
}
|
||||
|
||||
for (int j = 0; j < 10; j++) {
|
||||
if (x % 2 == 1) {
|
||||
switch (op) {
|
||||
case '|':
|
||||
states[j] = 1;
|
||||
break;
|
||||
case '&':
|
||||
states[j] = 2;
|
||||
break;
|
||||
case '^':
|
||||
states[j] ^= 3;
|
||||
break;
|
||||
}
|
||||
}
|
||||
x /= 2;
|
||||
}
|
||||
}
|
||||
|
||||
int alwaysZero = 0;
|
||||
int alwaysOne = 0;
|
||||
int xored = 0;
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
switch (states[i]) {
|
||||
case 1:
|
||||
alwaysOne += 1 << i;
|
||||
break;
|
||||
case 2:
|
||||
alwaysZero += 1 << i;
|
||||
break;
|
||||
case 3:
|
||||
xored += 1 << i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
alwaysZero ^= 1023;
|
||||
|
||||
out.println(3);
|
||||
out.println("| " + alwaysOne);
|
||||
out.println("& " + alwaysZero);
|
||||
out.println("^ " + xored);
|
||||
}
|
||||
}
|
28
archive/2017.10/2017.10.26 - unsorted/С.task
Normal file
28
archive/2017.10/2017.10.26 - unsorted/С.task
Normal file
@@ -0,0 +1,28 @@
|
||||
2 С
|
||||
6 SINGLE
|
||||
8 STANDARD
|
||||
9 input.txt
|
||||
8 STANDARD
|
||||
10 output.txt
|
||||
1
|
||||
0
|
||||
13 3
|
||||
| 3
|
||||
^ 2
|
||||
| 1
|
||||
-1
|
||||
1
|
||||
11 src/chelper
|
||||
16 -Xmx256m -Xss64m
|
||||
4 Main
|
||||
10 chelper.С
|
||||
39 net.egork.chelper.checkers.TokenChecker
|
||||
0
|
||||
0
|
||||
10 2017.10.26
|
||||
0
|
||||
1
|
||||
14 io.InputReader
|
||||
15 io.OutputWriter
|
||||
0
|
||||
0
|
42
archive/2017.10/2017.10.27 - unsorted/D.java
Normal file
42
archive/2017.10/2017.10.27 - unsorted/D.java
Normal file
@@ -0,0 +1,42 @@
|
||||
package chelper;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void solve(int testNumber) {
|
||||
int n = in.nextInt();
|
||||
|
||||
long[] a = in.nextLongArray(n);
|
||||
|
||||
Arrays.sort(a);
|
||||
|
||||
long t = 0;
|
||||
long ans = 0;
|
||||
for (int i = 0; i < n; i++) {
|
||||
t += a[i];
|
||||
}
|
||||
|
||||
int i = n - 1;
|
||||
while (i > 0) {
|
||||
ans += t;
|
||||
t -= a[i];
|
||||
i--;
|
||||
if (i > 0) {
|
||||
t -= a[i];
|
||||
i--;
|
||||
}
|
||||
}
|
||||
out.println(ans);
|
||||
}
|
||||
}
|
36
archive/2017.10/2017.10.27 - unsorted/D.task
Normal file
36
archive/2017.10/2017.10.27 - unsorted/D.task
Normal file
@@ -0,0 +1,36 @@
|
||||
1 D
|
||||
6 SINGLE
|
||||
8 STANDARD
|
||||
9 input.txt
|
||||
8 STANDARD
|
||||
10 output.txt
|
||||
3
|
||||
0
|
||||
9 4
|
||||
2 3 4 5
|
||||
2 19
|
||||
1
|
||||
1
|
||||
7 3
|
||||
1 2 3
|
||||
1 6
|
||||
1
|
||||
2
|
||||
13 6
|
||||
1 4 4 4 4 4
|
||||
2 38
|
||||
1
|
||||
11 src/chelper
|
||||
16 -Xmx256m -Xss64m
|
||||
4 Main
|
||||
9 chelper.D
|
||||
39 net.egork.chelper.checkers.TokenChecker
|
||||
0
|
||||
0
|
||||
10 2017.10.27
|
||||
0
|
||||
1
|
||||
14 io.InputReader
|
||||
15 io.OutputWriter
|
||||
0
|
||||
0
|
62
archive/2017.10/2017.10.27 - unsorted/С.java
Normal file
62
archive/2017.10/2017.10.27 - unsorted/С.java
Normal file
@@ -0,0 +1,62 @@
|
||||
package chelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import io.InputReader;
|
||||
import io.OutputWriter;
|
||||
import misc.SimpleSavingChelperSolution;
|
||||
|
||||
|
||||
public class С 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[n];
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
a[i] = in.nextInt() - 1;
|
||||
}
|
||||
|
||||
boolean[] visited = new boolean[n];
|
||||
|
||||
List<Integer> b = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
if (visited[i]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int t = i;
|
||||
int c = 0;
|
||||
while (!visited[t]) {
|
||||
visited[t] = true;
|
||||
t = a[t];
|
||||
c++;
|
||||
}
|
||||
b.add(c);
|
||||
}
|
||||
|
||||
Collections.sort(b);
|
||||
|
||||
if (b.size() >= 2) {
|
||||
int x = b.remove(b.size() - 1);
|
||||
int y = b.remove(b.size() - 1);
|
||||
b.add(x + y);
|
||||
}
|
||||
|
||||
long res = 0;
|
||||
for (Integer integer : b) {
|
||||
res += ((long) integer) * ((long) integer);
|
||||
}
|
||||
|
||||
out.println(res);
|
||||
}
|
||||
}
|
56
archive/2017.10/2017.10.27 - unsorted/С.task
Normal file
56
archive/2017.10/2017.10.27 - unsorted/С.task
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user