GithubHelp home page GithubHelp logo

atcoder's Introduction

atcoder's People

Contributors

taketakeyyy avatar

Watchers

 avatar  avatar

atcoder's Issues

ABC140のD問題で、コーナーケースっぽいやつでコケる

解説PDFをシミュレートするコードが、コーナーケースっぽい testcase_19 でコケるので、テストケースが公開されたら再考する。

def solve():
    N, K = list(map(int, input().split()))
    S = input()
    S = "R" + S + "L"

    endRL = 0  # 端っこのRL
    RL, LR = 0, 0  # RLの数, LRの数
    happy_num = 0  # 幸福な人の数

    M = len(S)
    for i in range(1, M):
        if S[i-1]=="R" and S[i]=="L":
            if (i-1)==0 or i==(M-1):
                endRL += 1
            else:
                RL += 1
        elif S[i-1]=="L" and S[i]=="R":
            LR += 1

        # 初期状態の幸福な人の数を数える
        if (i-1)==0 or i==(M-1):
            continue
        if (S[i-1]=="L" and S[i]=="L") or (S[i-1]=="R" and S[i]=="R"):
            happy_num += 1

    # 幸福な人の数を可能な限り最大化する
    if RL >= LR:
        if K >= LR:
            happy_num += LR*2
            RL -= LR
            K -= LR
        else:
            happy_num += K*2
    else:
        if K >= RL:
            happy_num += RL*2
            LR -= RL
            K -= RL
            if K >= min(LR, endRL):
                happy_num += min(LR, endRL)
            else:
                happy_num += K
        else:
            happy_num += K*2

    print(happy_num)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.