kichi2004's BLOG

競技プログラミングの参加記とか日常とか。(※Google Analyticsを使用しています)

競プロ

「AtCoder Beginner Contest 124」に参加しました

投稿日:2019年4月13日 更新日:

コンテストページはこちら

結果

全完 [A(100), B(200), C(300), D(400)] 39:46 ペナルティ: 1 (+5:00 -> 44:46)
・順位: 313位
・パフォーマンス: 1600 (Inner: 1718)
・Rating変化: 1142 -> 1198 (+56) [Rating最高値]

各問題の解法

A問題 (100点)

提出詳細
やるだけ。

int A, B;
cin >> A >> B;
if (A > B) {
  cout << A + max(A - 1, B) << endl;
} else {
  cout << B + max(A, B - 1) << endl;
}

B問題 (200点)

提出詳細
やるだけ。

  int N;
  cin >> N;
vector<int> H(N);
int max, ans = 1;
cin >> max;
for (int i = 1; i < N; i++){
  int h;
  cin >> h;
  if (max <= h) {
    ans++;
    max = h;
  }
}
cout << ans << endl;

C問題 (300点)

白黒白黒・・・・ と 黒白黒白・・・・ をそれぞれ試して小さい方を取る。
提出詳細

string S;
cin >> S;
int N = S.size();
vector<int> ans(2);

for(int i = 0; i < 2; i++) {
  //i = 0: 1010101....
  //i = 1: 0101010....
  //でそれぞれ塗り替える必要のある回数を数える
 int cnt = 0;
  for (int j = 0; j < N; j++)
  {
    if (S[j] != '0' + (j % 2 == i))
      cnt++;
  }
  ans[i] = cnt;
}
cout << min(ans[0], ans[1]) << endl;

D問題(400点)

提出詳細
0が連続する区間を求めておいて、K個埋めるものを N-K+1 パターン試す。

int N = ReadInt;
int K = ReadInt;
string S = Read;

var list = new List<Pair<int, int>>();
int l = 10000000, r = 0;
//0が(1つ以上)連続する区間について、(開始のindex, 個数)をメモしてlistに入れる
for (int i = 0; i < N; i++)
{
    if (S[i] == '0')
    {
        l = Min(l, i);
        r++;
    }
    else if (r != 0)
    {
        list.Add(make_pair(l, r));
        l = 10000000;
        r = 0;
    }
}

//最後が0だったときは、最後の区間も追加
if (r != 0) list.Add(make_pair(l, r));
//すべての区間について指示できる場合は、全員の人数を出力
if (list.Count <= K)
{
    Console.WriteLine(N);
    return;
}

//count: ループ回数, max: 答え
int count = list.Count - K + 1, max = list[K].first;
for (int i = 1; i < count; i++)
{
    //範囲の左端
    int A = list[i - 1].first + list[i - 1].second;
    //範囲の右端+1
    int B = i == count - 1 ? N : list[i + K].first;
    max = Max(max, B - A);
}

Console.WriteLine(max);

感想

初めてABCで全完しました!!!!
かつ、Beginnerで初1600perf!!!
めちゃめちゃ嬉しい!!
次落とさなければ無事に水色になれそうです!

-競プロ

執筆者:


comment

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

CAPTCHA


関連記事

no image

「AtCoder Beginner Contest 121」に参加しました

コンテストページはこちら 結果 3完 [A(100), B(200), C(300)] 11:16 ペナルティ: 0 ・順位: 1006位 ・パフォーマンス: 1108 ・Rating変化: 1039 …

no image

AtCoder 解説についての考え

kichi2004 です. 先日,AtCoder の解説についてのツイートを複数行ったところ,かなり広範囲に広まってしまい,いくつかのルートでは,誤解を含んで広まっているようでした. この記事では,A …

no image

「AtCoder Beginner Contest 119」に参加しました

コンテストページはこちら 結果 3完 [A(100), B(200), D(400)] 90:24 ペナルティ: 1 ・順位: 524位 ・パフォーマンス: 1395 ・Rating変化: 986 – …

no image

「M-SOLUTIONS プロコンオープン」に参加しました

コンテストページはこちら 結果 3完 [A(100), B(200), D(500)] 68:17 ペナルティ: 0 ・順位: 725位 (Rated) ・パフォーマンス: 1498 ・Rating変 …

no image

「AtCoder Beginner Contest 128」に参加しました

コンテストページはこちら 結果 4完 [A(100), B(200), C(300), D(400)] 72:50 ペナルティ: 4 (-> 92:00) ・順位: 896位 (Rated) ・パフォ …