#include "JavaGraderAdapter.h"
#include "graderlib.cpp"

JNIEnv *env;
jclass frogClass;
jobject solverObject;
jmethodID solveMethod;

int solve(int n, int a, int b, int s[], int x[], int y[]) {
    jintArray jx = env->NewIntArray(n);
    jintArray jy = env->NewIntArray(n);
    jintArray js = env->NewIntArray(n);
    env->SetIntArrayRegion(js, 0, n, (jint *)s);
    int k = env->CallIntMethod(solverObject, solveMethod, n, a, b, js, jx, jy);
    env->GetIntArrayRegion(jx, 0, n, (jint *)x);
    env->GetIntArrayRegion(jy, 0, n, (jint *)y);
    return k;
}

JNIEXPORT void JNICALL Java_grader_run
 (JNIEnv * _env, jclass, jobject _solver) {
    env = _env;
    solverObject = _solver;
    frogClass = env->FindClass("frog");
    solveMethod = env->GetMethodID(frogClass, "solve", "(III[I[I[I)I");
    _main(solve);
}
