結果

問題 No.910 素数部分列
ユーザー qsako6qsako6
提出日時 2019-10-18 23:17:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,413 bytes
コンパイル時間 1,062 ms
コンパイル使用メモリ 119,632 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-08 02:23:25
合計ジャッジ時間 3,719 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 WA -
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 3 ms
4,380 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 5 ms
4,380 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 4 ms
4,376 KB
testcase_36 AC 4 ms
4,380 KB
testcase_37 AC 5 ms
4,376 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 3 ms
4,380 KB
testcase_43 AC 4 ms
4,380 KB
testcase_44 AC 4 ms
4,376 KB
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 AC 3 ms
4,380 KB
testcase_49 AC 2 ms
4,380 KB
testcase_50 AC 2 ms
4,376 KB
testcase_51 AC 2 ms
4,380 KB
testcase_52 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;
using i64 = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
const int INF = (1 << 30);
const i64 INFL = (1LL << 62);
const i64 MOD = 1000000007;
template <class T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
template <class T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
template <class T>
i64 mod_pow(i64 a, i64 n, T mod) {
  mod = (i64)mod;
  i64 res = 1, p = a % mod;
  while (n) {
    if (n & 1) res = res * p % mod;
    p = p * p % mod;
    n >>= 1;
  }
  return res;
}
void print() { std::cout << std::endl; }
template <typename T, typename... A>
void print(const T& first, const A&... rest) {
  cout << sizeof...(rest) << endl;
  std::cout << first;
  if (sizeof...(rest)) std::cout << " ";
  print(rest...);
}
template <typename... A>
void print(const A&... rest) {
  print(rest...);
}
template <typename A>
void print(const std::vector<A>& v) {
  std::for_each(v.begin(), v.end(), [](A x) { std::cout << x << " "; });
  std::cout << std::endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = 0;
  int l = -1;
  int r = -1;
  int cnt_1 = 0;
  int cnt_9 = 0;
  rep(i, n) {
    if (s[i] == '1') ++cnt_1;
    if ((s[i] != '1') && (s[i] != '9')) {
      ++ans;
    } else if (s[i] == '1' && l == -1) {
      l = i;
    } else if (s[i] == '9') {
      r = i;
      ++cnt_9;
    }
  }
  if (l != -1 && r != -1) {
    int c1 = 0;
    int c9 = 0;
    for (int i = l; i <= r; ++i) {
      if (s[i] == '1') ++c1;
      if (s[i] == '9') ++c9;
    }

    ans += min(c1, c9);  // 19の個数
    // 991
    int rest9 = cnt_9 - min(c1, c9);
    int rest1 = cnt_1 - min(c1, c9);
    if (c9 > c1) {
      rest9 += c9 - c1;
    } else {
      rest1 += c1 - c9;
    }
    if (rest9 > 0 && rest1 > 0) {
      ans += (rest9 / 2);
      rest1 -= (rest9 / 2);
    }
    // 11
    ans += (max(rest1, 0)) / 2;
  } else {
    ans += cnt_1 / 2;
  }
  cout << ans << endl;

  return 0;
}
0