QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#560348#8680. Turning RedPhantomThreshold#AC ✓270ms68572kbC++202.0kb2024-09-12 15:15:552024-09-12 15:15:56

Judging History

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

  • [2024-09-12 15:15:56]
  • 评测
  • 测评结果:AC
  • 用时:270ms
  • 内存:68572kb
  • [2024-09-12 15:15:55]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	const int inf=0x3f3f3f3f;
	int l,b;
	cin>>l>>b;
	string s;
	vector<int> a(l+5);
	cin>>s;
	s=' '+s;
	for(int i=1;i<=l;i++)
	{
		if(s[i]=='R')a[i]=0;
		else if(s[i]=='G')a[i]=1;
		else a[i]=2;
	}
	//LLLLLLLLLBBBBBBBBBB
	const int N=l+b;
	vector<vector<int>> G(N+5);
	for(int i=1;i<=b;i++)
	{
		int k;
		cin>>k;
		for(int j=1;j<=k;j++)
		{
			int x;
			cin>>x;
			G[i+l].push_back(x);
			G[x].push_back(i+l);
		}
	}
//	cerr<<"?"<<endl;
	vector<int> vis(N+5);
	vector<int> subs;
	function<void(int)> dfs0=[&](int u)
	{
		vis[u]=1;
		subs.push_back(u);
		for(auto v:G[u])
		{
			if(not vis[v])
			{
				dfs0(v);
			}
		}
	};
	vector<int> col(N+5);
	function<int(int,int)> solve=[&](int r,int ty)
	{
//		cerr<<"solve "<<r<<' '<<ty<<endl;
		int ret=0;
		queue<int> q;
		q.push(r);
		vis[r]=1;
		col[r]=ty;
		while(not q.empty())
		{
			int u=q.front();q.pop();
//			cerr<<"test "<<u<<endl;
			ret+=col[u];
			for(auto v:G[u])
			{
				if(not vis[v])
				{
					int need=(6-a[v]-col[u])%3;
					if(G[v].size()==1u and need!=0)return inf;
					for(auto z:G[v])
					{
						if(z!=u)
						{
							if(col[z]!=-1 and col[z]!=need)return inf;
							col[z]=need;
							if(not vis[z])
							{
								q.push(z);
								vis[z]=1;
							}
						}
					}
				}
			}
		}
		return ret;
	};
	int ans=0;
	for(int i=1;i<=b;i++)
	{
		if(not vis[i+l])
		{
			subs.clear();
			dfs0(i+l);
			int minn=inf;
			for(int kk=0;kk<=2;kk++)
			{
				for(auto u:subs)col[u]=-1,vis[u]=0;
				int ret=solve(i+l,kk);
				if(ret<minn)minn=ret;
			}
			for(auto u:subs)col[u]=-1,vis[u]=1;
			if(minn==inf)
			{
				cout<<"impossible"<<endl;
				return 0;
			}
//			cerr<<"ans "<<i<<' '<<minn<<endl;
			ans+=minn;
		}
	}
	for(int i=1;i<=l;i++)
	{
		if(a[i] and G[i].size()==0)
		{
			cout<<"impossible"<<endl;
			return 0;
		}
	}
	cout<<ans<<endl;
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 151ms
memory: 38820kb

input:

200000 171004
RGRGBBBGGBRRRBBRRBRBBGRRRGGGGRRRRGBBBRGGGBGGRGGRGRRBRBRRGGBGGGGBRBRBRRBRBRGRRGRBRRBGRRRRBRBBBRGBBBGRRBRGRRGGRGGBGRBGRBRGBBRRBBBGBGRGBBRBGGGGBBBBRBRRRGBGRRBBGGGRRBRBBRGRBGRBRGGBRBBBBRGGRRRBGRBGRBRRRGRGRRBRGRRGRRGBBBBRGGBBRRBGGBGBGRBRGBGGRRGRBRRGGRGRBBBRRBBRRGGRRRRGBRGGGGGGRGBRGRBBBGRBBG...

output:

impossible

result:

ok single line: 'impossible'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3588kb

input:

10 0
RRRRRRRRRR

output:

0

result:

ok single line: '0'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3744kb

input:

10 0
GGGGGGGGGG

output:

impossible

result:

ok single line: 'impossible'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3592kb

input:

10 0
BBBBBBBBBB

output:

impossible

result:

ok single line: 'impossible'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3812kb

input:

10 0
RGBRGBRGBR

output:

impossible

result:

ok single line: 'impossible'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3460kb

input:

10 0
GBBRRRBRGB

output:

impossible

result:

ok single line: 'impossible'

Test #7:

score: 0
Accepted
time: 0ms
memory: 3764kb

input:

10 2
BBRRBRBRRR
7 7 8 5 3 10 9 4
5 6 10 1 3 2

output:

impossible

result:

ok single line: 'impossible'

Test #8:

score: 0
Accepted
time: 0ms
memory: 3732kb

input:

10 9
RRRRRBGRRG
1 10
5 9 3 8 2 5
2 8 7
1 7
1 10
2 6 1
1 3
1 6
4 1 9 4 2

output:

5

result:

ok single line: '5'

Test #9:

score: 0
Accepted
time: 88ms
memory: 22188kb

input:

200000 10000
RBBBBGRRGGRBRGRGBBRBGGRGRGRBBRRRGRGRGRBGRBBBBGBGBBGGBBGGGGBRGBBBBBBRRGBBGGGRBBBGBRGGGRRGGGGBGBGBGRBBGGRRRGGGRGGRBRRBGRGRBBGBGGRGBBRBBBGGRGBBGBBBBBGRGBGGRGBGGBGRRBGBBGRBGBGGRBBBGBBBGGGBBBRBBGRRRBGBBRBRBBGRGGGBBRGRRRGRRRRGRRBGBRRRRGBBRBBGRRRRBRBRRRGBGRGGBGRBRBGBBRRGBBRBBBGBGGGBBRGRBRRGBBR...

output:

impossible

result:

ok single line: 'impossible'

Test #10:

score: 0
Accepted
time: 109ms
memory: 29516kb

input:

200000 49974
GRBRRGBRRRRRGBRBGRRBGGGRRRRBGGBBBGRRGBBRBGBRBRRBRBBRGRBGGBBGBBRRRBGGBRBRRGBRRRBRRGRGRGRBGRBGBBBGGGRGRBGRGGRBBRBRGGBRBBRRGGGRBGBGBGRBRBRGGBBBRBBRGRRBBGBGRBBRBBBRGGGGRRBGBBRGBGBGGBRBGGRGGGBRRRBBBGRRRRGBBBGBBGRRRBGRGGGRGBRGBGRBBRBRRBGGRGBBRGBBBRGRBBBRRGGRRRGGRRRGRRBGGGBGRRGBRRRRRGRGBGGRRRR...

output:

impossible

result:

ok single line: 'impossible'

Test #11:

score: 0
Accepted
time: 104ms
memory: 36456kb

input:

200000 97963
GRBBRBGGGBGBBGRBBBRGRGBBBGBRBGBGGGBRBBGRGRRBRRGBRRBBGRRGBRRGBBRBGRRRGRGRRRBGBBRGGBRRBBBGRBBGBBRRRGRRGRGRRRBBRGBRRRRRGGGGGBGRRBGRGGBBBBRBBRBBBBBBRRRGBGGRGRGRBBRRBGBRRBBRGBGRBRBRGBRRGBRBGGRGGGGBGGGRBBRGRGGBBGRRGRBGGRBGRBBBRRGGRGGBRRBBRGGRBRBBGRRRGGGBRBRGBRBRBBGGBRGRBBRGGBBBGGBGRRRRRRGGGBR...

output:

impossible

result:

ok single line: 'impossible'

Test #12:

score: 0
Accepted
time: 82ms
memory: 41712kb

input:

200000 400000
GRGBBBRRGGRGBBRBBGBRRRBBRBRGRGRRBBRBRGRBRGGRRGGBRGRRBRBRRBRRGGBBGRBBGRRRBRBGBBRBGBRBBBBBBGBRGRBBGRGBGBBGRGBGBBBBGRGRRRGGGBGGGGRBRBRBRRBGGBGRRGBGGGRRBBBGRBRBGGBBRBBGRGGBGRGBGRRGGBRGGRGRGGBGBRBBBRGGBRRRRBGRBGRRGBRBRGRRBBGGGRRGRGGBRBBBBRGBBGRGGBGGRBGGRBRBBRBBBGRGGGGGBGGRRBBGRGGGRGBRBGGGGR...

output:

200051

result:

ok single line: '200051'

Test #13:

score: 0
Accepted
time: 0ms
memory: 3532kb

input:

10 10
GRBBGBBRRG
2 10 1
2 9 10
2 5 6
2 4 2
2 8 4
2 7 5
2 2 3
2 3 7
2 6 9
1 1

output:

12

result:

ok single line: '12'

Test #14:

score: 0
Accepted
time: 255ms
memory: 58296kb

input:

200000 199999
BRGBBBRBBGGRRGBGRBGBRRGGGBRGGBBGRRRGGBRBBGRBGGBGRGBGBRBGGRBRRGBRBGRBGGGRRGGBGGBBBBBRRGRRRRBGRBGGGBBGGGRGRRGRGRGBGRBBBGGRGRRRRGRGGGGGGGBBBBGRGRGGRBRGRGBBBRRBGRGRGGBGRBRRRRGBBRBBGBGRRRGBRRRBRRGBBBRRBGRBRRBGBGBGGRBBRRGGRRRBBRRGBRGRRGBRRGRRGGRGRRRRGBGRBBRRGRRBRRBBRGBRRBRGGRRBBBRGRGBBGGBRRR...

output:

199855

result:

ok single line: '199855'

Test #15:

score: 0
Accepted
time: 248ms
memory: 67752kb

input:

200000 199999
BRGGGBBBGGRBGGBRGGGBBBBBBBRRGBBBGBBRBGGBGGGBGBBGBBGRBRRGGRRBBGGBRRGBRGBBBGGGRBRRRBRBBBRGBRRBRRGBGBRGBGRGGGGBBRGGRRGBGGBBGBBRBGRRBRBRGGBBRRRGBBGRRBRRBRGGGBBGGRGRGGGBGGGRBRGGRBGGGGBBRBRRBRRGRBBRBGGBBBGRGRBGRRBGGRRRBRBRGGGBGGRBGBBBRGGRRRRBGRGRBGGRBGBBBGBBRRRGGRGBRRRBRGRRRGGGRRRBGRRGGRBRBR...

output:

impossible

result:

ok single line: 'impossible'

Test #16:

score: 0
Accepted
time: 231ms
memory: 65844kb

input:

200000 200000
RRBBBGRBBGRBGBBRRGGBRBBGGBRGRBGBGBBBRBBGGBGRGBBRBRGBGRRGBBBGBGRRRBGRGBBGBBRGBRGBGGBBGBRRRRRRBBRBGGBGGRBBRBBBRBBBRRRGGGGRGBBBRBBGRRBRBBRBBGGRRRGGBRGRRRGRBBRGGGGRBGGBBGGRRRBGBBGBBRGRBRGRBGBRBGBGGGBBGGRBRRGBBRRGRBGBRBRRBBGGBGGRBGRGGGRRGGBGRRBBRBRRGGBRGGRGRBBRRRRBBRBGRBBBRGGGRGRGBGRGRGBRGR...

output:

199859

result:

ok single line: '199859'

Test #17:

score: 0
Accepted
time: 268ms
memory: 52268kb

input:

200000 200000
RRRRBRRGGGGGGRBBBGRRGBBRRBGRRBRRGRRBGGRGBRBGBRGGBRRBBGGGRGRGRGBGRBRGRBBGBRRBRRBGGGRBGBRGBBGGRGBRGGRBGBGGRBGGRGGGGRGGGGRRRGBBGRBRRGBRRBGRBBBRRBGRGRGBBGRRBBRBBGGRBRBGRBGBGBRRGGGBBGGBGRRGRRBGGBBRGGBRGRGBGGGRBBBRGRRGRBGRRGGGRBRGGGGRRGGRGGRBGRGBRBGBBRGBGRGBBBGRRGRGGBBBRBGGRGBRGRBGRRRRBBGRGR...

output:

200292

result:

ok single line: '200292'

Test #18:

score: 0
Accepted
time: 0ms
memory: 3456kb

input:

10 9
BRBRBRGRRB
1 8
1 4
1 6
1 9
1 3
1 7
10 2 5 6 4 1 7 8 9 3 10
1 5
1 2

output:

12

result:

ok single line: '12'

Test #19:

score: 0
Accepted
time: 135ms
memory: 32228kb

input:

200000 199999
BRRGBGBBGRGBGRGRGRBRRGBGBRRGBBBRGBBBRBBRRRGRRRBBRBGGRRGBBBGRRRBBBRBBRRBRRBBBGGGBRRRBRBGRBGRBRGGBGRBRGGGBGRGRGBBBRGGRRRBBBGBGGRRGRBRBBBBRRGBGRBRBGRGBRGRGRBRBGRGBRBRGBBBRGGGGGBRRGBRBBBGBRGRRGBRBGBBRBGGRGRGBBGRGRBGRRGBRGRBGRBBRBGRBRBRRBBBGGGBBGGBGBGGBGBBRRGGGGRBRBGBGBBGRBGRGRBBBBRGRGBBGRG...

output:

200007

result:

ok single line: '200007'

Test #20:

score: 0
Accepted
time: 110ms
memory: 32320kb

input:

200000 199999
RBRGBRGRRGRBGGBGRRRGBGRBRRBGGBRBGBRGRGRRRBBRRRRRRGGBBGRGRGBGRGRBBBRBGRBBGGGRBBRRGBRGGRRGBRGGRBRRRGRGRRRBGRRRBRGBRBBBRGGRGRRGGRBGGRBRRGBGGGBGGBRGBGGBBRRBRRRRGBBBRGBRBGBBGRBRGGBBBBRGRGGBRBRRGGBRGBGBRBGBGBGGBRRGRGGRRGRBRRRBGGBGRBGRGRGGGBRGRGRRBBGRBRGRRGGBGRRBGGGRRRBGRBGRGRBBRGBBGBGRRGRBGG...

output:

impossible

result:

ok single line: 'impossible'

Test #21:

score: 0
Accepted
time: 0ms
memory: 3536kb

input:

10 10
BRBBRGBGRG
2 10 6
2 8 9
2 7 1
2 2 4
2 6 7
2 5 10
2 9 3
2 2 5
2 1 8
2 3 4

output:

impossible

result:

ok single line: 'impossible'

Test #22:

score: 0
Accepted
time: 270ms
memory: 68556kb

input:

200000 200000
RRGBBGRGBGGRBRBRRRBGGBBGGBGRBGBGRRBRRBBGBBGBBGGGGBBGBRRRGBRRBRBGGGRBRRGBGRRGBGGBBGRBRRBGBRGBBBBGGRRRGBGGBBBBRRBBGBBBBGGGRGRGBBBRRGBGRBGRBRGRRRBBRGGRRBBGRRGGGBBBBBRGGRBGBGGGGGGGRGGRRBGGBBBBBRGRRBBBRRGGGBGRGRGGRBGRRBGBBRBGRGBBGRGBBGRGGRGRRRBGGGRRBRGRGGRRGRGBBBGBGBBBBBRGBBBRBGGGGGBRGBBBRG...

output:

impossible

result:

ok single line: 'impossible'

Test #23:

score: 0
Accepted
time: 259ms
memory: 68572kb

input:

200000 200000
RRRGGRBRRBBRBBGBGGGBBBGGBGRRGRGBBGBGBRBRGGGBGRGRGGBGGGRBRRGBGGBRGRBBBBBRGRRRRBRRRBRRRGRGRBBGRGGBGBRRBGRRGRGRBGGRBRBBRRBBBBBBBBGBBBRGBGRRBRGBBBBRGBBBRGBGGRBRRBBRGRGGRRGGRRGGBRGBBGRGGGGRBRGRGGBGRRGGBBBGRGBBBBGBGRBGBBBBBRRRGRGBBBBBBRRBGRRBRRBGGBRRGBBRRBRBRBRBBBGGRBBGRRGRBGRRBGBGRBRBRRRGGR...

output:

impossible

result:

ok single line: 'impossible'

Test #24:

score: 0
Accepted
time: 33ms
memory: 10196kb

input:

60000 50000
BRGGGRGRRGGGGBBBGGBGRGGRGBGBGRGBBBBRGGRBRBGRBRGBGRBBRRRBRRGGRGBBBRGRBRBRBRBBBBGBGRGGBRRGGBGBGBGBGBGGRBRRGRRGBGGGBBRBBGGGRRGRBBBBBGGBBGRBBBGBGGRRRRRGRBGRRRRBGRBRRBBGRRBGRBGRGGGGBBGGRGRBGRRRRRGGRRBRRRBRBRBRBBRGBRGBRRBRGBGBRRGRBRBRRRBBGGRGGRRBGRRBBGGBRRBBBBRRRGBRRBRBRGGBGBGGGGBBGGGRBGRGRGBB...

output:

30280

result:

ok single line: '30280'

Test #25:

score: 0
Accepted
time: 30ms
memory: 10268kb

input:

54937 54937
GGGRGBGRRRRRBGBBRGRBBGBGBRRRBBGGBGGRBBGRBRGBGRBBGGGRBBGGGBRGRGRRRGRRGGGBGGRBRBGBGRGRGRGGGBGRRBRBGBBBGRRRGBRBGGGGGRBGGGRRGRRBBGGGGGBRGBBGGRBGRGRBRGBRRGGRGGBRRBGRBRRBBGGGRBGBRRRRBGBGRRBRGBRRRBRRGGRRGBBGBBGBGRGGRBRGRGRBGBGGRRRRGGGRGGRGRRGBGRBBGBRBGBRGGBBGBGGBRBBGBBBGGRRGGBBBBRRBGRGGRRBGRRRR...

output:

54911

result:

ok single line: '54911'

Test #26:

score: 0
Accepted
time: 69ms
memory: 41864kb

input:

200000 400000
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...

output:

0

result:

ok single line: '0'

Test #27:

score: 0
Accepted
time: 65ms
memory: 41704kb

input:

200000 400000
GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG...

output:

400000

result:

ok single line: '400000'

Test #28:

score: 0
Accepted
time: 93ms
memory: 41664kb

input:

200000 400000
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...

output:

200000

result:

ok single line: '200000'

Test #29:

score: 0
Accepted
time: 49ms
memory: 19164kb

input:

200000 10
BBBRBBBRRGRBRRRRBGBRBRRRGBBBRGRGGGGRGBGGGGRGRBBGGRGBBBRRRBBRBGGRRGBBRRRRGRRBGGRBBGBBBGBGGRGRGGGRRGGRRBRBGGRBBRBRRGRRRGGRGBBRRBGRGRBRRRGRBRRGRGBBRGGBBBRBBRRBGBGRBGGBBGGBBGRBGGBBGBRRRGBRBGRGBBBRBRBRBBRRRGBGBRRGRRRBGBGGGRGBGGGGRBGBBBRRGRGBRGRGRRGRGRBGBGGBGGGBRGRBBBBRBRBRBBGGBRRRGBGBGRRRGBBRRG...

output:

impossible

result:

ok single line: 'impossible'

Extra Test:

score: 0
Extra Test Passed