답안 #72269

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
72269 2018-08-26T06:37:48 Z um..(#2163, grape, sssyyy, arpiel0610) 마법 다우징 (FXCUP3_magic) C++17
100 / 100
3 ms 380 KB
#include "dowsing.h"


void FindTreasure(int N) {
	int t_ans1 = 0, t_ans2 = 0;
	int map[105][105];
	for (int i = 1; i <= N; i++)
		for (int j = 1; j <= N; j++)
			map[i][j] = -1;

	int on = 0, oa = 0, ot = 0, zn = 0;
	for (int i = 1; i < N; i++) {
		map[i][i] = Detect(i, i);
		if (map[i][i] == 0) {
			zn++;
		}
		else {
			on++;
			if (on == 1) oa = i;
			else {
				ot = i;
				break;
			}
		}
	}

	int chk = 0;
	if (on == 0) {
		int ans = 0;
		int ish = 0;
		if (N % 2 == 0) {
			for (int i = 1; i <= N - 3; i += 2) {
				map[i][i + 1] = Detect(i, i + 1);
				if (map[i][i + 1] == 1) {
					ans = i;
					break;
				}
			}

			if (ans == 0) {
				ans = N - 1;
			}

			chk = ans - 1;
			if (chk == 0) chk = N;
			if (Detect(chk, ans) == 1) t_ans1 = ans, t_ans2 = ans;
			else t_ans1 = ans + 1, t_ans2 = ans + 1;
		}
		else {
			ish = 1;
			for (int i = 1; i <= N - 2; i += 2) {
				map[i][i + 1] = Detect(i, i + 1);
				if (map[i][i + 1] == 1) {
					ans = i;
					break;
				}
			}
			if (ans == 0) {
				ans = N;
				t_ans1 = ans, t_ans2 = ans;
			}
			else {

				chk = ans - 1;
				if (chk == 0) chk = N;
				if (Detect(chk, ans) == 1) t_ans1 = ans, t_ans2 = ans;
				else t_ans1 = ans + 1, t_ans2 = ans + 1;
			}
		}

	}
	else {
		if (on == 1) ot = N;

		for (int i = 1; i <= N; i++) {
			if (i != oa && i != ot) {
				if (Detect(i, oa) == 1) {
					t_ans1 = ot, t_ans2 = oa;
					break;
				}
				else {
					t_ans1 = oa, t_ans2 = ot;
					break;
				}
			}
		}
	}

	Report(t_ans1, t_ans2);
}

Compilation message

dowsing.cpp: In function 'void FindTreasure(int)':
dowsing.cpp:30:7: warning: variable 'ish' set but not used [-Wunused-but-set-variable]
   int ish = 0;
       ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Correct : C = 4
2 Correct 2 ms 376 KB Correct : C = 3
3 Correct 3 ms 380 KB Correct : C = 148
4 Correct 3 ms 376 KB Correct : C = 99
5 Correct 3 ms 376 KB Correct : C = 149
6 Correct 3 ms 376 KB Correct : C = 100
7 Correct 3 ms 376 KB Correct : C = 148
8 Correct 3 ms 376 KB Correct : C = 149
9 Correct 3 ms 376 KB Correct : C = 149
10 Correct 3 ms 376 KB Correct : C = 149
11 Correct 3 ms 376 KB Correct : C = 149
12 Correct 3 ms 376 KB Correct : C = 148