QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#354955#6516. New but Nostalgic ProblemSurvivor_winnerWA 11ms34820kbC++14847b2024-03-16 09:54:152024-03-16 09:54:15

Judging History

你现在查看的是最新测评结果

  • [2024-03-16 09:54:15]
  • 评测
  • 测评结果:WA
  • 用时:11ms
  • 内存:34820kb
  • [2024-03-16 09:54:15]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
using namespace std;
string s[1000010];
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	int t;
	cin >> t;
	while (t--)
	{
		int n, k;
		cin >> n >> k;
		for (int i = 1; i <= n; i++) cin >> s[i];
		sort(s + 1, s + n + 1);
		string ans = s[n];
		deque<pair<string, int>> q;
		for (int i = 2; i <= n; i++)
		{
			string t = "";
			for (int j = 0; j < s[i].size() && j < s[i - 1].size(); j++)
			{
				if (s[i][j] == s[i - 1][j]) t += s[i][j];
				else break;
			}
			while (!q.empty() && q.front().second < i - k + 1) q.pop_front();
			while (!q.empty() && q.back().first < t) q.pop_back();
			q.push_back(make_pair(t, i - 1));
			if (q.front().first < ans) ans = q.front().first; 
		}
		cout << (ans != "" ? ans : "EMPTY") << '\n';
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 34808kb

input:

2
5 3
gdcpc
gdcpcpcp
suasua
suas
sususua
3 3
a
b
c

output:

gdcpc
EMPTY

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 11ms
memory: 34820kb

input:

20000
5 3
apveofpr
irdbqk
rnionnjjrk
wrpihlsw
ofylfsriof
5 4
iiltghqg
kybhogptqf
jfnmqxzrdq
rpztcluq
tzmnrcjae
5 5
ysp
vujmkkcutl
ksawqeiiaf
waukilaq
wmlsutlued
5 3
pikybt
yiqmqvtjeq
tyrsoihf
vnvjrxpus
cuubpacubb
5 2
rihuvikhg
twrsuoervz
ukiekoohw
eysqgndpf
sxswpeqtaf
5 5
vxzhicbp
nvtdbgqal
jilppvpt...

output:

EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
...

result:

wrong answer 3rd lines differ - expected: 'w', found: 'EMPTY'