It was the second participation in the AtCoder Contest, this time only A was AC, I do not know whether B was present or not (as WJ), C was 48/51 correct answer 3 WA, how to do It was sad that I couldn't do almost anything for the last 30 minutes ...
I quickly came up with this, because all I have to do is put together K out of N ...
    list = input().split()
    print(int(list[0]) - int(list[1]) + 1)
Input method without using a list I want to learn quickly ...
It was easy to think about the algorithm because there was a similar problem of lottery in the ant book, I was vaguely wondering if it was for 3 times at first, but 2 times was enough ... This is C
    #include<stdio.h>
     
    int main(){
      int r, g, b, n;
      int cnt = 0;
      scanf("%d %d %d %d\n", &r, &g, &b, &n);
      int x = n / r;
      for(int i=x;i>=0;i--){
        int y = (n - (i * r)) / g;
        for(int j=y;j>=0;j--){
          int z = n - (i * r) - (j * g);
          if(z % b == 0){
            cnt++;
          }
        }
      }
      printf("%d\n", cnt);
      return 0;
    }
Please forgive me for the trauma that I put in x, y, z because of the floating error in the first half ... Please let me know if there is any more.
Postscript: It was AC, I did it
If you write roughly
・ Increase cnt by 1 for each ʻAB in one word  ・ Increase cnta by 1 for the last ʻA
・ Increase cntb by 1 for each B of the head
・ Outputs cnt plus the minimum values of cnta and cntb
    n = int(input())
    list = []
    cnt = 0
    cnta = 0
    cntb = 0
    cntexp = 0
    for i in range(n):
      list.append(input())
      a = list[i].count("AB")
      cnt += a
      if(list[i][-1:] == "A"):
        cnta += 1
      if(list[i][0:1] == "B"):
        cntb += 1
      if((list[i][-1:] == "A")and(list[i][0:1] == "B")):
        cntexp += 1
    cntab = min(cnta, cntb)
    if(cntab == cntexp):
      cntab -= 1
    ans = cnt + cntab
    print(ans)
It was above that I implemented it in consideration of various exception handling, but the last two were WA ... Please tell me what other patterns exist ...
I seemed to be able to solve the D and E problems, but I didn't have enough time so I want to go slowly ...
Recommended Posts