feat: new problem formatted
This commit is contained in:
42
rod-cutting/src/checker.cpp
Normal file
42
rod-cutting/src/checker.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
#include "testlib.h"
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int readAns(InStream &stream, vector<int> &prices, int size) {
|
||||
int revenue = stream.readInt();
|
||||
vector<int> pieces;
|
||||
int totalSize = 0, totalPrice = 0;
|
||||
while (!stream.seekEof()) {
|
||||
pieces.push_back(stream.readInt(1, size));
|
||||
totalSize += pieces.back();
|
||||
totalPrice += prices[pieces.back()];
|
||||
}
|
||||
|
||||
quitif(totalSize != size, _wa, "Pieces sizes dont add up to the given piece size");
|
||||
quitif(totalPrice != revenue, _wa, "Pieces prices dont add up to the revenue given");
|
||||
|
||||
return revenue;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
setName("compare two signed int%d's", 8 * int(sizeof(int)));
|
||||
registerTestlibCmd(argc, argv);
|
||||
|
||||
int n = inf.readInt();
|
||||
vector<int> prices(n + 1);
|
||||
for (int i = 1; i <= n; i++) {
|
||||
prices[i] = inf.readInt();
|
||||
}
|
||||
|
||||
int ja = readAns(ans, prices, n);
|
||||
int pa = readAns(ouf, prices, n);
|
||||
|
||||
if (ja > pa)
|
||||
quitf(_wa, "Expected (%i) found (%i)", ja, pa);
|
||||
|
||||
if (ja < pa)
|
||||
quitf(_fail, "Participant gave a better answer. PA - (%i), JA - (%i)", pa, ja);
|
||||
|
||||
quitf(_ok, "OK");
|
||||
}
|
||||
Reference in New Issue
Block a user