結果
| 問題 |
No.1633 Sorting Integers (Multiple of 2^K)
|
| コンテスト | |
| ユーザー |
noya2
|
| 提出日時 | 2021-07-08 07:50:44 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 427 ms / 2,000 ms |
| コード長 | 1,409 bytes |
| コンパイル時間 | 4,725 ms |
| コンパイル使用メモリ | 256,052 KB |
| 最終ジャッジ日時 | 2025-01-22 18:06:02 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 45 |
ソースコード
#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;
}
noya2