結果

問題 No.775 tatyamと素数大富豪(hard)
ユーザー square1001square1001
提出日時 2019-03-27 15:46:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,912 bytes
コンパイル時間 1,401 ms
コンパイル使用メモリ 98,740 KB
実行使用メモリ 14,624 KB
最終ジャッジ日時 2024-04-22 02:58:53
合計ジャッジ時間 4,994 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,624 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
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 4 ms
5,376 KB
testcase_09 AC 5 ms
5,376 KB
testcase_10 AC 5 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 4 ms
5,376 KB
testcase_14 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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