From 134d8b90d9a2ae33399c452e9461c49caf890a97 Mon Sep 17 00:00:00 2001 From: arthur Date: Mon, 24 Nov 2025 17:49:07 -0300 Subject: [PATCH] fix: corrected checker to validate both participant and judge answer. --- .../longest-increasing-subsequence.pdf | Bin 82013 -> 82013 bytes longest-increasing-subsequence/problem.json | 2 +- .../src/checker.cpp | 38 ++++++++++-------- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/longest-increasing-subsequence/longest-increasing-subsequence.pdf b/longest-increasing-subsequence/longest-increasing-subsequence.pdf index 69b88019f973af5cc7093a4e769f52e696e6e76f..4f5d246f8531c7f56445af0bf462f1eb1f5bfcab 100644 GIT binary patch delta 159 zcmccHz7w&g2PjHg&Rav@|s~b}_ebG&Z$#Gch$Xa&G%zxAGcz-^Q?MbZ bB$i9xCp9m7w&g2O&H8gQ_G;uU>HZwGIvb1nBF)?>Bw=lGHHg`5~advUGQ?MbZ bB$i9xCp9m &nums, vector &ans) { +int readAns(InStream& stream, vector& nums) { + + int size = stream.readInt(1, 1e3); + vector 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 nums(n); for (int i = 0; i < n; i++) nums[i] = inf.readInt(); - int ja = ans.readInt(); - int pa = ouf.readInt(1, 1e3); - - vector 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);