#include "validate.h" #include #include using namespace std; int main(int argc, char **argv) { init_io(argc, argv); int n, m, b, r; judge_in >> n >> m; judge_in >> b >> r; vector > event(r, vector(3)); for (int i = 0; i < r; i++) { judge_in >> event[i][0]; judge_in >> event[i][1]; judge_in >> event[i][2]; --event[i][1]; --event[i][2]; } vector > cur(n, { 0, -1 }), first(n, vector(m, b)), total(n, vector(m, 0)); for (int i = 0; i < r; i++) { int cur_time = event[i][0], kid = event[i][1], toy = event[i][2], prev_time = cur[kid][0], prev_toy = cur[kid][1]; if (toy >= 0) first[kid][toy] = min(first[kid][toy], cur_time); if (prev_toy >= 0) total[kid][prev_toy] += cur_time - prev_time; cur[kid][0] = cur_time; cur[kid][1] = toy; } for (int i = 0; i < n; i++) { int prev_time = cur[i][0], prev_toy = cur[i][1]; if (prev_toy >= 0) total[i][prev_toy] += b - prev_time; } string init; judge_ans >> init; bool judge_possible = init != "impossible"; if (!(author_out >> init)) { wrong_answer("Empty output\n"); } transform(init.begin(), init.end(), init.begin(), ::tolower); if (init == "impossible") { if (judge_possible) { wrong_answer("They claim impossible, but there is a solution\n"); } } else { if (!judge_possible) { wrong_answer("They claim possible, but there is no solution\n"); } vector toy(n); vector used(m, 0); stringstream ss(init); for (int i = 0; i < n; i++) { if (!((i == 0 ? ss : author_out) >> toy[i])) { wrong_answer("Kid %d: Found something that was not an integer\n", i+1); } if (toy[i] < 1 || toy[i] > m) { wrong_answer("Kid %d: assigned toy %d not in range [1,%d]\n", i+1, toy[i], m); } toy[i]--; if (used[toy[i]]) { wrong_answer("Kid %d: toy %d used multiple times\n", i+1, toy[i]); } used[toy[i]] = true; } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i == j) { continue; } if (first[i][toy[j]] < first[i][toy[i]] && // i rather plays with toy[j] than toy[i] total[i][toy[j]] < total[j][toy[j]]) { // i envies j for playing with toy[j] wrong_answer("Kid %d (assigned toy %d) starts crying because of kid %d (assigned toy %d):\n firsttime[%d][%d] = %d, firsttime[%d][%d] = %d\n totaltime[%d][%d] = %d, totaltime[%d][%d] = %d\n", i+1, toy[i]+1, j+1, toy[j]+1, i+1, toy[j]+1, first[i][toy[j]], i+1, toy[i]+1, first[i][toy[i]], i+1, toy[j]+1, total[i][toy[j]], j+1, toy[j]+1, total[j][toy[j]]); } } } } string trash; if (author_out >> trash) { wrong_answer("Answer correct but has trailing output\n"); } accept(); }