QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#99017#5504. Flower GardenExplodingKonjacRE 2645ms100540kbC++176.8kb2023-04-21 08:47:482023-04-21 08:47:51

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-21 08:47:51]
  • 评测
  • 测评结果:RE
  • 用时:2645ms
  • 内存:100540kb
  • [2023-04-21 08:47:48]
  • 提交

answer

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

namespace FastIO
{

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

class FastOutput: public FastIOBase
{
#ifdef OPENIOBUF
 public:
	inline void flush()
		{ fwrite(buf,1,buf_p,target),buf_p=0; }
#endif
 protected:
	inline void __putc(char x)
	{
#ifdef OPENIOBUF
		if(buf[buf_p++]=x,buf_p==BUFSIZE)flush();
#else
		putc(x,target);
#endif
	}
	template<typename T>
	inline void __write(T x)
	{
		static char stk[64],*top;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
	inline void setTarget(FILE *f) { this->flush(),target=f; }
	~FastOutput(){ flush(); }
#else
	inline void setTarget(FILE *f) { target=f; }
#endif
	template<typename ...T>
	inline void writesp(const T &...x)
		{ initializer_list<int>{(this->operator<<(x),__putc(' '),0)...}; }
	template<typename ...T>
	inline void writeln(const T &...x)
		{ initializer_list<int>{(this->operator<<(x),__putc('\n'),0)...}; }
	inline FastOutput &operator <<(char x)
		{ return __putc(x),*this; }
	inline FastOutput &operator <<(const char *s)
		{ for(;*s;__putc(*(s++)));return *this; }
	inline FastOutput &operator <<(const string &s)
		{ return (*this)<<s.c_str(); }
	template<typename T,typename=typename enable_if<is_integral<T>::value>::type>
	inline FastOutput &operator <<(const T &x)
		{ return __write(x),*this; }
}qout;

class FastInput: public FastIOBase
{
#ifdef OPENIOBUF
 public:
	inline void flush()
		{ buf[fread(buf,1,BUFSIZE,target)]='\0',buf_p=0; }
#endif
 protected:
	inline char __getc()
	{
#ifdef OPENIOBUF
		if(buf_p==BUFSIZE) flush();
		return buf[buf_p++];
#else
		return getc(target);
#endif
	}
 public:
#ifdef OPENIOBUF
	FastInput(FILE *f=stdin): FastIOBase(f){ buf_p=BUFSIZE; }
	inline void setTarget(FILE *f) { this->flush(),target=f; }
#else
	FastInput(FILE *f=stdin): FastIOBase(f){}
	inline void setTarget(FILE *f) { target=f; }
#endif
	inline char getchar() { return __getc(); }
	template<typename ...T>
	inline void read(T &...x)
		{ initializer_list<int>{(this->operator>>(x),0)...}; }
	inline FastInput &operator >>(char &x)
		{ while(isspace(x=__getc()));return *this; }
	template<typename T,typename=typename enable_if<is_integral<T>::value>::type>
	inline FastInput &operator >>(T &x)
	{
		static char ch,sym;x=sym=0;
		while(isspace(ch=__getc()));
		if(ch=='-') sym=1,ch=__getc();
		for(;isdigit(ch);x=(x<<1)+(x<<3)+(ch^48),ch=__getc());
		return sym?x=-x:x,*this;
	}
	inline FastInput &operator >>(char *s)
	{
		while(isspace(*s=__getc()));
		for(;!isspace(*s) && *s && ~*s;*(++s)=__getc());
		return *s='\0',*this;
	}
	inline FastInput &operator >>(string &s)
	{
		char str_buf[(1<<8)+1],*p=str_buf;
		char *const buf_end=str_buf+(1<<8);
		while(isspace(*p=__getc()));
		for(s.clear(),p++;;p=str_buf)
		{
			for(;p!=buf_end && !isspace(*p=__getc()) && *p && ~*p;p++);
			*p='\0',s.append(str_buf);
			if(p!=buf_end) break;
		}
		return *this;
	}
}qin;

} // namespace FastIO
using namespace FastIO;

using LL=long long;
using LD=long double;
using UI=unsigned int;
using ULL=unsigned long long;

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

int T,n,q,lim,nn,w[400005];
char ans[400005];
vector<int> g1[400005],g2[400005],gr[400005];

struct TreeNode{ int id1,id2; }t[400005];
#define LC (i<<1)
#define RC (i<<1|1)
void build(int l,int r,int i=1)
{
	if(l==r) return t[i].id1=t[i].id2=l,void();
	t[i].id1=++nn,t[i].id2=++nn;
	int mid=(l+r)>>1;
	build(l,mid,LC),build(mid+1,r,RC);
	g1[t[i].id1].push_back(t[LC].id1);
	g1[t[LC].id2].push_back(t[i].id2);
	g1[t[i].id1].push_back(t[RC].id1);
	g1[t[RC].id2].push_back(t[i].id2);
}
void addEdgeFrom(int lq,int rq,int x,int i=1,int l=1,int r=n)
{
	if(l>=lq && r<=rq) return g1[t[i].id2].push_back(x);
	int mid=(l+r)>>1;
	if(mid>=lq) addEdgeFrom(lq,rq,x,LC,l,mid);
	if(mid<rq) addEdgeFrom(lq,rq,x,RC,mid+1,r);
}
void addEdgeTo(int lq,int rq,int x,int i=1,int l=1,int r=n)
{
	if(l>=lq && r<=rq) return g1[x].push_back(t[i].id1);
	int mid=(l+r)>>1;
	if(mid>=lq) addEdgeTo(lq,rq,x,LC,l,mid);
	if(mid<rq) addEdgeTo(lq,rq,x,RC,mid+1,r);
}

int tot,ccnt,top,dfn[400005],low[400005],col[400005],stk[400005];
bool vis[400005];
void tarjan(int u)
{
	dfn[u]=low[u]=++tot;
	stk[++top]=u,vis[u]=true;
	for(auto &v: g1[u])
		if(!dfn[v]) tarjan(v),low[u]=min(low[u],low[v]);
		else if(vis[v]) low[u]=min(low[u],dfn[v]);
	if(dfn[u]==low[u])
	{
		int x,y=++ccnt;
		do x=stk[top--],vis[x]=false,col[x]=y;
		while(x!=u);
	}
}
bool solve1(int S)
{
	queue<int> q;
	int sum=0;
	fill(vis+1,vis+nn+1,false);
	fill(ans+1,ans+nn+1,'R');
	q.push(S),vis[S]=true;
	while(!q.empty())
	{
		int u=q.front();
		for(auto &v: g2[u])
			if(!vis[v]) q.push(v),vis[v]=true;
		sum+=w[u],ans[u]='F',q.pop();
	}
	if(sum>=lim && sum<=2*lim) return true;
	q=queue<int>(),sum=0;
	fill(ans+1,ans+nn+1,'F');
	q.push(S),vis[S]=true;
	while(!q.empty())
	{
		int u=q.front();
		for(auto &v: gr[u])
			if(!vis[v]) q.push(v),vis[v]=true;
		sum+=w[u],ans[u]='R',q.pop();
	}
	return sum>=lim && sum<=2*lim;
}
bool solve2()
{
	static int deg[400005];
	queue<int> q;
	int sum=0;
	for(int u=1;u<=nn;u++) deg[u]=gr[u].size();
	for(int u=1;u<=nn;u++) if(!deg[u]) q.push(u);
	fill(ans+1,ans+nn+1,'F');
	while(!q.empty())
	{
		int u=q.front();
		sum+=w[u],ans[u]='R',q.pop();
		if(sum>=lim && sum<=2*lim) return true;
		for(auto &v: g2[u]) if(!--deg[v]) q.push(v);
	}
	return false; // shouldn't appear
}
int main()
{
	qin>>T;
	while(T--)
	{
		qin>>lim>>q,n=3*lim,nn=n;
		build(1,n);
		for(int i=1;i<=q;i++)
		{
			int a,b,c,d;
			qin>>a>>b>>c>>d,nn++;
			addEdgeFrom(a,b,nn);
			addEdgeTo(c,d,nn);
		}
		for(int i=1;i<=nn;i++) if(!dfn[i]) tarjan(i);
		for(int u=1;u<=nn;u++) for(auto &v: g1[u])
		{
			if(col[u]==col[v]) continue;
			g2[col[u]].push_back(col[v]);
			gr[col[v]].push_back(col[u]);
		}
		for(int i=1;i<=n;i++) w[col[i]]++;
		bool fl=false;
		int oldnn=nn;
		nn=ccnt;
		for(int i=1;i<=nn;i++)
		{
			if(w[i]<lim) continue;
			bool res=solve1(i);
			if(res) {fl=true;break;}
		}
		if(!fl && solve2()) fl=true;
		if(!fl) qout<<"NIE\n";
		else
		{
			qout<<"TAK\n";
			for(int i=1;i<=n;i++) qout<<ans[col[i]];
			qout<<'\n';
		}
		tot=top=0;
		for(int i=1;i<=oldnn;i++)
		{
			g1[i].clear(),g2[i].clear(),gr[i].clear();
			w[i]=dfn[i]=low[i]=col[i]=0;
			vis[i]=false;
		}
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 5ms
memory: 33624kb

input:

2
1 3
1 1 2 2
1 2 3 3
1 1 3 3
1 3
1 1 2 2
2 2 3 3
3 3 1 1

output:

TAK
RRF
NIE

result:

ok good!

Test #2:

score: 0
Accepted
time: 2645ms
memory: 100540kb

input:

10
33333 100000
28701 40192 93418 95143
95902 97908 78378 78461
36823 44196 22268 23996
23977 24786 33315 48829
83965 90411 4923 8445
20235 21177 32543 47454
29598 35414 72477 73049
2014 12632 42163 46466
64305 65518 98825 99552
32331 41625 92772 96224
26500 54122 76990 77126
18249 20335 31165 36080...

output:

NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE

result:

ok good!

Test #3:

score: -100
Dangerous Syscalls

input:

10
33333 100000
15207 33614 66276 66276
97173 97173 67589 73960
19673 36626 65207 65207
89825 98169 27079 27079
56067 56966 7560 7560
18170 35477 18752 18752
32621 36748 34460 34460
61595 61700 14117 14117
32395 36710 9064 9064
13172 13172 1728 4640
40462 41878 47171 47171
76965 82414 5767 5767
9225...

output:

TAK
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF...

result: