Example #1
0
 public void solve(int testNumber, InputReader in, OutputWriter out) {
   int firstCount = in.readInt();
   int[] first = IOUtils.readIntArray(in, firstCount);
   int secondCount = in.readInt();
   int[] second = IOUtils.readIntArray(in, secondCount);
   int[] countFirst = countDivisors(first);
   int[] countSecond = countDivisors(second);
   Arrays.sort(first);
   Arrays.sort(second);
   long result = 1;
   double doubleResult = 1;
   for (int i = 0; i < primes.length; i++) {
     for (int j = 0; j < Math.min(countFirst[i], countSecond[i]); j++) {
       result *= primes[i];
       result %= MOD;
       doubleResult *= primes[i];
     }
   }
   int firstIndex = 0;
   int secondIndex = 0;
   while (firstIndex < firstCount && secondIndex < secondCount) {
     if (first[firstIndex] == second[secondIndex]) {
       result *= first[firstIndex];
       result %= MOD;
       doubleResult *= first[firstIndex];
       firstIndex++;
       secondIndex++;
     } else if (first[firstIndex] < second[secondIndex]) firstIndex++;
     else secondIndex++;
   }
   if (result == doubleResult) out.printLine(result);
   else out.printFormat("%09d\n", (int) result);
 }
Example #2
0
 public void solve(int testNumber, InputReader in, OutputWriter out) {
   int count = in.readInt();
   int[] computer = IOUtils.readIntArray(in, count);
   int[][] required = new int[count][];
   for (int i = 0; i < count; i++) {
     int requiredCount = in.readInt();
     required[i] = IOUtils.readIntArray(in, requiredCount);
   }
   MiscUtils.decreaseByOne(required);
   int answer = Integer.MAX_VALUE;
   for (int i = 1; i <= 3; i++) answer = Math.min(answer, go(computer, required, i));
   out.printLine(answer);
 }
Example #3
0
 public void solve(int testNumber, net.egork.utils.old.io.old.InputReader in, PrintWriter out) {
   int count = in.readInt();
   int[] numbers = IOUtils.readIntArray(in, count);
   Arrays.sort(numbers);
   int[] result = new int[count];
   for (int i = 0; i < count; i += 2) result[i / 2] = numbers[i];
   for (int i = 1; i < count; i += 2) result[count - 1 - i / 2] = numbers[i];
   IOUtils.printArray(result, out);
 }
Example #4
0
 public void solve(int testNumber, InputReader in, OutputWriter out) {
   int count = in.readInt();
   int surprising = in.readInt();
   int required = in.readInt();
   int[] scores = IOUtils.readIntArray(in, count);
   int answer = 0;
   for (int i : scores) {
     if (i < required) continue;
     if (i >= 3 * required - 2) answer++;
     else if (i >= 3 * required - 4 && surprising > 0) {
       answer++;
       surprising--;
     }
   }
   out.printLine("Case #" + testNumber + ":", answer);
 }