結果

問題 No.1729 ~サンプルはちゃんと見て!~ 16進数と8進数(1)
ユーザー umncumnc
提出日時 2022-02-13 00:21:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,478 bytes
コンパイル時間 4,346 ms
コンパイル使用メモリ 262,368 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-11 14:14:35
合計ジャッジ時間 5,726 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= n; ++i)
#define reps(i, s, e) for (ll i = s; i <= e; ++i)
#define rrep(i, n) for (ll i = n - 1; 0 <= i; --i)
#define all(v) v.begin(), v.end()
template <class T> bool chmax(T& a, const T& b) {
  if (a < b) {a = b; return 1;} return 0;
}
template <class T> bool chmin(T& a, const T& b) {
  if (b < a) {a = b; return 1;} return 0;
}
using ll = long long;
using ld = long double;
using cp = complex<ld>;
using pa = pair<ll, ll>;
using tup = tuple<ll, ll, ll>;
using vp = vector<pair<ll, ll> >;
using vtup = vector<tuple<ll, ll, ll> >;
using st = string;
using vs = vector<string>;
using vc = vector<char>;
using vvi = vector<vector<ll> >;
using vvc = vector<vector<char> >;
using vi = vector<ll>;
const ll MOD1 = 1000000007;
const ll MOD2 = 998244353;
const ll INF = (1LL << 60);

void init() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL), cout.tie(NULL);
  cout << fixed << setprecision(15);
}

string to_base_2(string s) {
  string ret = "";
  rep(i, s.size()) {
    if (s[i] == 'A') ret += "1010";
    else if (s[i] == 'B')
      ret += "1011";
    else if (s[i] == 'C')
      ret += "1100";
    else if (s[i] == 'D')
      ret += "1101";
    else if (s[i] == 'E')
      ret += "1110";
    else if (s[i] == 'F')
      ret += "1111";
  }
  return ret;
}

string to_base_8(string s) {
  if (s.size() % 3 == 1) {
    s = "00" + s;
  } else if (s.size() % 3 == 2) {
    s = '0' + s;
  }
  string ret = "";
  for (int i = 0; i < s.size() - 1; i += 3) {
    if (s.substr(i, 3) == "000") ret += "0";
    else if (s.substr(i, 3) == "001") ret += "1";
    else if (s.substr(i, 3) == "010") ret += "2";
    else if (s.substr(i, 3) == "011") ret += "3";
    else if (s.substr(i, 3) == "100") ret += "4";
    else if (s.substr(i, 3) == "101") ret += "5";
    else if (s.substr(i, 3) == "110") ret += "6";
    else if (s.substr(i, 3) == "111") ret += "7";
  }
  return ret;
}

int main() {
  init();

  st n;
  cin >> n;

  string bin = to_base_2(n);
  string oct = to_base_8(bin);

  vi cnt(8);
  rep(i, oct.length()) {
    rep(j, 8) {
      if (oct[i] == j + '0') cnt[j]++;
    }
  }
  ll mx = -1;
  rep(i, 8) chmax(mx, cnt[i]);
  vi ans;
  rep(i, 8) if (cnt[i] == mx) ans.push_back(i);

  rep(i, ans.size()) {
    if (i == ans.size() - 1) cout << ans[i] << endl;
    else cout << ans[i] << " ";
  }
}
0