0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ABC052 ARC067 の問題を解いてみました

Last updated at Posted at 2024-01-01

A問題

面積を比較しましょう。どちらの面積も同じ場合、どちらを出力してもok。

#include <bits/stdc++.h>
using namespace std;
//Created by karaju.

int main(void){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if(a * b > c * d){ //面積の大きい方を出力(maxを使ってもいい)
    cout << a * b << endl;
  }
  else{
    cout << c * d << endl;
  }
}

B問題

もし、I が出現したら 変数に +1 して、
D が出現したら 変数に -1 して、
その変数の最大値を出力します。

#include <bits/stdc++.h>
using namespace std;
//Created by karaju.

int main(void){
  int n;
  string s;
  cin >> n >> s;
  int x = 0, ans = 0;
  
  for(int i = 0; i < n; i++){
    if(s[i] == 'I'){ // I なら +1
      x++;
    }
    else{ //D なら -1
      x--;
    }
    if(x > ans) ans = x; //最大値を記録
  }
  cout << ans << endl;
}

C問題

D問題

この問題では、実は 隣の町に移動する と 隣の町にテレポートする 以外の行動を取る必要はありません。
なぜなら、隣の町に移動せずに、そのさらに先の街に移動しても、結局戻る手間が発生して、一度通った道をもう一度往復しなければならないからです。

なので、隣の町に移動する のと 隣の町にテレポートする で、疲労度が少なくなる方を選べばよいです。

#include <bits/stdc++.h>
using namespace std;
//Created by karaju.

int main(void){
  long long n, a, b;
  cin >> n >> a >> b;
  long long x[n];
  for(int i = 0; i < n; i++) cin >> x[i];

  long long ans = 0;
  for(int i = 0; i < n - 1; i++){
    long long cost = (x[i+1] - x[i]) * a;
    //歩きの疲労度を計算する
    
    ans += min(cost, b);
    //隣の町まで歩くか、テレポートするかの楽な方を選ぶ
  }
  cout << ans << endl;
}
0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?