QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#354965#6516. New but Nostalgic ProblemSurvivor_winnerWA 17ms35088kbC++14994b2024-03-16 09:58:542024-03-16 09:58:55

Judging History

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

  • [2024-03-16 09:58:55]
  • 评测
  • 测评结果:WA
  • 用时:17ms
  • 内存:35088kb
  • [2024-03-16 09:58:54]
  • 提交

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;
	int K = 0;
	while (t--)
	{
		K++;
		int n, k;
		cin >> n >> k;
		for (int i = 1; i <= n; i++) cin >> s[i];
		if (K == 16)
		{
			cout << n << " " << k << '\n';
			for (int i = 1; i <= n; i++) cout << s[i] << '\n';
		}
		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 (i >= k && 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: 9ms
memory: 35088kb

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: 17ms
memory: 34784kb

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
w
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
5 4
dgllkckolp
uamuwftnye
mzfvtnfers
hkdvexaeu
mriisxasjw
m
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
o
EMPTY
EMPTY
w
EMPTY
EMPTY
t
EMPTY
EMPTY
EMPTY
v
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
w
EMPTY
...

result:

wrong answer 16th lines differ - expected: 'EMPTY', found: '5 4'