Submission #72403

#TimeUsernameProblemLanguageResultExecution timeMemory
72403cat > /dev/null (#118)Magic Dowsing (FXCUP3_magic)C++17
100 / 100
3 ms380 KiB
#include "dowsing.h"
#include<queue>
using namespace std;

void FindTreasure(int N) {
    queue<int> q;
    for (int i = 1; i < N; i ++)
        if (Detect(i, i)) {
            q.push(i);
        }

    if (q.size() == 1)
        q.push(N);

    if (q.size() == 2) {
        int i, j;
        i = q.front(); q.pop();
        j = q.front();

        int t = j + 1;
        if (t > N)
            t = 1;
        if (t == i)
            t = j - 1;
        if (t == 0)
            t = N;

        if (Detect(t, j))
            Report(i, j);
        else
            Report(j, i);
        return;
    }
    else {
        for (int i = N, j = 1; j <= N/2; i --, j ++) {
            if (Detect(i, j)) {
                int t = i + 1;
                if (t > N)
                    t = 1;
                if (t == j)
                    t = i - 1;
                if (t == 0)
                    t = N;

                if (Detect(i, t))
                    Report(i, i);
                else
                    Report(j, j);

                return;
            }
        }
        Report((N+1)/2, (N+1)/2);
    }


    return;
}
#Verdict Execution timeMemoryGrader output
Fetching results...