へんてこのブログ

日々気づいたことや、最近やっていることを書いています

SRM554 Div2

久しぶりにSRMに参加した。
今回は京都のホテルから参戦した。
Easyしか通せなかった。そのEasyも効率悪い書き方してるからヤヴァイ
Easyを出す時に、TopCoderの方でコンパイルしようとしたらエラーが出た。
問題はコメントに日本語を使っていたからだった。
今度から日本語書かないようにする。

教訓:日本語書かない

250

  int find(int redCount, int redHeight, int blueCount, int blueHeight) {
    int result = 0;
    int sum_count = redCount + blueCount;
    for(int i=1;i <= sum_count;i++) {
        int tmp_redCount = redCount;
        int tmp_blueCount = blueCount;
          
        int red_height = 0;
        int red_flag = 1;
        int blue_height = 0;
        int blue_flag = 1;
          
        int j = 0;
        for(j = 0 ; j < i ; j++) {
            if(j % 2 == 0) {
                if(tmp_redCount != 0) {
                    tmp_redCount--;
                    red_height += redHeight;
                }else {
                    red_flag = 0;
                    break;
                }
            }else {
                if(tmp_blueCount != 0) {
                    tmp_blueCount--;
                    red_height += blueHeight;
                }else {
                    red_flag = 0;
                    break;
                }
            }
        }
        
        tmp_redCount = redCount;
        tmp_blueCount = blueCount;
        
        for(j=0;j<i;j++) {
            if(j % 2 == 0) {
                if(tmp_blueCount != 0) {
                    tmp_blueCount--;
                    blue_height += blueHeight;
                }else {
                    blue_flag = 0;
                    break;
                }
            }else {
                if(tmp_redCount != 0) {
                    tmp_redCount--;
                    blue_height += redHeight;
                }else {
                    blue_flag = 0;
                    break;
                }
            }
        }
          
        if(blue_flag && red_flag) {
            if(blue_height == red_height) result++;
            else result += 2;
        }else if(red_flag || blue_flag){
            result++;
        }
        
    }
    return result;
  }