0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

「Diverta 2019 Programming Contest」を終えて

Last updated at Posted at 2019-05-11

2回目のAtCoder Contestの参加となりました、今回はAだけAC、Bが結局あってるのかあってないのかわからない(WJのまま)、Cが48/51正答の3つWAという結果でした、仕方ないとはいえラスト30分間ほとんど何もできなかったのは悲しかった...

A問題

これはすぐに思いつきました、N個のうちK個の数をひとまとめにすればいいだけなので...

    list = input().split()
    print(int(list[0]) - int(list[1]) + 1)

リストを使わない入力方法早く覚えたい...

B問題

蟻本にくじ引きの似たような問題があったのでアルゴリズムを考えるのは楽でした、最初for3回回しなのかな~とぼんやり思ってたけど2回で十分でしたね...こっちは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;
    }

わざわざx, y, zでおいているのは前半でFloatingエラーでまくったトラウマなので許してください...あとあっているか教えてください。

追記:ACでした、やったね

C問題

考えたアルゴリズム

ざっくり書くと
・1つの単語中のAB1つにつきcntを1つ増加
・ラストのAにつきcntaを1増加
・頭のBにつきcntbを1増加
・cntにcntaと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)

これに色々な例外処理を考慮して実装したのが上でしたがラスト2つがWAでした...ほかにどういうパターンが存在するのか教えてください...

D,E問題も解けそうだったけど時間が足りなかったのでゆっくりやっていきたいです...

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?