fix: corrected checker to validate both participant and judge answer.

This commit is contained in:
2025-11-24 17:49:07 -03:00
parent 30d27627db
commit 134d8b90d9
3 changed files with 23 additions and 17 deletions

View File

@@ -11,7 +11,7 @@
"grader": false,
"subject": {
"en_us": [
"dynamic-programming", "longest-increasing-subsequence"
"dynamic-programming", "longest-increasing-subsequence", "LIS"
],
"pt_br": [
"programação-dinâmica", "maior-subsequência-crescente"

View File

@@ -3,19 +3,35 @@
using namespace std;
bool isPaAnswerOk(vector<int> &nums, vector<int> &ans) {
int readAns(InStream& stream, vector<int>& nums) {
int size = stream.readInt(1, 1e3);
vector<int> ans;
while (!stream.seekEof())
ans.push_back(stream.readInt());
if (size != ans.size())
quitf(_wa, "Subsequence does not match size provided");
for (int i = 1; i < ans.size(); i++) {
if (ans[i - 1] >= ans[i]) return false;
if (ans[i - 1] >= ans[i]) {
quitf(_wa, "Subsequence is not strictly increasing");
}
}
// checking if numbers provided are indeed a subsequence of the original array
int j = 0;
for (int i = 0, j = 0; i < nums.size() && j < ans.size(); i++) {
for (int i = 0; i < nums.size() && j < ans.size(); i++) {
if (nums[i] == ans[j]) {
j++;
}
}
return j == (int)ans.size();
if (j != size) {
quitf(_wa, "The provided subsequence is not present in the original array");
}
return size;
}
@@ -27,18 +43,8 @@ int main(int argc, char* argv[]) {
vector<int> nums(n);
for (int i = 0; i < n; i++) nums[i] = inf.readInt();
int ja = ans.readInt();
int pa = ouf.readInt(1, 1e3);
vector<int> paAns;
while (!ouf.seekEof())
paAns.push_back(ouf.readInt());
if (pa != paAns.size())
quitf(_wa, "Subsequence does not match size provided");
if (!isPaAnswerOk(nums, paAns))
quitf(_wa, "Subsequence does not match the constraints");
int ja = readAns(ans, nums);
int pa = readAns(ouf, nums);
if (ja > pa)
quitf(_wa, "Expected (%i) found (%i)", ja, pa);