A - 時刻の正規化 / Time Normalization Editorial by admin
DeepSeek V3Overview
Given time data (H hours M minutes), treat it as (60H+M) minutes elapsed from 0:00, and normalize it into the format of days D, hours h (0-23), and minutes m (0-59).
Analysis
While it is possible to perform the carry-over processing as described in the problem statement (carrying minutes → carrying hours), a more efficient approach is to calculate the “total elapsed minutes.” Since the input constraints can be as large as \(10^9\), performing carry-over processing in a loop would result in a large computational cost and is not efficient. Instead, a mathematical approach using division and modulo operations is appropriate.
Algorithm
- For each input (H, M), calculate the total elapsed minutes: \(total\_minutes = H \times 60 + M\)
- Divide the total elapsed minutes by the number of minutes in a day (24×60=1440) to obtain the number of days D: \(D = total\_minutes \div 1440\)
- Calculate the remaining minutes: \(remaining\_minutes = total\_minutes \mod 1440\)
- Divide the remaining minutes by 60 to obtain the hours h: \(h = remaining\_minutes \div 60\)
- Take the remainder of dividing the remaining minutes by 60 to obtain the minutes m: \(m = remaining\_minutes \mod 60\)
This method yields the same result as the procedure described in the problem statement, but computes it efficiently using only division and modulo operations.
Complexity
- Time complexity: \(O(N)\)
- Space complexity: \(O(N)\)
Since only constant-time computation is performed for each data entry, the total computation is proportional to the input size N.
Implementation Notes
Since input values can be as large as \(10^9\), they must be handled accurately with integer arithmetic
By combining division and modulo operations, normalization can be performed efficiently
The output format must be “days hours minutes” separated by spaces
By performing bulk input reading, even large amounts of input data can be processed quickly
Source Code
import sys
def main():
data = sys.stdin.read().split()
n = int(data[0])
index = 1
results = []
for _ in range(n):
H = int(data[index])
M = int(data[index+1])
index += 2
total_minutes = H * 60 + M
days = total_minutes // (24 * 60)
remaining_minutes = total_minutes % (24 * 60)
h = remaining_minutes // 60
m = remaining_minutes % 60
results.append(f"{days} {h} {m}")
for res in results:
print(res)
if __name__ == "__main__":
main()
This editorial was generated by deepseekv3.
posted:
last update: