답안 #72251

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
72251 2018-08-26T06:22:50 Z 비타500(#2243, junodeveloper, solarmagic) 마법 다우징 (FXCUP3_magic) C++17
100 / 100
3 ms 380 KB
#include "dowsing.h"
#include <algorithm>
#include <stdio.h>
void FindTreasure(int N) {
    
    bool firstCheck = false;
    int ff = 0, ss = 0;
    
    for (int i = 1; i <= N; i++) {
        if (Detect(i, i)) {
            if (!firstCheck) {
                ff = i;
                firstCheck = true;
            }
            else {
                ss = i;
                break;
            }
        }
    }
    
    if (firstCheck == false) {
        
        for (int i = 1; i <= (N - 1) / 2; i++) {
            
            if (Detect(i, N - i + 1)) {
                int alpha = 1;
                if (alpha + i == N - i + 1) {
                    alpha += 1;
                }
                if (Detect(i, i + alpha)) {
                    Report(i, i);
                    return;
                }
                else {
                    Report(N - i + 1, N - i + 1);
                    return;
                }
            }
        }
        
        if(Detect((N + 1) / 2, (N + 1) / 2 - 1)) {
            Report((N + 1) / 2, (N + 1) / 2);
        }
        else {
            Report((N + 1) / 2 + 1, (N + 1)/ 2 + 1);
        }
        return;
    }
    
    if (ff > ss) {
        std::swap(ff, ss);
    }
    
    // ff < ss
    
    int alpha = 1 + (ff + 1 == ss);
    
    if (ff + alpha > N) {
        alpha = -1;
    }
    
    if (Detect(ff + alpha, ss)){
        Report(ff, ss);
    }
    else {
        Report(ss, ff);
    }
}

# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Correct : C = 5
2 Correct 2 ms 376 KB Correct : C = 4
3 Correct 3 ms 376 KB Correct : C = 149
4 Correct 3 ms 376 KB Correct : C = 100
5 Correct 3 ms 376 KB Correct : C = 150
6 Correct 3 ms 380 KB Correct : C = 101
7 Correct 3 ms 376 KB Correct : C = 149
8 Correct 3 ms 376 KB Correct : C = 150
9 Correct 3 ms 376 KB Correct : C = 150
10 Correct 3 ms 376 KB Correct : C = 102
11 Correct 3 ms 376 KB Correct : C = 105
12 Correct 3 ms 376 KB Correct : C = 102