Submission #72870

#TimeUsernameProblemLanguageResultExecution timeMemory
72870aintaMagic Dowsing (FXCUP3_magic)C++17
100 / 100
3 ms380 KiB
#include "dowsing.h"
 
void FindTreasure(int N) {
	int i, j, c1 = -1, c2 = -1, c3 = -1;
	for (i = 1; i <= N; i++) {
		if (Detect(i, i)) {
			if (c1 == -1)c1 = i;
			else c2 = i;
		}
		else {
			c3 = i;
		}
	}
	if (c1 != -1) {
		if (Detect(c1, c3)) {
			Report(c1, c2);
		}
		else Report(c2, c1);
		return;
	}
	for (i = 1; i < N - 1; i += 2) {
		if (Detect(i, i + 1)) {
			for (j = 1; j <= N; j++) {
				if (i != j &&i + 1 != j) {
					if (Detect(i, j)) {
						Report(i, i);
					}
					else {
						Report(i + 1, i + 1);
					}
					return;
				}
			}
		}
	}
	if (N % 2 == 1) {
		Report(N, N);
	}
	else {
		if (Detect(1, N))Report(N, N);
		else Report(N - 1, N - 1);
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...