結果

問題 No.1732 ~サンプルはちゃんと見て!~ 16進数と8進数(2)
ユーザー milanis48663220milanis48663220
提出日時 2021-11-05 23:43:27
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 3,048 bytes
コンパイル時間 1,445 ms
コンパイル使用メモリ 126,496 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 08:02:18
合計ジャッジ時間 2,195 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}
string as_base_8(int n){
    string ans;
    while(n){
        ans += (n%8)+'0';
        n /= 8;
    }
    reverse(ans.begin(), ans.end());
    return ans;
}

string as_base_16(int n){
    string ans;
    while(n){
        int r = n%16;
        if(r <= 9) ans += r+'0';
        else ans += (r-10)+'A'; 
        n /= 16;
    }
    reverse(ans.begin(), ans.end());
    return ans;
}

string base8_to_base16(string s){
    int x = 0;
    for(char c: s){
        x = x*8+(c-'0');
    }
    cout << s << ' ' << x << ' ' << as_base_16(x) << endl;
    return as_base_16(x);
}

map<string, string> mp;

void test(){
    for(int x = 0; x < 16*16*16; x++) {
        auto b8 = as_base_8(x);
        auto b16 = as_base_16(x);
        bool ok = true;
        for(char c: b16){
            if(isdigit(c)) ok = false;
        }
        if(ok){
            mp[b16] = b8;
        }
    }
}

int calc_len(int i){
    int len = (i/3)*4;
    if(i%3 == 1) len += 2;
    if(i%3 == 2) len += 3;
    return len;
}

void f(){
    string s = "1234567";
    do{
        auto t = base8_to_base16(s);
        bool ok = true;
        for(char c: t){
            if(isdigit(c)) ok = false;
        }
        if(ok){
            cout << t << endl;
            break;
        }
    }while(next_permutation(s.begin(), s.end()));
}

string s7 = "ABDCC";
string s14 = "BBCCCFACAC";
string s28 = "ACCACCCCCCCCABACAAFFE";

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int t; cin >> t;
    while(t--){
        int n; cin >> n;
        int len = calc_len(n);
        if(len%7 != 0 || len%28 == 21){
            cout << -1 << endl;
            continue;
        }
        string ans;
        if(len%28 == 7) ans += s7;
        if(len%28 == 14) ans += s14;
        for(int i = 0; i < len/28; i++) ans += s28;
        
        cout << ans << endl;
    }
}
0