提出 #67517488


ソースコード 拡げる

#include <bits/stdc++.h>

using namespace std;

#define overload4(_1, _2, _3, _4, name, ...) name
#define rep1(n) for(int i = 0; i < (int)(n); ++i)
#define rep2(i, n) for(int i = 0; i < (int)(n); ++i)
#define rep3(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep4(i, a, b, c) for(int i = (a); i < (int)(b); i += (c))
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)

#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
#define Sort(a) (sort((a).begin(), (a).end()))
#define RSort(a) (sort((a).rbegin(), (a).rend()))
#define UNIQUE(a) (a.erase(unique((a).begin(), (a).end()), (a).end()))

using i64 = int64_t;
using i128 = __int128_t;

using ll = long long;
using ul = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<long long>;
using vc = vector<char>;
using vst = vector<string>;
using vd = vector<double>;
using vld = vector<long double>;
using P = pair<long long, long long>;

template<class T> long long sum(const T &a){ return accumulate(a.begin(), a.end(), 0LL); }
template<class T> auto min(const T &a){ return *min_element(a.begin(), a.end()); }
template<class T> auto max(const T &a){ return *max_element(a.begin(), a.end()); }

const long long MINF = 0x7fffffffffff;
const long long INF = 0x1fffffffffffffff;
const long long MOD = 1000000007;
const long double EPS = 1e-9;
const long double PI = acos(-1);

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; }

template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p){ is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p){ os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for(T &in : v) is >> in; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v){ for(int i = 0; i < (int) v.size(); ++i){ os << v[i] << (i + 1 != (int) v.size() ? " " : ""); } return os; }
template <typename T, typename S> ostream &operator<<(ostream &os, const map<T, S> &mp){ for(auto &[key, val] : mp){ os << key << ":" << val << " "; } return os; }
template <typename T> ostream &operator<<(ostream &os, const set<T> &st){ auto itr = st.begin(); for(int i = 0; i < (int) st.size(); ++i){ os << *itr << (i + 1 != (int) st.size() ? " " : ""); itr++; } return os; }
template <typename T> ostream &operator<<(ostream &os, const multiset<T> &st){ auto itr = st.begin(); for(int i = 0; i < (int) st.size(); ++i){ os << *itr << (i + 1 != (int) st.size() ? " " : ""); itr++; } return os; }
template <typename T> ostream &operator<<(ostream &os, queue<T> q){ while(q.size()){ os << q.front() << " "; q.pop(); } return os; }
template <typename T> ostream &operator<<(ostream &os, deque<T> q){ while(q.size()){ os << q.front() << " "; q.pop_front(); } return os; }
template <typename T> ostream &operator<<(ostream &os, stack<T> st){ while(st.size()){ os << st.top() << " "; st.pop(); } return os; }
template <class T, class Container, class Compare> ostream &operator<<(ostream &os, priority_queue<T, Container, Compare> pq){ while(pq.size()){ os << pq.top() << " "; pq.pop(); } return os; }

template<class T, class U>
void inGraph(vector<vector<T>> &G, U n, U m, bool directed = true, bool zero_index = true){
    G.resize(n);
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        if(!zero_index) a--, b--;
        G[a].push_back(b);
        if(!directed) G[b].push_back(a);
    }
}

template <typename T>
long long binary_search(long long ok, long long ng, T check){
    while(abs(ok - ng) > 1){
        long long mid = (ok + ng) / 2;
        if(check(mid)) ok = mid;
        else ng = mid;
    }
    return ok;
}

template <typename T>
long double binary_search_real(long double ok, long double ng, T check, int iter = 100){
    for(int i = 0; i < iter; ++i){
        long double mid = (ok + ng) / 2;
        if(check(mid)) ok = mid;
        else ng = mid;
    }
    return ok;
}

template <typename T>
long long trisum(T a, T b){
    long long res = ((b - a + 1) * (a + b)) / 2;
    return res;
}

template <typename T>
T intpow(T x, int n){
    T ret = 1;
    while(n > 0) {
        if(n & 1) (ret *= x);
        (x *= x);
        n >>= 1;
    }
    return ret;
}

template <typename T>
T getReminder(T a, T b){
    if(b == 0) return -1;
    if(a >= 0 && b > 0){
        return a % b;
    } else if(a < 0 && b > 0){
        return ((a % b) + b) % b;
    } else if(a >= 0 && b < 0){
        return a % b;
    } else{
        return (abs(b) - abs(a % b)) % b;
    }
}

template<class T, class U> inline T vin(T &vec, U n) { vec.resize(n); for(int i = 0; i < (int) n; ++i) cin >> vec[i]; return vec; }
template<class T> inline void vout(T vec, string s = "\n"){ for(auto x : vec) cout << x << s; }
template<class... T> void in(T&... a){ (cin >> ... >> a); }
void out(){ cout << '\n'; }
template<class T, class... Ts> void out(const T &a, const Ts&... b){ cout << a; (cout << ... << (cout << ' ', b)); cout << '\n'; }
void fout(){ cout << endl; }
template<class T, class... Ts> void fout(const T &a, const Ts&... b){ cout << a; (cout << ... << (cout << ' ', b)); cout << endl; }
void debug(){ cerr << '\n'; }
template<class T, class... Ts> void debug(const T &a, const Ts&... b){ cerr << a; (cerr << ... << (cerr << ' ', b)); cerr << '\n'; }

template<typename T>
string convertBase(T x, int b) {
    string res;
    T t = 1, k = abs(b);
    while(x){
        T num = (x * t) % k;
        if(num < 0) num += k;
        res += num + (num < 10 ? 48 : 87);
        x -= num * t;
        x /= k;
        t *= b / k;
    }
    if(res.empty()) res = '0';
    reverse(res.begin(), res.end());
    return res;
}

ll T;

void input(){
    in(T);
}

void solve(){
    ll a, n; in(a, n);
    ll ans = 0;
    rep(i, 1, 1000000){
        string num1 = to_string(i);
        {
            string num2 = num1;
            reverse(ALL(num2));
            ll num = stoll(num1 + num2);
            string b = convertBase(num, a);
            string rb = b;
            reverse(ALL(rb));
            if(num <= n && b == rb){
                ans += num;
            }
        }
        {
            string num2 = num1;
            num2.pop_back();
            reverse(ALL(num2));
            ll num = stoll(num1 + num2);
            string b = convertBase(num, a);
            string rb = b;
            reverse(ALL(rb));
            if(num <= n && b == rb){
                ans += num;
            }
        }
    }
    out(ans);
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(20);

    T = 1;
    // input();
    while(T--) solve();
}

提出情報

提出日時
問題 C - Palindromic in Both Bases
ユーザ dyktr_06
言語 C++ 23 (gcc 12.2)
得点 350
コード長 7092 Byte
結果 AC
実行時間 1182 ms
メモリ 3604 KiB

コンパイルエラー

Main.cpp: In instantiation of ‘void out(const T&, const Ts& ...) [with T = long long int; Ts = {}]’:
Main.cpp:182:8:   required from here
Main.cpp:124:82: warning: statement has no effect [-Wunused-value]
  124 | template<class T, class... Ts> void out(const T &a, const Ts&... b){ cout << a; (cout << ... << (cout << ' ', b)); cout << '\n'; }
      |                                                                                  ^~~~

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 350 / 350
結果
AC × 3
AC × 33
セット名 テストケース
Sample 00-sample-01.txt, 00-sample-02.txt, 00-sample-03.txt
All 00-sample-01.txt, 00-sample-02.txt, 00-sample-03.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt, 01-27.txt, 01-28.txt, 01-29.txt, 01-30.txt
ケース名 結果 実行時間 メモリ
00-sample-01.txt AC 423 ms 3400 KiB
00-sample-02.txt AC 445 ms 3384 KiB
00-sample-03.txt AC 503 ms 3488 KiB
01-01.txt AC 1182 ms 3484 KiB
01-02.txt AC 423 ms 3516 KiB
01-03.txt AC 1182 ms 3536 KiB
01-04.txt AC 633 ms 3400 KiB
01-05.txt AC 441 ms 3528 KiB
01-06.txt AC 560 ms 3540 KiB
01-07.txt AC 464 ms 3388 KiB
01-08.txt AC 425 ms 3480 KiB
01-09.txt AC 783 ms 3524 KiB
01-10.txt AC 503 ms 3532 KiB
01-11.txt AC 424 ms 3536 KiB
01-12.txt AC 425 ms 3388 KiB
01-13.txt AC 423 ms 3384 KiB
01-14.txt AC 425 ms 3544 KiB
01-15.txt AC 491 ms 3384 KiB
01-16.txt AC 490 ms 3600 KiB
01-17.txt AC 489 ms 3520 KiB
01-18.txt AC 488 ms 3480 KiB
01-19.txt AC 783 ms 3440 KiB
01-20.txt AC 776 ms 3540 KiB
01-21.txt AC 405 ms 3540 KiB
01-22.txt AC 405 ms 3388 KiB
01-23.txt AC 624 ms 3524 KiB
01-24.txt AC 626 ms 3484 KiB
01-25.txt AC 1180 ms 3604 KiB
01-26.txt AC 1179 ms 3528 KiB
01-27.txt AC 551 ms 3484 KiB
01-28.txt AC 551 ms 3384 KiB
01-29.txt AC 445 ms 3532 KiB
01-30.txt AC 444 ms 3488 KiB