Submission #262968

#TimeUsernameProblemLanguageResultExecution timeMemory
262968idk321Vision Program (IOI19_vision)Java
41 / 100
109 ms11896 KiB
import java.util.Arrays;
import java.util.Comparator;
import java.util.TreeSet;

public class vision {
	public void construct_network(int H, int W, int K) {
		int commands = 0;

		TreeSet<int[]> uniqueCommands = new TreeSet<int[]>(new ArrayComparator());
		if ((H <= 10 && W <= 10) || (Math.min(H, W) == 1)) {
			for (int i = 0; i < H; i++) {
				for (int j = 0; j < W; j++) {

					for (int k = i; k < H; k++) {
						int remaining = K - k + i;
						if (remaining >= 0) {
							if (j + remaining < W) {
								int[] command = {i * W + j, k * W + j + remaining};
								uniqueCommands.add(command);
							}
							if (j - remaining >= 0) {
								int[] command = {i * W + j, k * W + j - remaining};
								//System.out.println(Arrays.toString(command));
								uniqueCommands.add(command);
							}
						}
					}
				}
			}
		} else {
			int j = 0;
			int i = 0;
			for (int k = i; k < H; k++) {
				int remaining = K - k + i;
				if (remaining >= 0) {
					if (j + remaining < W) {
						int[] command = {i * W + j, k * W + j + remaining};
						uniqueCommands.add(command);
					}
					if (j - remaining >= 0) {
						int[] command = {i * W + j, k * W + j - remaining};
						//System.out.println(Arrays.toString(command));
						uniqueCommands.add(command);
					}
				}
			}
		}

		for (int[] command : uniqueCommands) {
			grader.add_and(command);
			commands++;
		}

		int[] command = new int[commands];
		for (int i = H * W, j = 0; j < commands; i++, j++) command[j] = i;
		grader.add_or(command);
	}

	private static class ArrayComparator implements Comparator<int[]> {
		@Override
		public int compare(int[] o1, int[] o2) {
			int min1 = Math.min(o1[0], o1[1]);
			int min2 = Math.min(o2[0], o2[1]);
			int compare = Integer.compare(min1, min2);
			if (compare != 0) return compare;
			int max1 = Math.max(o1[0], o1[1]);
			int max2 = Math.max(o2[0], o2[1]);
			return Integer.compare(max1, max2);
		}
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...