QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#141328#6516. New but Nostalgic Problemcy1999RE 1ms3580kbC++2.1kb2023-08-17 10:47:202023-08-17 10:47:23

Judging History

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

  • [2023-08-17 10:47:23]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:3580kb
  • [2023-08-17 10:47:20]
  • 提交

answer

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstring>
#include<map>
using namespace std;

int t; 
int n, k; 
map<char, vector<string> > mp;

int solve(char qwq, int l, int r, int id) {
	//嗯。。 
	if(l+1==r) {
		return l; 
	} 
	string a = mp[qwq][r], b = mp[qwq][r-1];
	int tmp = -1;
	for(int i=id; i<min(a.size(), b.size()); i++) {
		if(a[i]!=b[i]) {
			tmp = id;
			break;
		}
	}
	if(tmp<0) tmp = min(a.size(), b.size());
	if(mp[qwq][r-2].size()<=tmp) {
		return r-1;
	}
	if(mp[qwq][r-1].substr(0, tmp+1) != mp[qwq][r-2].substr(0, tmp+1)) {
		return r-1;
	} //hin好! 
	solve(qwq, l, r-1, tmp); //中嘞,哥。 
}

int main() {
	scanf("%d", &t);
	while(t--) {
		mp.clear();
		scanf("%d%d", &n, &k);
		for(int i=1; i<=n; i++) {
			string t; cin>>t; //哈哈 shift 不知道该怎么取消同步捏。 
			mp[t[0]].push_back(t);
		}
		if(mp.size()>=k) {
			puts("EMPTY");
			continue; 
		} //特判肯定对!! 
		//确实,确实,确实如此,,
		//选出的这几个,最长公共前缀并不一定是字典序最大的。
		//因为长度原因。 草语义内个啥。 
		//那我想想哈,, 
		//但是对应的组别(?)肯定是对的。
		//23333 
		string a, b; 
		char qwq;
		for(auto it = mp.begin(); it!=mp.end(); it++) {
			sort(it->second.begin(), it->second.end());
			if(it->second.size()<k) {
				if(it->second.size()>1) qwq = it->first;
				k -= it->second.size();
				continue;
			}
			if(k>1) qwq = it->first; 
			else k = mp[qwq].size();
			
			break; //233
		}
		//是不是要递归啊?西八。
		//总之这两个肯定是挨在一块的。 
//		for(int i=k-1; i>0; i--) {
////			mp[qwq][i][1] 现在找的是这个。233
////			这不该T了吗?可恶啊,, 
//		}
		int l = solve(qwq, 0, k-1, 1);
		a = mp[qwq][l], b = mp[qwq][l+1];
		
		int i;
		for( i=0; i<min(a.size(), b.size()); i++) {
			if(a[i]!=b[i]) {
				break;
			}
		} //虽然浪费了但是我感觉问题不大。 
		cout<<a.substr(0, i)<<endl;
	}
	return 0;
}
/*

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

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3580kb

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
Runtime Error

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
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
o
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
t
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
w
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPT...

result: