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,17 @@
// Sample input 1, in Java.
public class broken_memory {
public broken_memory() {
}
public static long GetLength() {
return 10L;
}
public static long GetValue(long i) {
if (i < 0L || i >= GetLength())
throw new IllegalArgumentException("Invalid argument");
if ((message.MyNodeId()) == i)
return (i ^ (i + message.MyNodeId() + 1)) + 1L;
return (i) + 1L;
}
}

View File

@@ -0,0 +1,17 @@
// Sample input 2, in Java.
public class broken_memory {
public broken_memory() {
}
public static long GetLength() {
return 30L;
}
public static long GetValue(long i) {
if (i < 0L || i >= GetLength())
throw new IllegalArgumentException("Invalid argument");
if ((29L - message.MyNodeId()) == i)
return (((i % 9L) + 1L) * ((i % 7L) + 1L) ^ (i + message.MyNodeId() + 1)) + 1L;
return (((i % 9L) + 1L) * ((i % 7L) + 1L)) + 1L;
}
}

View File

@@ -0,0 +1,17 @@
// Sample input 3, in Java.
public class broken_memory {
public broken_memory() {
}
public static long GetLength() {
return 16L;
}
public static long GetValue(long i) {
if (i < 0L || i >= GetLength())
throw new IllegalArgumentException("Invalid argument");
if ((12L ^ message.MyNodeId()) == i)
return ((i * i) ^ 21L ^ (i + message.MyNodeId() + 1)) + 1L;
return ((i * i) ^ 21L) + 1L;
}
}

22
dcj/tasks/flagpoles0.java Normal file
View File

@@ -0,0 +1,22 @@
// Sample input 1, in Java.
public class flagpoles {
public flagpoles() {
}
public static long GetNumFlagpoles() {
return 7L;
}
public static long GetHeight(long i) {
switch ((int)i) {
case 0: return 5L;
case 1: return 7L;
case 2: return 5L;
case 3: return 3L;
case 4: return 1L;
case 5: return 2L;
case 6: return 3L;
default: throw new IllegalArgumentException("Invalid argument");
}
}
}

19
dcj/tasks/flagpoles1.java Normal file
View File

@@ -0,0 +1,19 @@
// Sample input 2, in Java.
public class flagpoles {
public flagpoles() {
}
public static long GetNumFlagpoles() {
return 4L;
}
public static long GetHeight(long i) {
switch ((int)i) {
case 0: return 2L;
case 1: return 2L;
case 2: return 2L;
case 3: return 2L;
default: throw new IllegalArgumentException("Invalid argument");
}
}
}

20
dcj/tasks/flagpoles2.java Normal file
View File

@@ -0,0 +1,20 @@
// Sample input 3, in Java.
public class flagpoles {
public flagpoles() {
}
public static long GetNumFlagpoles() {
return 5L;
}
public static long GetHeight(long i) {
switch ((int)i) {
case 0: return 1L;
case 1: return 3L;
case 2: return 2L;
case 3: return 4L;
case 4: return 3L;
default: throw new IllegalArgumentException("Invalid argument");
}
}
}

View File

@@ -0,0 +1,36 @@
// Sample input 1, in Java.
public class number_bases {
public number_bases() {
}
public static long GetLength() {
return 3L;
}
public static long GetDigitX(long i) {
switch ((int)i) {
case 0: return 3L;
case 1: return 2L;
case 2: return 1L;
default: throw new IllegalArgumentException("Invalid argument");
}
}
public static long GetDigitY(long i) {
switch ((int)i) {
case 0: return 6L;
case 1: return 5L;
case 2: return 4L;
default: throw new IllegalArgumentException("Invalid argument");
}
}
public static long GetDigitZ(long i) {
switch ((int)i) {
case 0: return 0L;
case 1: return 8L;
case 2: return 5L;
default: throw new IllegalArgumentException("Invalid argument");
}
}
}

View File

@@ -0,0 +1,36 @@
// Sample input 2, in Java.
public class number_bases {
public number_bases() {
}
public static long GetLength() {
return 3L;
}
public static long GetDigitX(long i) {
switch ((int)i) {
case 0: return 1000L;
case 1: return 20000L;
case 2: return 300000L;
default: throw new IllegalArgumentException("Invalid argument");
}
}
public static long GetDigitY(long i) {
switch ((int)i) {
case 0: return 40000L;
case 1: return 500000L;
case 2: return 6L;
default: throw new IllegalArgumentException("Invalid argument");
}
}
public static long GetDigitZ(long i) {
switch ((int)i) {
case 0: return 41000L;
case 1: return 520000L;
case 2: return 300006L;
default: throw new IllegalArgumentException("Invalid argument");
}
}
}

View File

@@ -0,0 +1,39 @@
// Sample input 3, in Java.
public class number_bases {
public number_bases() {
}
public static long GetLength() {
return 4L;
}
public static long GetDigitX(long i) {
switch ((int)i) {
case 0: return 5L;
case 1: return 3L;
case 2: return 0L;
case 3: return 0L;
default: throw new IllegalArgumentException("Invalid argument");
}
}
public static long GetDigitY(long i) {
switch ((int)i) {
case 0: return 5L;
case 1: return 3L;
case 2: return 0L;
case 3: return 0L;
default: throw new IllegalArgumentException("Invalid argument");
}
}
public static long GetDigitZ(long i) {
switch ((int)i) {
case 0: return 0L;
case 1: return 6L;
case 2: return 0L;
case 3: return 0L;
default: throw new IllegalArgumentException("Invalid argument");
}
}
}

View File

@@ -0,0 +1,21 @@
// Sample input 1, in Java.
public class query_of_death {
public query_of_death() {
}
static int isthenodebroken = 0;
static int testvs[] = {1, 1, 0};
public static long GetLength() {
return 3L;
}
public static long GetValue(long i) {
if (i < 0L || i >= GetLength())
throw new IllegalArgumentException("Invalid argument");
int val = (int)(testvs[(int)i]^((int)(Math.random() * 2 + 1) % (isthenodebroken + 1)));
if (i == 1)
isthenodebroken = 1;
return val;
}
}

View File

@@ -0,0 +1,21 @@
// Sample input 2, in Java.
public class query_of_death {
public query_of_death() {
}
static int isthenodebroken = 0;
static int testvs[] = {1, 1, 1};
public static long GetLength() {
return 3L;
}
public static long GetValue(long i) {
if (i < 0L || i >= GetLength())
throw new IllegalArgumentException("Invalid argument");
int val = (int)(testvs[(int)i]^((int)(Math.random() * 2 + 1) % (isthenodebroken + 1)));
if (i == 0)
isthenodebroken = 1;
return val;
}
}

View File

@@ -0,0 +1,21 @@
// Sample input 3, in Java.
public class query_of_death {
public query_of_death() {
}
static int isthenodebroken = 0;
static int testvs[] = {1, 0, 1, 0, 1};
public static long GetLength() {
return 5L;
}
public static long GetValue(long i) {
if (i < 0L || i >= GetLength())
throw new IllegalArgumentException("Invalid argument");
int val = (int)(testvs[(int)i]^((int)(Math.random() * 2 + 1) % (isthenodebroken + 1)));
if (i == 4)
isthenodebroken = 1;
return val;
}
}

View File

@@ -0,0 +1,131 @@
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
public class Main {
public static void main(String[] args) {
new Main().run();
}
int myId = message.MyNodeId();
int nodeCount = message.NumberOfNodes();
long aLength = todd_and_steven.GetToddLength();
long bLength = todd_and_steven.GetStevenLength();
long itemCount = (long) 5.05e9;
long perNode = itemCount / nodeCount + 1;
long iL = Math.min(myId * perNode, itemCount);
long iR = Math.min((myId + 1) * perNode, itemCount);
void run() {
client();
if (myId == 0) {
server();
}
}
long mul(long a, long b) {
return (a * b) % MOD;
}
long add(long a, long b) {
return (a + b) % MOD;
}
long MOD = 1000000007L;
long BIG = 1000000000000L;
long get(int type, long i) {
if (type == 0) {
if (i >= aLength) {
return BIG;
}
return todd_and_steven.GetToddValue(i);
}
if (type == 1) {
if (i >= bLength) {
return BIG;
}
return todd_and_steven.GetStevenValue(i);
}
throw new IllegalArgumentException();
}
long binSearch(int type, long minVal) {
long l = 0;
long r = BIG;
while (r - l > 1) {
long m = (l + r) / 2;
long x = get(type, m);
if (x < minVal) {
l = m;
} else {
r = m;
}
}
if (get(type, l) < minVal) {
l++;
}
return l;
}
void client() {
long minVal = iL;
long maxVal = iR;
long ai = binSearch(0, minVal);
long bi = binSearch(1, minVal);
long nextA = get(0, ai);
long nextB = get(1, bi);
long pos = ai + bi;
long res = 0;
while (true) {
long x = Math.min(nextA, nextB);
if (x >= maxVal) {
break;
}
res = add(res, x ^ pos);
pos++;
if (x == nextA) {
ai++;
nextA = get(0, ai);
}
if (x == nextB) {
bi++;
nextB = get(1, bi);
}
}
message.PutLL(0, res);
message.Send(0);
}
void server() {
long res = 0;
for (int i = 0; i < nodeCount; i++) {
message.Receive(i);
long x = message.GetLL(i);
res = add(res, x);
}
System.out.println(res);
}
}

View File

@@ -0,0 +1,28 @@
// Sample input 1, in Java.
public class todd_and_steven {
public todd_and_steven() {
}
public static long GetToddLength() {
return 1L;
}
public static long GetStevenLength() {
return 2L;
}
public static long GetToddValue(long i) {
switch ((int)i) {
case 0: return 3L;
default: throw new IllegalArgumentException("Invalid argument");
}
}
public static long GetStevenValue(long i) {
switch ((int)i) {
case 0: return 2L;
case 1: return 6L;
default: throw new IllegalArgumentException("Invalid argument");
}
}
}

View File

@@ -0,0 +1,27 @@
// Sample input 2, in Java.
public class todd_and_steven {
public todd_and_steven() {
}
public static long GetToddLength() {
return 1L;
}
public static long GetStevenLength() {
return 1L;
}
public static long GetToddValue(long i) {
switch ((int)i) {
case 0: return 101L;
default: throw new IllegalArgumentException("Invalid argument");
}
}
public static long GetStevenValue(long i) {
switch ((int)i) {
case 0: return 100L;
default: throw new IllegalArgumentException("Invalid argument");
}
}
}

View File

@@ -0,0 +1,31 @@
// Sample input 3, in Java.
public class todd_and_steven {
public todd_and_steven() {
}
public static long GetToddLength() {
return 2L;
}
public static long GetStevenLength() {
return 4L;
}
public static long GetToddValue(long i) {
switch ((int)i) {
case 0: return 15L;
case 1: return 23L;
default: throw new IllegalArgumentException("Invalid argument");
}
}
public static long GetStevenValue(long i) {
switch ((int)i) {
case 0: return 4L;
case 1: return 8L;
case 2: return 16L;
case 3: return 42L;
default: throw new IllegalArgumentException("Invalid argument");
}
}
}

View File

@@ -0,0 +1,160 @@
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
public class Main {
public static void main(String[] args) {
new Main().run();
}
int myId = message.MyNodeId();
int nodeCount = message.NumberOfNodes();
long numberLength = weird_editor.GetNumberLength();
long perNode = numberLength / nodeCount + 1;
long iL = Math.min(myId * perNode, numberLength);
long iR = Math.min((myId + 1) * perNode, numberLength);
void run() {
client();
if (myId == 0) {
server();
}
}
long mul(long a, long b) {
return (a * b) % MOD;
}
long add(long a, long b) {
return (a + b) % MOD;
}
long merge(long res1, long l1, long res2, long l2) {
return add(mul(res1, pow(10, l2)), res2);
}
long calcSeries(long digit, int n) {
long res = 0;
long d = 1;
for (int i = 0; i < n; i++) {
res = add(res, mul(d, digit));
d = mul(d, 10);
}
return res;
}
long MOD = 1000000007L;
long pow(long a, long n) {
if (n == 0) {
return 1 % MOD;
}
if (n == 1) {
return a % MOD;
}
if (n % 2 == 0) {
long x = pow(a, n / 2);
return mul(x, x);
}
return mul(pow(a, n - 1), a);
}
void client() {
// System.out.println("[" + iL + ", " + iR + "]");
List<Long> digits = new ArrayList<>();
for (long i = iL; i < iR; i++) {
long x = weird_editor.GetDigit(i);
digits.add(x);
}
List<Long> res = new ArrayList<>();
long[] counts = new long[10];
int rightmost = -1;
for (int digit = 9; digit >= 1; digit--) {
for (int i = rightmost + 1; i < digits.size(); i++) {
if (digits.get(i) == digit) {
counts[digit]++;
rightmost = i;
}
}
}
long[] ress = new long[10];
long[] ressLen = new long[10];
for (int i = 0; i < 10; i++) {
ress[i] = calcSeries(i, (int) counts[i]);
ressLen[i] = counts[i];
}
for (int i = 8; i >= 0; i--) {
ress[i] = merge(ress[i + 1], ressLen[i + 1], ress[i], ressLen[i]);
ressLen[i] += ressLen[i + 1];
}
putLLArray(0, counts);
putLLArray(0, ress);
putLLArray(0, ressLen);
message.Send(0);
// System.out.println("counts " + Arrays.toString(counts));
// System.out.println("ress " + Arrays.toString(ress));
// System.out.println("ressLen " + Arrays.toString(ressLen));
}
void putLLArray(int target, long[] a) {
message.PutInt(target, a.length);
for (int i = 0; i < a.length; i++) {
message.PutLL(target, a[i]);
}
}
long[] getLLArray(int source) {
int len = message.GetInt(source);
long[] a = new long[len];
for (int i = 0; i < len; i++) {
a[i] = message.GetLL(source);
}
return a;
}
void server() {
long totalRes = 0;
long totalLen = 0;
int maxDigit = 0;
for (int i = nodeCount - 1; i >= 0; i--) {
message.Receive(i);
long[] counts = getLLArray(i);
long[] ress = getLLArray(i);
long[] ressLen = getLLArray(i);
int newMaxDigit = maxDigit;
for (int j = maxDigit + 1; j < 10; j++) {
if (counts[j] != 0) {
newMaxDigit = j;
}
}
// totalRes = merge(totalRes, totalLen, ress[maxDigit], ressLen[maxDigit]);
totalRes = merge(ress[maxDigit], ressLen[maxDigit], totalRes, totalLen);
totalLen += ressLen[maxDigit];
maxDigit = newMaxDigit;
}
long zeroCount = numberLength - totalLen;
totalRes = mul(totalRes, pow(10, zeroCount));
System.out.println(totalRes);
}
}

View File

@@ -0,0 +1,19 @@
// Sample input 1, in Java.
public class weird_editor {
public weird_editor() {
}
public static long GetNumberLength() {
return 4L;
}
public static long GetDigit(long i) {
switch ((int)i) {
case 0: return 3L;
case 1: return 0L;
case 2: return 0L;
case 3: return 1L;
default: throw new IllegalArgumentException("Invalid argument");
}
}
}

View File

@@ -0,0 +1,23 @@
// Sample input 2, in Java.
public class weird_editor {
public weird_editor() {
}
public static long GetNumberLength() {
return 8L;
}
public static long GetDigit(long i) {
switch ((int)i) {
case 0: return 1L;
case 1: return 0L;
case 2: return 2L;
case 3: return 3L;
case 4: return 2L;
case 5: return 1L;
case 6: return 3L;
case 7: return 0L;
default: throw new IllegalArgumentException("Invalid argument");
}
}
}

View File

@@ -0,0 +1,25 @@
// Sample input 3, in Java.
public class weird_editor {
public weird_editor() {
}
public static long GetNumberLength() {
return 10L;
}
public static long GetDigit(long i) {
switch ((int)i) {
case 0: return 4L;
case 1: return 4L;
case 2: return 3L;
case 3: return 3L;
case 4: return 2L;
case 5: return 1L;
case 6: return 0L;
case 7: return 0L;
case 8: return 0L;
case 9: return 9L;
default: throw new IllegalArgumentException("Invalid argument");
}
}
}