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?

More than 1 year has passed since last update.

AtCoderログ:ABC267

Posted at

ABC267に参加しました

今回はA, B, Cの3完でした。
A:2分
B:19分
C:45分

レート変動

290→331(パフォーマンス:657)

A問題-Saturday

ごり押し

int main() {
  string s;
  cin >> s;
  if (s == "Monday") cout << 5;
  else if (s == "Tuesday") cout << 4;
  else if (s == "Wednesday") cout << 3;
  else if (s == "Thursday") cout << 2;
  else cout << 1;
  cout << endl;
  return 0;
}

B問題-Split?

A問題と同様にベタ書きしました

int main() {
  string s;
  cin >> s;
  vector<bool> retsu(7, false);
  if (s[6] == '0') retsu[0] = true;
  if (s[3] == '0') retsu[1] = true;
  if (s[7] == '0' && s[1] == '0') retsu[2] = true;
  if (s[4] == '0' && s[0] == '0') retsu[3] = true;
  if (s[8] == '0' && s[2] == '0') retsu[4] = true;
  if (s[5] == '0') retsu[5] = true;
  if (s[9] == '0') retsu[6] = true;

  if (s[0] == '1') {
    cout << "No" << endl;
    return 0;
  }
  else {
    rep(i, 5) {
      if (retsu[i] == false && retsu[i + 1] == true) {
        rep3(j, i + 2, 7) {
          if (retsu[j] == false) {
            cout << "Yes" << endl;
            return 0;
          }
        }
      }
    }
  }
  cout << "No" << endl;
  return 0;
}

C問題-Index × A(Continuous ver.)

b[i]を計算後の連続部分数列の和としてO(n)でそれらを求められるような実装にした。

int main() {
  long long n, m;
  cin >> n >> m;
  long long res = -1000000000000000000;
  vector<long long> a(n);
  vector<long long> b(n, -1000000000000000000);
  vector<long long> c(n, -1000000000000000000);
  rep(i, n) cin >> a[i];
  b[0] = 0;
  c[0] = 0;
  rep(i, m) b[0] += a[i] * (i + 1);
  rep(i, m) c[0] += a[i];
  rep(i, n - m) c[i + 1] = c[i] + a[i + m] - a[i];
  res = b[0];
  rep(i, n - m) {
    b[i + 1] = b[i] + a[i + m] * m - c[i];
    res = max(res, b[i + 1]);
  }
  cout << res << endl;
  return 0;
}

D問題-Index × A(Not Continuous ver.)

dpのDとはコンテスト中には気づかなかった...

int main() {
  long long n, m, A;
  cin >> n >> m;
  long long res = -1000000000000000000;
  vector<long long> a(n + 1);
  vector<vector<long long>> dp(n + 1, vector<long long>(m + 1, -1000000000000000000));
  rep3(i, 1, n + 1) cin >> a[i];
  rep3(i, 1, n + 1) {
    dp[i][0] = 0;
    dp[i][1] = a[i];
  }
  rep3(i, 2, n + 1) {
    rep3(j, 1, i + 1) {
      if (j == m + 1) break;
      dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - 1] + a[i] * j);
    }
  }
  rep3(i, m, n + 1) {
    res = max(res, dp[i][m]);
  }
  cout << res << endl;

  return 0;
}
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?