把所有正整数排成三角形,第一行是 $1$,第二行是 $2,3$,第三行是 $4,5,6$,以此类推。那么第二种操作就是往右下移一格。
把操作反过来考虑,容易发现当 $y>x$ 时, 不断把 $y$ 往左上移一定是更优的(如果 $y$ 在第一列就先加 $1$)。
时间复杂度 $O(1)$。
As we are currently experiencing an overwhelming number of web requests for fetching user submissions, we have temporarily disabled the full submissions list. You must now be logged in to view submissions.
Type: Editorial
Status: Open
Posted by: jiangly
Posted at: 2025-12-12 23:42:55
Last updated: 2025-12-12 23:42:59
把所有正整数排成三角形,第一行是 $1$,第二行是 $2,3$,第三行是 $4,5,6$,以此类推。那么第二种操作就是往右下移一格。
把操作反过来考虑,容易发现当 $y>x$ 时, 不断把 $y$ 往左上移一定是更优的(如果 $y$ 在第一列就先加 $1$)。
时间复杂度 $O(1)$。