結果

問題 No.205 マージして辞書順最小
ユーザー snrnsidysnrnsidy
提出日時 2021-06-08 10:36:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,064 bytes
コンパイル時間 2,548 ms
コンパイル使用メモリ 212,888 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-08-17 13:37:59
合計ジャッジ時間 3,497 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 2 ms
4,380 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 WA -
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	string res,s;
	vector <string> v;
	int n;
	priority_queue <pair<pair<char,string>, pair<int, int>>, vector<pair<pair<char,string>, pair<int, int>>>, greater<pair<pair<char,string>, pair<int, int>>>> pque;

	cin >> n;

	for (int i = 0; i < n; i++)
	{
		cin >> s;
		v.push_back(s);
	}

	for (int i = 0; i < n; i++)
	{
		pque.push(make_pair(make_pair(v[i][0],v[i].substr(1)), make_pair(i, 0)));
	}

	while (!pque.empty())
	{
		char ch = pque.top().first.first;
		string s = pque.top().first.second;
		int now = pque.top().second.first;
		int idx = pque.top().second.second;
		pque.pop();
		res += ch;

		if (idx + 1 < v[now].length())
		{
			string t = s.substr(1);
			if (t.length() == 0)
			{
				t = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz";
			}
			pque.push(make_pair(make_pair(v[now][idx + 1],t), make_pair(now, idx + 1)));
		}
	}

	cout << res << '\n';

	return 0;
}
0