結果
問題 | No.775 tatyamと素数大富豪(hard) |
ユーザー |
![]() |
提出日時 | 2019-03-27 15:46:00 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,912 bytes |
コンパイル時間 | 1,451 ms |
コンパイル使用メモリ | 99,020 KB |
実行使用メモリ | 14,500 KB |
最終ジャッジ日時 | 2024-10-14 01:44:50 |
合計ジャッジ時間 | 5,161 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 9 TLE * 1 |
ソースコード
#include <set>#include <string>#include <vector>#include <iostream>#include <algorithm>using namespace std;const int lim = 100;int main() {int N, K;cin >> N >> K;vector<int> A(N);for (int i = 0; i < N; ++i) {cin >> A[i];}vector<int> cnt(lim);for (int i = 0; i < N; ++i) {++cnt[A[i]];}vector<vector<int> > g;g.push_back(vector<int>());vector<int> cur;for (int i = lim - 1; i >= 10; --i) {if (i % 11 != 0 || cnt[i / 11] == 0) {for (int j = 0; j < cnt[i]; ++j) {cur.push_back(i);g.push_back(cur);}}else {for (int j = 0; j < cnt[i]; ++j) {cur.push_back(i / 11);g.push_back(cur);cur.pop_back();cur.push_back(i);g.push_back(cur);}for (int j = 0; j < cnt[i / 11]; ++j) {cur.push_back(i / 11);g.push_back(cur);}}}reverse(g.begin(), g.end());vector<string> ans;for (vector<int> v : g) {vector<int> rc = cnt;for (int i : v) {--rc[i];}int sum = 0;for (int i = 0; i < lim; ++i) {sum += rc[i];}vector<int> arr;for (int i = 1; i <= 9; ++i) {int rem = sum - rc[i] - rc[i * 11];int t = rc[i];for (int j = rc[i] - 2; j >= rem; j -= 2) {arr.push_back(i * 11);t = j;}for (int j = 0; j < t; ++j) {arr.push_back(i);}}for (int i = 10; i < lim; ++i) {for (int j = 0; j < rc[i]; ++j) {arr.push_back(i);}}sort(arr.begin(), arr.end());set<string> st;do {string s;for (int i : arr) {s += to_string(i);}st.insert(s);} while (next_permutation(arr.begin(), arr.end()));if (st.size() >= K) {string prefix;for (int i : v) {prefix += to_string(i);}vector<string> w(st.begin(), st.end());reverse(w.begin(), w.end());for (int i = 0; i < K; ++i) {ans.push_back(prefix + w[i]);}break;}}for (string s : ans) {cout << s << '\n';}return 0;}