I'm new to such things, so I don't know. It's just fun to think logically and to output and confirm what you have learned. As I noticed when I was job hunting, some major IT companies give AtCoder scores. In that sense, it may be judged not only as self-satisfaction but also objectively. Right now, I'm solving in order from here "What to do next after registering with AtCoder-If you solve this much, you can fight enough! 10 past questions-".
[Problem summary] There were a total of NN 10000 yen bills, 5000 yen bills, and 1000 yen bills, and the total amount was YY yen. Find one set of the number of bills for each amount that meets these conditions. If such a situation cannot exist, output -1 -1 -1.
[Restrictions]
1≤N≤2000 1000≤Y≤2∗107 N is an integer Y is a multiple of 1000
First of all, did you write the part that should be considered as a commentary? That is. But I'm glad I read it after solving it. I've been addicted to muscle training lately, so I tried to push it through with power play. I think that an absolute solution will come out if there is no time limit, but instead I had to think about how to optimize it. It is the same as the probability and permutation that I did when I was a high school student, and it takes time to ask for all. So, 10,000 yen bill and 5,000 yen bill If you realize that the number of 1000-yen bills will be fixed automatically if you know the number of, this problem seems to be OK.
from sys import stdin
N,Y = [int(x) for x in stdin.readline().rstrip().split()]
a = -1
b = -1
c = -1
for i in range(N+1):
for j in range(N-i+1):
if i+j+(N-i-j) == N and Y == 10000*i + 5000*j + 1000*(N-i-j):
a = i
b = j
c = (N-i-j)
break
print(str(a)+' '+str(b)+' '+str(c))
Even with this, the correct answer was correct, but I regret that I should make efforts to increase the processing speed and reduce the size. I also wanted to remember about format. What I learned this time ・ -Input method in competitive programming -Optimization of combination
is! If you use your head and do it like that, the sense of accomplishment is amazing. Tobacco is delicious. When I didn't know anything about competitive programming, I put the input data in a list, took it out each time, put it in a variable, and so on, so it was a redundant code. I wanted to input beautifully this time, so I tried using list comprehension and stdin module!
The combination is as above! It's just the beginning, but programming is a series of applications of basic knowledge as long as you have a basic concept. ?? ?? If you remember the module each time, you can do it more and more, right? ?? ?? I'm starting to notice the gal inside me. I want to do more and more with an invincible mind. please excuse my poor writing.
Recommended Posts