/*
SAMPLE GRADER for task AVOID

USAGE:
place together with your solution and avoid.h in the same directory, then:
g++ <flags> sample_grader.cpp <solution_file>
e.g.:
g++ -std=c++17 sample_grader.cpp avoid.cpp

INPUT/OUTPUT:
The sample grader first expects on standard input the integers R and H and
the positions a and b of the chairmen (1 <= a, b <= 1 000). Then,
the grader calls scout(R, H) and writes to standard output a protocol of all
grader functions called by your program. Upon termination, it writes your
verdict to standard output.
*/
#include <iostream>
#include <set>
#include <vector>

#include "avoid.h"

namespace sample_grader {

using std::cout;
using std::cin;
using std::endl;
using std::set;
using std::swap;
using std::vector;

constexpr int N = 1000;

int R, H;
int r, h;
int a, b;
vector<int> answers;

[[noreturn]] void invalid_input()
{
    cout << "Invalid input" << endl;
    exit(0);
}

[[noreturn]] void wrong_answer(const char *msg)
{
    cout << msg << endl;
    exit(0);
}

void print_vector(vector<int> v)
{
    cout << "{";
    for (size_t i = 0; i < v.size(); ++i) {
        cout <<  v[i];
        if (i + 1 != v.size()) cout << ", ";
    }
    cout << "}";
}

} // namespace sample_grader


void send(std::vector<int> positions)
{
    using namespace sample_grader;
    cout << "send(";
    print_vector(positions);
    cout << ")" << endl;

    ++r;
    if (r > R) wrong_answer("Out of robots");

    set<int> position_set;
    int curr_answer = 0;
    for (int x : positions) {
        if (x < 1 or x > N or position_set.find(x) != position_set.end()) {
            wrong_answer("Invalid send");
        }
        position_set.insert(x);

        if (x == a or x == b) curr_answer = 1;
    }

    answers.push_back(curr_answer);
}

std::vector<int> wait()
{
    using namespace sample_grader;
    h++;
    cout << "wait()";
    if (h <= H) {
        cout << " returns ";
        print_vector(answers);
    }
    cout << endl;

    if (h > H) wrong_answer("Out of time");

    vector<int> result = answers;
    answers.clear();
    return result;
}


int main()
{
    using namespace sample_grader;
    if (!(cin >> R >> H >> a >> b) || R <= 0 || H <= 0) invalid_input();
    if (a > b) swap(a, b);
    if (a < 1 or b > N) invalid_input();

    auto p = scout(R, H);
    cout << "scout(" << R << ", " << H << ") returned {" << p.first << ", " << p.second << "}" << endl;

    if (p.first > p.second) swap(p.first, p.second);

    if (p.first == a and p.second == b) {
        cout << "Correct: " << r << " robot(s) used, " << h << " hour(s) passed" << endl;
    } else {
        wrong_answer("Wrong answer");
    }
    return 0;
}
