Trailer Tailor: Nearest Mood Match
A streaming app’s Trailer Tailor must pick a trailer vibe: funny
or serious
. It looks at how long people watch (minutes), how often they rewatch, what genre they love, and which device they use. But minutes and rewatches sit on different scales, and genres/devices are words - so the app needs a fair way to compare everything before choosing the closest existing example.

You are asked to read a vocabulary of genres and devices, an initial set of viewing records, and then classify new records with 1-NN. Use statistics from the initial records only to put the two numeric features on the same footing by standardizing them (with z-score), turn the two categorical features into one-hot encodings according to the given vocabularies, concatenate all features, and pick the single nearest neighbor by Euclidean distance. If several neighbors are equally near, print the alphabetically smallest label. Tokens not found in a vocabulary contribute no active bit for that field.
The first line of the input contains a single integer v1
followed by a line of v1
tokens forming the genre vocabulary. The next line contains a single integer v2
followed by a line of v2
tokens forming the device vocabulary.
The next line contains a single integer n
representing how many initial records you have. Each of the next n
lines contains two floating-point numbers and three tokens - watch_time rewatch_count genre device label
.
The next line contains a single integer q
. Each of the next q
lines contains watch_time rewatch_count genre device
for the records to classify.
The program should print q
lines. Each line should contain the predicted label: funny
or serious
.
Input | Output |
---|---|
3 | funny |
2 | funny |
3 | funny |
Constraints
Time limit: 2 seconds
Memory limit: 512 MB
Output limit: 1 MB