QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#211368#6635. Strange KeyboardExplodingKonjacWA 78ms7884kbC++205.4kb2023-10-12 15:28:482023-10-12 15:28:49

Judging History

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

  • [2023-10-12 15:28:49]
  • 评测
  • 测评结果:WA
  • 用时:78ms
  • 内存:7884kb
  • [2023-10-12 15:28:48]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
// #define OPENIOBUF

namespace FastIO
{

class FastIOBase
{
 protected:
#ifdef OPENIOBUF
	static const int BUFSIZE=1<<16;
	char buf[BUFSIZE+1];
	int buf_p=0;
#endif
	FILE *target;
	FastIOBase(FILE *f): target(f){}
	~FastIOBase()=default;
 public:
#ifdef OPENIOBUF
	virtual void flush()=0;
#endif
};

class FastOutput final: public FastIOBase
{
 private:
	void __putc(char x)
	{
#ifdef OPENIOBUF
		if(buf[buf_p++]=x,buf_p==BUFSIZE) flush();
#else
		putc(x,target);
#endif
	}
	template<typename T>
	void __write(T x)
	{
		char stk[numeric_limits<T>::digits10+1],*top=stk;
		if(x<0) return __putc('-'),__write(-x);
		do *(top++)=x%10,x/=10; while(x);
		for(;top!=stk;__putc(*(--top)+'0'));
	}
 public:
	FastOutput(FILE *f=stdout): FastIOBase(f) {}
#ifdef OPENIOBUF
	~FastOutput() { flush(); }
	void flush() { fwrite(buf,1,buf_p,target),buf_p=0; }
#endif
	FastOutput &operator <<(char x)
	{ return __putc(x),*this; }
	FastOutput &operator <<(const char *s)
	{ for(;*s;__putc(*(s++)));return *this; }
	FastOutput &operator <<(const std::string &s)
	{ return (*this)<<s.c_str(); }
	template<typename T>
	std::enable_if_t<std::is_integral<T>::value,FastOutput&> operator <<(const T &x)
	{ return __write(x),*this; }
	template<typename ...T>
	void writesp(const T &...x)
	{ std::initializer_list<int>{(this->operator<<(x),__putc(' '),0)...}; }
	template<typename ...T>
	void writeln(const T &...x)
	{ std::initializer_list<int>{(this->operator<<(x),__putc('\n'),0)...}; }
	template<typename Iter>
	void writesp(Iter begin,Iter end)
	{ while(begin!=end) (*this)<<*(begin++)<<' '; }
	template<typename Iter>
	void writeln(Iter begin,Iter end)
	{ while(begin!=end) (*this)<<*(begin++)<<'\n'; }
}qout;

class FastInput final: public FastIOBase
{
 private:
	bool __eof;
 public:
	FastInput(FILE *f=stdin): FastIOBase(f),__eof(false)
#ifdef OPENIOBUF
	{ buf_p=BUFSIZE; }
	void flush() { buf[fread(buf,1,BUFSIZE,target)]=EOF,buf_p=0; }
	bool eof()const { return buf[buf_p]==EOF; }
#else
	{}
	bool eof()const { return feof(target); }
#endif
	char get()
	{
		if(__eof) return EOF;
#ifdef OPENIOBUF
		if(buf_p==BUFSIZE) flush();
		char ch=buf[buf_p++];
#else
		char ch=getc(target);
#endif
		return ~ch?ch:(__eof=true,EOF);
	}
	void unget(char c)
	{
		__eof=false;
#ifdef OPENIOBUF
		buf[--buf_p]=c;
#else
		ungetc(c,target);
#endif
	}
	explicit operator bool()const { return !__eof; }
	FastInput &operator >>(char &x)
	{ while(isspace(x=get()));return *this; }
	template<typename T>
	std::enable_if_t<std::is_integral<T>::value,FastInput&> operator >>(T &x)
	{
		char ch,sym=0;x=0;
		while(isspace(ch=get()));
		if(__eof) return *this;
		if(ch=='-') sym=1,ch=get();
		for(;isdigit(ch);x=(x<<1)+(x<<3)+(ch^48),ch=get());
		return unget(ch),sym?x=-x:x,*this;
	}
	FastInput &operator >>(char *s)
	{
		while(isspace(*s=get()));
		if(__eof) return *this;
		for(;!isspace(*s) && !__eof;*(++s)=get());
		return unget(*s),*s='\0',*this;
	}
	FastInput &operator >>(std::string &s)
	{
		char str_buf[(1<<8)+1]={0},*p=str_buf;
		char *const buf_end=str_buf+(1<<8);
		while(isspace(*p=get()));
		if(__eof) return *this;
		for(s.clear(),p++;;p=str_buf)
		{
			for(;p!=buf_end && !isspace(*p=get()) && !__eof;p++);
			if(p!=buf_end) break;
			s.append(str_buf);
		}
		unget(*p),*p='\0',s.append(str_buf);
		return *this;
	}
	template<typename ...T>
	void read(T &...x)
	{ std::initializer_list<int>{(this->operator>>(x),0)...}; }
	template<typename Iter>
	void read(Iter begin,Iter end)
	{ while(begin!=end) (*this)>>*(begin++); }
}qin;

} // namespace FastIO
using FastIO::qin,FastIO::qout;

using LL=long long;
using LD=long double;
using UI=unsigned int;
using ULL=unsigned long long;
constexpr int INF=1e9;

#ifndef DADALZY
#define FILEIO(file) freopen(file".in","r",stdin),freopen(file".out","w",stdout)
#define LOG(...) void()
#else
#define FILEIO(file)
#define LOG(...) fprintf(stderr,__VA_ARGS__)
#endif

int T,n,m;
char s[1000005];

struct TrieNode{ bool end=false;int ch[26]={0}; }t[1000005];
int cnt,rt;
void insert(const char *s)
{
	int u=rt;
	for(auto i=s;*i;i++)
	{
		int c=*i-'a';
		if(!t[u].ch[c])
			t[t[u].ch[c]=++cnt]=TrieNode{};
		u=t[u].ch[c];
	}
	t[u].end=true;
}
int dis[5005],vis[5005],f[1000005],dp[5005];
list<int> dfs(int u,int d=0)
{
	list<int> res;
	for(auto &v: t[u].ch)
		if(v) res.splice(res.end(),dfs(v,d+1));
	if(t[u].end) res.push_back(d);
	f[u]=-INF;
	for(auto &l: res)
		f[u]=max(f[u],dis[(l-d)%m]+(l-d)/m);
	return res;
}

int main()
{
	qin>>T;
	while(T--)
	{
		qin>>n>>m;
		set<int> lens;
		cnt=rt=1;
		for(int i=1;i<=n;i++)
		{
			qin>>s;
			lens.insert(strlen(s));
			insert(s);
		}
		fill(dis,dis+m,INF),dis[0]=0;
		for(auto &_L: lens)
		{
			int L=_L%m;
			fill(vis,vis+m,0);
			for(int i=0;i<m;i++)
			{
				if(vis[i]) continue;
				for(int u=i,v;vis[u]<2;u=v)
				{
					vis[u]++,v=(u+L)%m;
					int w=1+(u+L)/m;
					dis[v]=min(dis[v],dis[u]+w);
				}
			}
		}
		qin>>s,n=strlen(s);
		dfs(rt);
		fill(dp,dp+n+1,INF),dp[0]=0;
		for(int i=0;i<n;i++)
		{
			int u=rt;
			for(int j=i+1;j<=n;j++)
			{
				u=t[u].ch[s[j-1]-'a'];
				if(!u) break;
				dp[j]=min(dp[j],dp[i]+f[u]+1);
			}
		}
		qout<<(dp[n]==INF?-1:dp[n])<<'\n';
	}
	return 0;
}
/*
2
2 3
defgh
abc
abcde
1 1
a
b

*/

詳細信息

Test #1:

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

input:

2
2 3
defgh
abc
abcde
1 1
a
b

output:

3
-1

result:

ok 2 number(s): "3 -1"

Test #2:

score: -100
Wrong Answer
time: 78ms
memory: 7884kb

input:

1
1413 4867
yumnkkghwtqnhpmmsbfwypcwudihegsvtdaykueuqozagpgdnhbwzoqrqswyctzonwmjdjmmpyzbyihhpyznmqltcuckqmcybbdafoexqztxhzlfjowznisnxtgoiqjztogldyegajmegalqgawrzotuntocmsagvkzdnwhmaewuxiuhvintpzwyrkgapnmegpveyuuorrfvrfakjyetfaoqtvwghlslsvmahrkvzkwpaviufknrpuapicqdnn
yumnkkghwtqnhpmmsbfwypcwudihegsvt...

output:

20

result:

wrong answer 1st numbers differ - expected: '10', found: '20'