QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#776464 | #8321. 季风 | sumairu | 40 | 119ms | 5452kb | C++23 | 12.7kb | 2024-11-23 18:51:03 | 2024-11-23 18:51:03 |
Judging History
answer
/**
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣤⡤⠤⣤⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡴⠛⠉⠀⠀⠀⠀⠈⠙⢷⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⠟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⣆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣰⠶⣄⡀⠀⠀⠀⢠⡟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢹⡆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⡏⠀⠀⠉⠛⠶⣤⣸⡇⠀⠀⠀⠀⣀⣤⣶⣶⠒⠒⠒⠶⣬⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣤⠴⠶⣿⠀⠀⠀⠀⠀⠀⠈⠉⠉⠛⠒⠶⢿⣭⣀⡀⢻⡀⠀⠀⢠⡿⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣤⠶⠛⠋⠁⠀⠀⢸⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⠛⠷⣴⣞⠛⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⡴⠞⠉⠀⠀⠀⠀⠀⠀⢰⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠛⢦⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⠞⠋⠀⠀⠀⠀⢀⡤⠠⡄⠀⢰⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⠿⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⡞⠁⠀⠀⠀⠀⣠⠖⠋⠀⣸⠇⠀⢸⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠀⢀⡀⠀⠀⠀⠀⠀⠀⢦⡀⠀⠀⠀⠸⣷⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡼⠋⠀⠀⠀⠀⢀⣴⠋⢀⢀⡴⠋⠀⢀⣼⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣽⠀⣼⢿⡄⠀⠀⠀⠀⣆⠀⠉⢦⡀⠀⠀⠀⠘⢧⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⡟⠁⠀⠀⠀⠀⣠⠟⠇⠀⠈⠉⠁⠀⣀⣾⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡟⢰⠏⠀⠻⣄⠀⠀⠀⠹⣄⣰⠟⠁⠀⠀⠀⠀⠀⢻⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣾⡟⠀⢀⣀⡖⠀⣰⠏⠀⠀⠀⠀⠀⢀⣼⣿⠋⠸⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣧⡟⠀⠀⠀⠹⣦⠀⠀⠀⠀⠁⠀⣶⠀⠀⣴⠛⢧⠀⢻⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⣠⠞⣩⡟⠀⠀⠈⠉⠀⢀⡟⠀⠀⢀⣀⣠⣤⣾⡿⠗⠒⠚⣿⠠⣤⠀⠀⠀⠀⠀⠀⠀⢸⣿⠓⠒⠲⠶⠶⠾⢷⣤⣀⣀⠀⠀⠙⣧⠀⠹⣆⣼⠃⠀⢷⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⢀⡴⠟⢁⡼⣿⠁⠀⠀⠀⠀⠀⢸⠃⠀⠀⠈⠉⢠⡾⠋⠀⠀⠀⠀⠸⣆⠙⣧⡀⠀⠀⠀⠀⠀⢸⡇⠀⠀⠀⠀⠀⠀⠀⠻⣆⠉⠁⠀⠀⢹⡄⠀⠈⠁⠀⠀⠘⣷⢦⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⣠⡶⠋⢀⡴⠋⢰⡏⠀⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⣠⠟⠀⠀⠀⠀⠀⠀⠀⢻⡄⢸⣷⣄⠀⠀⠀⠀⢸⡇⠀⠀⠀⠀⠀⠀⠀⠀⠈⢳⣄⠀⠀⠸⣧⠀⠀⠀⠀⠀⠀⢿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⢰⣾⡥⠴⠞⠋⠀⠀⣼⠀⠀⠀⠀⠀⠀⠀⣸⠀⠀⠀⣰⠏⠀⠀⠀⠀⠀⠀⠀⠀⠀⢻⡄⣷⠙⠷⣄⡀⠀⢸⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢷⣄⠀⣿⠀⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⣿⡆⠀⠀⠀⠀⠀⠀⢸⡄⠀⣼⢏⣀⣤⣶⣦⣤⣶⣶⣶⣶⣶⣿⣿⣾⡆⠀⠈⠻⢦⣼⡇⢰⣶⣶⣶⣶⣶⣶⣶⣤⣤⣤⣦⠙⢧⣿⠀⠀⠀⠀⠀⠀⢸⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⣿⡇⠀⠀⠀⠀⠀⠀⠘⣇⣼⠏⠘⣿⡿⢿⣿⣿⣿⣿⣿⡏⠉⠉⠉⠙⠃⠀⠀⠀⠀⠉⠁⠘⠛⢻⣿⣿⣿⣿⣿⣟⠛⢛⠷⠀⠀⣿⠀⠀⠀⠀⠀⠀⢸⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⡟⣷⠀⠀⠀⠀⠀⠀⠀⢻⡏⠀⠀⠀⠀⣸⣿⣿⣿⣿⣿⣷⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣾⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⢰⡏⠀⠀⠀⠀⠀⠀⣾⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⣷⢹⣆⠀⠀⠀⠀⠀⠀⠈⣷⠀⠀⠀⠀⢹⣿⣿⣿⣿⣿⣿⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⣾⠀⠀⠀⠀⠀⠀⢰⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⢿⠘⣿⣆⠀⠀⠀⠀⠀⠐⠘⣧⠀⠀⠀⠘⢿⣿⣿⣿⣿⠏⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢿⣿⣿⣿⡿⠃⠀⠀⠀⣼⠃⠀⠀⠀⠀⠀⣰⠟⠐⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠸⣇⣿⠙⣧⣄⠀⠀⠀⠀⠀⠘⢧⡀⠀⠀⠈⢹⠿⢟⡋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢻⡿⠀⡀⠀⠀⣼⠃⠀⠀⠀⠀⣀⡾⠋⠀⣴⣷⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⢻⣿⠀⣿⠝⠳⣤⣀⡀⠀⠀⠈⢷⣤⠇⢠⡞⠠⠾⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⠟⠁⡾⠃⣠⡾⠃⠀⠀⣀⣤⠾⠋⠀⠀⠀⡿⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣿⣸⣿⠀⠀⠀⠉⠙⠓⡶⠦⠤⣿⡆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠓⢰⡿⠤⠴⠶⣿⠉⠀⠀⠀⠀⠀⢠⡇⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣿⢻⠀⠀⠀⠀⠀⠃⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢲⣄⠀⠀⠀⠀⠀⠀⠀⢀⣴⠆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡟⠀⠀⠀⠀⠀⠀⢸⡇⣸⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⡿⢸⡇⠀⠀⠀⠀⠀⢿⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠛⠲⠤⣤⠤⠴⠞⠋⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⡏⠀⠀⠀⠀⠀⠀⢸⠇⠈⣇⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣸⡇⢸⡇⠀⠀⠀⠀⠀⢸⣿⣦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢿⡇⠀⠀⠀⠀⠀⠀⢺⢀⠀⢿⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣸⢷⠛⣇⠀⠀⠀⠀⠀⠈⣿⠉⠻⣦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣾⣅⣸⠀⠀⠀⠀⠀⠀⢀⣿⢸⡀⢸⡇⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡿⠘⣀⣿⠀⠀⠀⠀⠀⢷⢸⡄⠀⠈⠙⠶⣤⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣠⡴⠟⠁⠀⠈⣿⠀⠀⠀⠀⠀⠀⠈⡟⣼⡇⠀⣧⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⡇⠀⢿⢿⠀⠀⠀⠀⠀⠀⠈⣧⠀⠀⠀⠀⠀⠉⠛⠶⢤⣤⣀⣀⠀⣀⡀⠀⠀⠀⠀⠀⢀⣠⡴⠞⠋⠁⠀⠀⠀⠀⢀⡏⠀⠀⠀⠀⠀⠀⢠⡇⢹⣤⠀⢹⡄⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⣼⠀⠀⡿⢸⡆⠀⠀⠀⠀⠀⠀⢻⡆⠀⠀⠀⠀⠀⠀⠀⠀⣿⡿⠟⠋⠉⠁⠀⠀⠀⠀⠀⢸⠁⠀⠀⠀⠀⠀⠀⠀⠀⢸⠇⠀⠀⠀⠀⠀⠀⢸⡇⠈⣟⠀⠈⣷⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⢰⡟⠀⢰⡇⠘⡇⠀⠀⠀⠀⠀⠘⠀⣷⠀⠀⠀⠀⠀⠀⠀⠀⣿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⡿⠆⠀⠀⠀⠀⠀⠀⣼⠁⠀⢻⡀⠀⠸⣇⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⣼⠁⠀⣼⠁⠀⣿⠀⠀⠀⠀⠀⠀⠀⠻⣇⣀⠀⠀⠀⠀⠀⠀⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⡀⠀⠀⠀⠀⠀⠀⠀⣰⡇⠀⠀⠀⠀⠀⠀⠀⣿⡆⠀⠈⣷⡀⠀⢻⡄⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⢰⡇⠀⢀⡏⠀⠀⢻⠀⠀⠀⠀⠀⠀⠀⠀⢻⣦⣄⠀⠀⠀⠀⣠⡟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⣧⠀⠀⠀⠀⠀⣠⣾⣿⠀⠀⠀⠀⠀⠀⢠⣠⡇⡇⠀⠀⠸⣯⡀⠀⢷⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⡾⠀⠀⣼⠁⠀⠀⠸⡇⠀⠀⠀⠀⠀⠀⠀⠀⢿⣽⡧⠴⢶⣿⣿⠖⠒⠛⠛⠃⠀⠀⠀⠚⠋⠉⠉⠉⠙⠓⠲⢾⡛⠻⣽⠃⠀⠀⠀⠀⠀⠀⢸⣿⣃⠀⠀⠀⠀⢹⣷⠀⠘⣧⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣸⠃⠀⢸⡏⠀⠀⠀⢀⣿⠀⠀⠀⠀⢀⣀⠀⠈⠈⢷⠖⠚⠋⠁⢹⡇⠀⢀⣴⠶⠶⢦⣄⣀⣤⡶⠶⠤⠤⠤⠶⠾⠇⢰⡏⠀⠀⠀⠀⠀⠀⠻⣿⣿⣤⡀⠀⠀⠀⠀⢿⣀⠀⠸⣆⠀⠀⠀
⠀⠀⠀⠀⠀⢰⠏⠀⢀⡿⠀⠀⠀⣰⠟⢹⣿⡄⠀⠀⠀⠻⣄⠀⠀⠘⣷⣤⣄⣀⣈⡙⠛⢹⡷⢶⣦⣴⣾⣛⣻⢯⣴⣦⠴⠖⠃⠀⢀⡾⠀⠀⠀⠀⠀⠀⠀⢰⣿⡇⠀⠹⣆⠀⠀⠸⡞⣧⣆⠀⠹⣄⠀⠀
⠀⠀⠀⠀⢠⡟⠀⠀⡼⠁⠀⠀⣰⠏⠀⠈⣟⣧⠀⠀⠀⠀⢻⣆⠀⠀⠈⣧⡿⠀⠈⠉⠛⠛⣻⣿⡿⢿⣿⡍⠉⠀⠀⠀⠀⠀⠀⠀⡾⠁⠀⠀⠀⢀⣴⠀⠀⡾⣿⠁⠀⠀⠘⣧⠀⠀⢿⠘⣟⠀⠀⢻⡄⠀
⠀⠀⢀⣠⡟⠀⢀⡾⠃⠀⠀⣰⡏⠀⠀⠀⣻⠘⣧⠀⠀⠀⠀⢻⣷⡄⠀⠘⢷⡀⠀⠀⠀⠀⠩⣉⠁⠈⣛⡁⠀⠀⠀⠀⠀⠀⣀⣾⠁⠀⠀⣀⣠⣟⠁⠀⣠⣤⡟⠀⠀⠀⠀⠘⣧⡄⠘⡇⠙⣇⠀⠀⠻
*/
#include <bits/stdc++.h>
using namespace std;
#define i64 long long
#define ld long double
#define ull unsigned long long
#define bit(n,i) ((n>>i)&1)
#define pii pair<int,int>
#define sz(x) (int)x.size()
#define FOR(i,a,b) for(int i=a; i<=b; i++)
#define FOD(i,a,b) for(int i=a; i>=b; i--)
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(),x.end()
#define __sumairu__ signed main()
#define die_hard_onimai_fan void seggs()
#define file(name) if(fopen(name".inp","r")){freopen(name".inp","r",stdin);freopen(name".out","w",stdout);}
#define brute(name) if(fopen(name".inp","r")){freopen(name".inp","r",stdin);freopen(name".ans","w",stdout);}
#define TIME (1.0*clock()/CLOCKS_PER_SEC)
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ai(n) array<int,n>
#define dbg(x) {cout<<#x<<' '<<x<<endl;}
#define dbgF(arr,l,r) {cout<<#arr;FOR(_i,l,r)cout<<' '<<(arr)[_i];cout<<endl;}
#define dbgArr(arr,n) {cout<<#arr;FOR(_i,1,n)cout<<' '<<(arr)[_i];cout<<endl;}
#define el '\n'
template <typename T,typename U>
ostream& operator<<(ostream &os,pair<T,U>p){return os<<"{"<<p.fi<<", "<<p.se<<"}";}
mt19937_64 rd(chrono::steady_clock::now().time_since_epoch().count());
i64 Rand(i64 l,i64 r)
{
i64 ans=l+rd()%(r-l+1);
assert(l<=ans&&ans<=r);
return ans;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
//const i64 base=1e9+7;
//const i64 mod=(1ll<<53)+5;
#define int long long
#define debug 0
//const int mod=1e9+7;
//const int mod=998244353;
const int inf=1e9;
const i64 infl=1e18;
///check the limits, dummy
const int N=1e5+5;
int n,k,X,Y;
int x[N],y[N];
namespace sub1
{
void solve()
{
auto f=[&](int m)->int{
int nx=x[1]*m;
int ny=y[1]*m;
int dist=abs(X-nx)+abs(Y-ny);
return max(dist-m*k,0ll);
};
int l=1,r=inf;
while(r-l>10)
{
int x1=(l*2+r)/3;
int x2=(l+2*r)/3;
int v1=f(x1),v2=f(x2);
if(v1<v2||(v1==0&&v2==0))r=x2;
else l=x1;
}
// cout<<f(2)<<el;
// cout<<l<<' '<<r<<el;
int ans=-1;
FOR(i,l,r)if(f(i)==0)
{
ans=i;
break;
}
cout<<ans<<el;
}
}
namespace k0
{
void solve()
{
int sumX=0,sumY=0;
FOR(i,1,n)
{
sumX+=x[i];
sumY+=y[i];
}
int ans=inf;
if(sumX==X&&sumY==Y)ans=n;
if(sumX==0||sumY==0)
{
if(ans==inf)ans=-1;
cout<<ans<<el;
return;
}
int curX=0,curY=0;
FOR(i,1,n)
{
curX+=x[i];
curY+=y[i];
if(((X-curX)%sumX==0&&(X-curX)/sumX>=0) && ((Y-curY)%sumY==0&&(Y-curY)/sumY>=0) && (X-curX)/sumX==(Y-curY)/sumY)
{
chmin(ans,i+n*(Y-curY)/sumY);
}
}
if(ans==inf)ans=-1;
cout<<ans<<el;
}
}
die_hard_onimai_fan
{
cin>>n>>k>>X>>Y;
FOR(i,1,n)cin>>x[i]>>y[i];
if(X==0&&Y==0)
{
cout<<0<<el;
return;
}
if(n==1)sub1::solve();
else k0::solve();
}
__sumairu__
{
FAST
file("");
int tt=1;cin>>tt;
while(tt--)seggs();
cerr<<"\nTime elapsed: "<<TIME<<" s.\n";
}
/**
4
1 2 2 2
1 1
1 2 -2 -2
1 1
1 2 0 0
1 1
3 0 -3 9
-1 2
-2 3
4 -1
1
1 0 -39267054 -13736220
-19633527 -6868110
*/
Details
Tip: Click on the bar to expand more detailed information
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 1ms
memory: 3972kb
input:
300 1 32286 -66773299 39159226 2655 14568 1 9900506 22484330 26135209 -33930 -9866575 1 669210 -40846340 -58419438 -529764 8866 1 74 -74443560 -78969527 -14 -37 1 473964 -91643319 -21680398 106817 243107 1 8543824 31629618 -37823687 1090776 4153469 1 16 -8109 -8410 -16 0 1 794120 -60084819 -21436725...
output:
2397 48619539 135 1227305 914 13 -1 96 28 1092928 42688085 -1 40791405 1 54608218 168 3415 13660 -1 53118060 19256086 17049 162101612 168026244 -1 147383845 16356862 158113199 367 19 -1 212 7 6677 13 56318408 0 -1 5 -1 107373214 7 176722 26 90888792 562 -1 3189099 655611 159239 1015616 60054 16874 8...
result:
ok 300 numbers
Test #2:
score: 10
Accepted
time: 1ms
memory: 3848kb
input:
300 1 0 14658671 -17744707 -19 23 1 0 -43777875 2899010 1318511 -388002 1 0 -39267054 -13736220 -19633527 -6868110 1 0 51104805 90132261 1473 -925 1 0 -30105792 20070528 48 -32 1 0 -73521410 -3106528 7939241 3095051 1 0 1934605 -4643052 -5 12 1 0 10981610 -30724102 5490805 -15362051 1 0 -8877616 887...
output:
-1 -1 2 -1 -1 -1 -1 2 -1 -1 -1 1 1 -1 1 -1 -1 504450 -1 383792 -1 2 -1 -1 -1 2 -1 1 551573 1 -1 1 -1 -1 -1 -1 290386 -1 -1 -1 -1 -1 1 -1 -1 122858 -1 1 -1 -1 1 -1 2 -1 1 1 -1 -1 558002 0 -1 1 -1 -1 -1 -1 -1 1 1 2 -1 2 -1 -1 -1 -1 2 -1 453621 2 2 -1 -1 127092 -1 -1 2 2 -1 198741 -1 -1 2 1 -1 -1 -1 2 ...
result:
ok 300 numbers
Test #3:
score: 10
Accepted
time: 1ms
memory: 3952kb
input:
300 1 342739 0 84733186 0 0 1 1 -71236915 69825956 0 0 1 1 96944547 67493888 0 0 1 101010 10720443 27403069 0 0 1 0 -47050862 27820930 0 0 1 299851 -32954036 24041633 0 0 1 22039 16175909 -32970576 0 0 1 54 -92637795 -64306686 0 0 1 65 -42213950 -76922091 0 0 1 48846 0 20220443 0 0 1 4641 0 0 0 0 1 ...
output:
248 141062871 164438435 378 -1 191 2230 2906380 1832863 414 0 -1 21701397 25503860 3505 1570 43 56654328 1699 52308137 7951717 89151814 4773275 -1 243123 13 -1 69375 216700 58 114 457 35773753 1749173 -1 5825141 -1 28683350 117459 201508 64575587 323716 16610172 3959091 0 570 34498369 21969418 19289...
result:
ok 300 numbers
Test #4:
score: 10
Accepted
time: 1ms
memory: 3972kb
input:
300 1 491 19238896 24359756 2923207 -8745945 1 28452 -33430186 -3983771 18956 9495 1 1198593 -53848855 -4734461 93056 1105536 1 676 2931070 -9330910 52 -67 1 10 55228984 8970 -5 0 1 765812 2781176 64328480 -208 -223 1 0 -18744011 -35145767 -24 -45 1 251234 23812841 -10427626 -6279 -6797 1 996 -44886...
output:
-1 37413957 58583316 15424 11047591 88 -1 137 103025 69345443 2 -1 -1 4395 -1 -1 -1 -1 537956 149379205 -1 -1 25894733 440611 8990 3 -1 -1 -1 52207537 60700 420024 19149414 1 10 -1 52 -1 15156244 -1 320 -1 17647291 16255 0 3325 34073206 50713 -1 495 1 6 599074 3 -1 54344608 -1 30919544 -1 -1 11 -1 2...
result:
ok 300 numbers
Test #5:
score: 0
Wrong Answer
time: 1ms
memory: 3976kb
input:
686 4 123 61343816 -81149292 43 62 -26 -93 68 31 -103 0 2 41 5546 -92990467 -40 0 -25 0 6 835927 -25588646 -89091109 644485 191442 677934 157993 398739 437187 762871 73056 776002 59925 553067 282859 2 542128 21060442 -2011 -23932 0 -25454 0 3 1 44172958 49903094 -1 0 -1 0 0 0 1 4491 18010618 -313236...
output:
-1 -1 -1 -1 -1 5805 -1 282 -1 -1 -1 12 17505368 -1 7 -1 -1 -1 -1 -1 0 1396 -1 -1 -1 -1 -1 -1 -1 39193857 -1 -1 -1 -1 -1 862 -1 -1 -1 -1 -1 134 -1 -1 172988585 -1 2159 -1 137673246 -1 -1 458486 -1 -1 -1 -1 -1 -1 -1 124524118 -1 -1 -1 -1 5039527 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 16783 0 ...
result:
wrong answer 1st numbers differ - expected: '1202474', found: '-1'
Test #6:
score: 0
Wrong Answer
time: 1ms
memory: 3956kb
input:
684 7 0 -4659965 65259689 -4659965 -99999977 0 0 0 0 0 0 4659965 99999979 0 0 0 0 1 0 18167938 67528693 18167938 67528693 7 0 -98200220 34188772 -98200220 34188772 -68294507 12668575 -28670964 -87244428 -98971553 90836074 74941179 92402443 10378449 63151034 -11200823 12733866 3 0 -80260647 -12683275...
output:
-1 1 1 -1 1 -1 -1 -1 1 6 2128095 -1 1 -1 306230 -1 6 -1 5 -1 2804421 2 -1 -1 -1 1 -1 -1 -1 1 -1 -1 3 -1 1354128 1 -1 -1 -1 -1 1560100 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 10 -1 5 -1 6 -1 2 -1 1346785 -1 -1 1 1451066 -1 5 -1 -1 5287866 -1 -1 -1 -1 2 -1 -1 -1 -1 -1 1 -1 7 -1 -1 6 3298596 -1 -1...
result:
wrong answer 1st numbers differ - expected: '578408832', found: '-1'
Test #7:
score: 0
Wrong Answer
time: 1ms
memory: 3956kb
input:
667 6 22320 -47869922 -94574425 -35667 -912623 452472 -751486 42399 685787 -602148 221313 389986 58340 504503 896866 3 568 40479510 -78492210 -218 -454519 249230 -310323 -501776 -456425 4 96 -34634275 -41782650 450066 2475397 -1983097 1089604 -2006742 1395784 394497 -1700181 2 586988 87270830 324220...
output:
-1 -1 -1 -1 2115032 6492421 -1 -1 -1 10818277 49646093 214611 -1 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 4 -1 -1 464 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 617 -1 -1 171 0 -1 -1 245 -1 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 -1 228610 -1 -1 388947 -1 -1 -1 -1 -1 -1 3 -1 -1 -1 -1 6 -1 -1 -1...
result:
wrong answer 4th numbers differ - expected: '239385813', found: '-1'
Test #8:
score: 0
Wrong Answer
time: 11ms
memory: 4112kb
input:
5026 7 1536 96224177 3215062 -431 -1063 -930 207 392 -343 -151 -351 190 240 708 -222 1084 -118 2 2007 4875 8961 0 -1006 1282 725 3 74 6255 36271857 2 0 2 0 39 0 4 299644 51336139 54387095 -223835 -75808 -50044 -249599 -36180 -263463 -257793 -41851 5 87337 46515166 83800720 -45698 -41639 -38633 -4870...
output:
-1 -1 -1 -1 -1 -1 781696 1860552 -1 -1 -1 10669352 113239787 -1 -1 -1 -1 -1 79 -1 -1 -1 -1 6292206 -1 -1 -1 -1 -1 -1 -1 3515420 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1404 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 769 -1 -1 -1 -1 -1 -1 78 -1 -1 20539291 -1 -1 49196973 -1 -1 -1 -1 -1 -1 -1 -1 -...
result:
wrong answer 1st numbers differ - expected: '69860', found: '-1'
Test #9:
score: 0
Wrong Answer
time: 14ms
memory: 4156kb
input:
5021 4 0 -12747354 40715188 8473127 -24739598 -4402460 47229129 -63791499 59230380 38500351 -16265125 1 0 13024199 16963243 -2413 -27747 4 0 85556443 48034225 66661568 99999993 18894875 99999991 -19570239 -99999994 -65986204 -99999993 1 0 -64373357 -92003118 3 0 3 0 -57596351 -55622531 -97485 -45744...
output:
5 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1017644 3 -1 -1 -1 -1 3 9 -1 -1 -1 -1 -1 3773967 -1 63606 4918116 -1 -1 269616 -1 -1 2 1 -1 5270454 -1 -1 -1 -1 0 -1 -1 -1 1181692 10 4 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 6 -1 1 2331264 13525 -1 -1 -1 -1 8 7 -1 -1 -1 -1 -1 3690734 -1 -1 -1 -1 -1 -1 -1 703624 1 299536...
result:
wrong answer 3rd numbers differ - expected: '202621014', found: '-1'
Test #10:
score: 0
Wrong Answer
time: 119ms
memory: 5452kb
input:
50122 5 25999922 8405 55768791 -1508111 -18663017 17765724 618297 -4046292 -11237396 -7742552 -12278384 6308331 3503946 2 204 -78318892 -78082051 582 -858 -620 -1217 2 33912059 -80164190 40071329 -4 -3 4 -3 1 281690 -6253970 14352972 -4363 328 5 11522477 13398456 -59393899 -173 -366 -221 -193 -484 1...
output:
-1 -1 -1 72 -1 -1 -1 -1 6 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 614 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1800248 -1 -1 1195 -1 -1 17991403 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 6 -1 -1 124956 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 42182698 668 -1 -1 -1 -1 -1 -1 -1 -1 -1 32104 -1 -1 -1 -1 -1 -1 -1 -1 -1 -...
result:
wrong answer 1st numbers differ - expected: '4', found: '-1'