結果

問題 No.1633 Sorting Integers (Multiple of 2^K)
ユーザー noya2noya2
提出日時 2021-07-08 07:50:44
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 280 ms / 2,000 ms
コード長 1,409 bytes
コンパイル時間 4,593 ms
コンパイル使用メモリ 264,976 KB
実行使用メモリ 34,028 KB
最終ジャッジ日時 2023-10-14 02:02:39
合計ジャッジ時間 9,907 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,352 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 1 ms
4,352 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 1 ms
4,352 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 1 ms
4,352 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,352 KB
testcase_23 AC 244 ms
29,928 KB
testcase_24 AC 264 ms
32,100 KB
testcase_25 AC 280 ms
34,028 KB
testcase_26 AC 239 ms
29,652 KB
testcase_27 AC 258 ms
31,696 KB
testcase_28 AC 218 ms
27,144 KB
testcase_29 AC 260 ms
31,960 KB
testcase_30 AC 218 ms
27,364 KB
testcase_31 AC 240 ms
29,912 KB
testcase_32 AC 163 ms
20,940 KB
testcase_33 AC 10 ms
4,348 KB
testcase_34 AC 2 ms
4,352 KB
testcase_35 AC 13 ms
4,716 KB
testcase_36 AC 6 ms
4,348 KB
testcase_37 AC 18 ms
5,336 KB
testcase_38 AC 94 ms
13,600 KB
testcase_39 AC 11 ms
4,424 KB
testcase_40 AC 2 ms
4,352 KB
testcase_41 AC 66 ms
10,652 KB
testcase_42 AC 3 ms
4,348 KB
testcase_43 AC 10 ms
4,352 KB
testcase_44 AC 100 ms
14,096 KB
testcase_45 AC 34 ms
7,072 KB
testcase_46 AC 5 ms
4,348 KB
testcase_47 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
using namespace std;
using namespace atcoder;
using namespace internal;
using ll = long long;
template <typename SG>
bool chmax(SG &a, const SG &b){if(a<b){a = b; return true;} return false;}

using VP = pair<vector<int>,pair<ll,int>>;
using LI = pair<ll,int>;

int main(){
    int n; cin >> n;
    int ans = 0;
    vector<int> cnt(9,0);
    rep(i,9) cin >> cnt[i];
    queue<VP> que;
    que.push(VP(cnt,LI(0,0)));
    vector<ll> ju(18,1LL);
    repp(i,18,1) ju[i] = ju[i-1] * 10LL;
    vector<ll> ni(49,1LL);
    repp(i,49,1) ni[i] = ni[i-1] * 2LL;
    while (!que.empty()){
        VP p = que.front(); que.pop();
        vector<int> v = p.first;
        ll m = p.second.first;
        int d = p.second.second;
        if (d == n){
            int score = 0;
            while (m % 2LL == 0LL){
                score++;
                m /= 2LL;
            }
            chmax(ans,score);
            continue;
        }
        rep(i,9){
            if (v[i] == 0) continue;
            ll newdegit = ll(i + 1) * ju[d];
            if ((m + newdegit) % ni[d+1] == 0){
                chmax(ans,d+1);
                auto q = v;
                q[i]--;
                que.push(VP(q,LI(m+newdegit,d+1)));
            }
        }
    }
    cout << ans << endl;
}
0