示例#1
0
文件: TaskC.java 项目: IgorKoval/yaal
 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);
 }
示例#2
0
文件: TaskD.java 项目: IgorKoval/yaal
 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);
 }
示例#3
0
文件: TaskA.java 项目: IgorKoval/yaal
 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);
 }
示例#4
0
文件: TaskB.java 项目: IgorKoval/yaal
 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);
 }
示例#5
0
 public void solve(int testNumber, InputReader in, OutputWriter out) {
   count = in.readInt();
   from = new int[count];
   to = new int[count];
   IOUtils.readIntArrays(in, from, to);
   previousSame = new int[count];
   for (int i = 0; i < count; i++) {
     for (int j = 0; j < i; j++) {
       if (from[i] == from[j] && to[i] == to[j] || from[i] == to[j] && to[i] == from[j])
         previousSame[i] += 1 << j;
     }
   }
   result = new long[8][8][1 << count];
   ArrayUtils.fill(result, -1);
   long answer = 0;
   for (int i = 0; i < count; i++) {
     if (previousSame[i] == 0) {
       answer += go(from[i], to[i], (1 << count) - 1 - (1 << i));
       if (from[i] != to[i]) answer += go(to[i], from[i], (1 << count) - 1 - (1 << i));
     }
   }
   out.printLine(answer);
 }