QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#470067#5416. Fabulous Fungus FrenzyBINYUTL 2ms3992kbC++142.5kb2024-07-10 10:00:292024-07-10 10:00:29

Judging History

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

  • [2024-07-10 10:00:29]
  • 评测
  • 测评结果:TL
  • 用时:2ms
  • 内存:3992kb
  • [2024-07-10 10:00:29]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N = 20;
int n,m,k,cnt,flag[N + 5][N + 5];
map <char,int> id;
struct update
{
	int x,y,op;
};
stack <update> s;
inline void add(int x,int y,int op)
{
	s.push({x,y,op});
}
struct Sqare
{
	int n,m,cnt[65];
	char c[N + 5][N + 5];
	void write()
	{
		for(int i = 1;i <= n;i++,puts(""))
			for(int j = 1;j <= m;j++)
				cout<<c[i][j];
	}
	void read()
	{
		for(int i = 1;i <= n;i++)
			scanf("\n%s",c[i] + 1);
		for(int i = 1;i <= n;i++)
			for(int j = 1;j <= m;j++)
				cnt[id[c[i][j]]]++;
	}
	void clear(int sx,int sy,int ex,int ey)
	{
		for(int i = sx;i <= ex;i++)
			for(int j = sy;j <= ey;j++)
			{
				if(c[i][j] != '#')
					cnt[id[c[i][j]]]--;
				c[i][j] = '#';
			}
	}
	void Swap(int sx,int sy,int ex,int ey)
	{
		swap(c[sx][sy],c[ex][ey]);
	} 
	void move(int sx,int sy,int ex,int ey)
	{
		while(sx < ex)
			Swap(sx,sy,sx + 1,sy),
			add(sx + 1,sy,-4),sx++;
		while(sy < ey)
			Swap(sx,sy,sx,sy + 1),
			add(sx,sy + 1,-2),sy++;
		while(sy > ey)
			Swap(sx,sy,sx,sy - 1),
			add(sx,sy - 1,-1),sy--;
		while(sx > ex)
			Swap(sx,sy,sx - 1,sy),
			add(sx - 1,sy,-3),sx--;
	}
}a[N + 5],c,d;
int get(Sqare &a,Sqare &b)
{
	int res = 0;
	for(int i = 0;i < 62;i++)
		res += max(a.cnt[i] - b.cnt[i],0);
	return res;
}
pair <int,int> find(char c)
{
	for(int i = 1;i <= d.n;i++)
		for(int j = 1;j <= d.m;j++)
			if(!flag[i][j]&&d.c[i][j] == c)
				return {i,j};
	return {-1,-1};
}
void solve(Sqare &a)
{
	for(int i = 1;i <= d.n;i++)
		for(int j = 1;j <= d.m;j++)
			flag[i][j] = 0;
	for(int i = 1;i <= a.n;i++)
	{
		for(int j = 1;j <= a.m;j++)
		{
			auto t = find(a.c[i][j]);
			if(t == make_pair(-1,-1))t = find('#');
			else cnt++;
			d.move(t.first,t.second,i,j);
			flag[i][j] = 1;
		}
	}
	d.clear(1,1,a.n,a.m);
}
int main()
{
	for(int i = 0;i < 26;i++)
		id['a' + i] = i;
	for(int i = 0;i < 26;i++)
		id['A' + i] = 26 + i;
	for(int i = 0;i < 9;i++)
		id['0' + i] = 52 + i;
	scanf("%d %d %d",&n,&m,&k);
	c.n = n;c.m = m;c.read();
	d.n = n;d.m = m;d.read(); 
	for(int i = 1;i <= k;i++)
		scanf("%d %d",&a[i].n,&a[i].m),a[i].read();
	while(1)
	{
		int flag = 0;
		for(int i = 1;i <= k;i++)
		{
			if(get(a[i],d) <= min(a[i].n * a[i].m - 1,cnt))
			{
				solve(a[i]);
				add(1,1,i);
				flag = 1;
				break;
			}
		}
		if(!flag)break;
	}
	if(get(c,d) > cnt)
		return puts("-1"),0;
	solve(c);
	cout<<s.size()<<"\n";
	while(!s.empty())
		cout<<s.top().op<<" "<<s.top().x<<" "<<s.top().y<<"\n",s.pop();
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3980kb

input:

3 3 1
OOO
GOG
BGB

OOO
GGG
BBB

3 1
B
G
B

output:

23
-3 1 3
-1 1 2
-1 1 1
1 1 1
-1 3 1
-4 3 2
-3 2 1
-1 3 1
-1 3 2
1 1 1
-1 3 1
-4 3 2
-1 2 1
-1 2 2
-3 1 1
-3 2 1
-1 3 1
-1 3 2
1 1 1
-1 3 1
-1 2 1
-3 1 1
-3 2 1

result:

ok puzzle solved

Test #2:

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

input:

2 2 1
OO
OO

PP
PP

1 2
OP

output:

-1

result:

ok puzzle solved

Test #3:

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

input:

4 8 4
11122222
33344444
55556666
77777777

NIxSHUOx
DExDUIxx
DANxSHIx
YUANSHEN

2 3
NIy
DEx

3 8
zzzzzzzz
DANNSH9I
YUA9SHEN

1 1
x

2 5
SHO8y
DUUI8

output:

228
4 1 1
-1 2 5
-4 2 6
-1 2 4
-1 2 5
-4 2 6
-1 2 3
-1 2 4
-1 2 5
-4 2 6
-1 2 2
-1 2 3
-1 2 4
-1 2 5
-4 2 6
-1 2 1
-1 2 2
-1 2 3
-1 2 4
-1 2 5
-4 2 6
-3 1 3
-3 2 3
-3 3 3
-1 4 3
-1 4 4
-1 4 5
-1 4 6
-1 4 7
2 1 1
-3 3 2
-1 4 2
-1 4 3
-1 4 4
-1 4 5
-1 4 6
-1 4 7
2 1 1
-3 3 2
-1 4 2
-1 4 3
-3 2 6
-3 3 ...

result:

ok puzzle solved

Test #4:

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

input:

2 2 1
OO
OO

OP
PP

1 2
PP

output:

8
-3 1 1
-1 2 1
1 1 1
-3 1 1
1 1 1
-3 1 2
-2 2 2
-1 1 1

result:

ok puzzle solved

Test #5:

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

input:

2 2 1
OO
OO

OP
PO

2 1
P
P

output:

4
-3 1 2
-1 1 1
1 1 1
-1 1 1

result:

ok puzzle solved

Test #6:

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

input:

2 2 1
OO
OO

OP
PO

2 2
PP
PP

output:

-1

result:

ok puzzle solved

Test #7:

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

input:

2 2 1
OO
OO

OP
PP

1 2
OP

output:

7
1 1 1
-3 1 2
-2 2 2
1 1 1
-3 1 2
-2 2 2
1 1 1

result:

ok puzzle solved

Test #8:

score: 0
Accepted
time: 2ms
memory: 3840kb

input:

20 20 20
bofelagiqboebdqplbhq
qsrksfthhptcmikjohkt
qrnhpoatbekggnkdonet
aoalekbmpbisgflbhmol
djnhnlitcakltqgegqrt
fdctfarsmbnbeosdgilo
ttrsljgiratfmioajorh
gorljkihdnmnofnblfhm
bqjkaehetdjlgctmijpc
geslcskpoqjcgtbdspoa
riqthroqmmhqgprqhsba
fdiarrcomockfqdjjdkd
jsbnigfqgsfekbbnnkir
ildqctqtqrpcetaocp...

output:

9816
20 1 1
-3 1 1
-3 2 1
-3 3 1
-3 4 1
-3 5 1
-3 6 1
-3 7 1
-3 8 1
-3 9 1
-3 10 1
-3 11 1
-3 12 1
-3 13 1
-3 14 1
-3 15 1
-3 16 1
-3 17 1
-3 18 1
-1 19 1
-1 19 2
-1 19 3
-1 19 4
-1 19 5
-1 19 6
-1 19 7
-1 19 8
-1 19 9
-1 19 10
-1 19 11
-1 19 12
-1 19 13
-1 19 14
-1 19 15
-1 19 16
-1 19 17
-1 19 18
...

result:

ok puzzle solved

Test #9:

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

input:

20 20 2
HbevPluVL5ORtUFcV9gf
Mrq6zdTPMPnwlN7Fpzx6
Nfp71dVuxTZp9Qet0Ca9
ugbaF34DquDdbUnk5x7V
fDFszn4PmvMpJ5BDWueJ
2YvFxKJgst8XbftPfy9T
F7Q4huk87Lrp1M7i08is
Q41E5AqLkkP3Q5qONXC2
MuM7iIzev3ZpxItvriQK
6OBdEC0sso5vdNQlrCSR
BJQtKjN6RmppsMGIYL81
yyKsWJSoKorGGblNle0r
RkKEQACh8f0bS5nPTtJH
fQgoc39vdsPAUmxlYYL...

output:

-1

result:

ok puzzle solved

Test #10:

score: -100
Time Limit Exceeded

input:

20 20 2
pqo3Mcpvo74RFSsJszsa
znrYm92Qr8fbqhbCTOgq
4KiMYr0kLAxPGNG15x7L
QHKmq6xaJ4PU4msuRAiv
UBfS6VUO87hRnMAjGXKX
zCgknw3FfhdifmVcT6FF
GH6ohIAzZuprlC3vMDVh
mHIJ9KlQvWxt6EgGbJkA
3SwJNhRSdEeF9BNtc9k2
mZmEuriH7Rc4ccMjqI0Y
cFfI8TC1iM4PkKziLOiN
15CUjuwudnrums3c3dsl
ekL52LiFEpzmU4vaGtuX
CfrnQtWb5zAN9oQS2fj...

output:


result: