結果

問題 No.1732 ~サンプルはちゃんと見て!~ 16進数と8進数(2)
ユーザー tnakao0123tnakao0123
提出日時 2021-11-07 16:26:47
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,916 bytes
コンパイル時間 472 ms
コンパイル使用メモリ 53,764 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-08 22:22:20
合計ジャッジ時間 2,215 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1732.cc:  No.1732 ~サンプルはちゃんと見て!~ 16進数と8進数(2) - yukicoder
 */

#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>

using namespace std;

/* constant */

const int MAX_N = 200;
const char S0[] = "ACCACCCCCCCCABACAAFFE"; // 05314531463146314527262527776
const char S1[] = "BBCCCFACAC"; // 013571463726254
const char S2[] = "CCBBA"; // 03145672 = 1100 1100 1011 1011 1010

/* typedef */

typedef vector<int> vi;

/* global variables */

/* subroutines */

void hex2oct(const char s[]) {
  vi hs, cs(8, 0);
  int l = strlen(s);
  for (int i = l - 1; i >= 0; i -= 3) {
    int x = 0;
    for (int d = 0; d < 3; d++)
      x |= (i >= d ? s[i - d] - 'A' + 10 : 0) << (d * 4);
    while (x > 0) {
      int h = x & 7;
      hs.push_back(h);
      cs[h]++;
      x >>= 3;
    }
  }
  reverse(hs.begin(), hs.end());

  printf("%s -> ", S0);
  for (auto h: hs) printf("%d", h); putchar(' ');
  for (int i = 0; i < 8; i++) printf("%d", cs[i]);
  putchar('\n');
}

/* main */

int main() {
  /*
    Let r=n%3,
    r == 0 -> |5,6,7|2,3,6,7|1,3,5,7|2,3,4,5,6,7|
    r == 1 -> |0|0|1|2,3,4,5,6,7|
    r == 2 -> |0|2,3|1,3,5,7|2,3,4,5,6,7|
  */
  //hex2oct(S0); hex2oct(S1); hex2oct(S2);

  int tn;
  scanf("%d", &tn);

  while (tn--) {
    int n;
    scanf("%d", &n);

    int q = n / 3, r = n % 3;

    if (r == 0) {
      if (q % 7 != 0) { puts("-1"); continue; }
      int x = n / 21;
      while (x--) printf("%s", S0); putchar('\n');
    }
    else if (r == 1) {
      if ((q * 4 + 2) % 7 != 0) { puts("-1"); continue; }
      int x = (n - 10) / 21;
      printf("%s", S1);
      while (x--) printf("%s", S0); putchar('\n');
    }
    else { // r == 2
      if ((q * 4 + 3) % 7 != 0) { puts("-1"); continue; }
      int x = (n - 5) / 21;
      printf("%s", S2);
      while (x--) printf("%s", S0); putchar('\n');
    }
  }
  return 0;
}

0