QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#470520 | #5416. Fabulous Fungus Frenzy | Mathew_Miao | WA | 0ms | 3956kb | C++23 | 4.4kb | 2024-07-10 14:44:48 | 2024-07-10 14:44:53 |
Judging History
answer
#include<map>
#include<set>
#include<cmath>
#include<ctime>
#include<queue>
#include<stack>
#include<cstdio>
#include<vector>
#include<string>
#include<bitset>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
const int MAXN=24;
const int MAXC=128;
const int INF=0x3f3f3f3f;
const long long LINF=0x3f3f3f3f3f3f3f3f;
int n,m,k;
#define node tuple<int,int,int>
basic_string <node> ans;
int px[MAXN],py[MAXN];
char a[MAXN][MAXN];
char c[MAXN][MAXN][MAXN];
int all=0;
int tot[MAXN][MAXC];
int cnt[MAXC];
inline int need(int x){
int res=0;
for(int i=0;i<MAXC;i++)
{
if(tot[x][i]>cnt[i]){
res+=tot[x][i]-cnt[i];
}
}
return res;
}
inline int value(int x){
int res=0;
for(int i=0;i<MAXC;i++)
{
res+=min(tot[x][i],cnt[i]);
}
return res;
}
inline bool check(int x){
return value(x)&&need(x)<=all;
}
int dx[4]={-1,1,0,0},dy[4]={0,0,-1,1};
int id[4]={-4,-3,-2,-1};
inline void swap(int& x,int& y,int d){
ans.push_back(node(id[d],x,y));
swap(a[x][y],a[x+dx[d]][y+dy[d]]);
x+=dx[d];
y+=dy[d];
}
inline void stamp(int x){
for(int i=1;i<=px[x];i++)
{
for(int j=1;j<=py[x];j++)
{
a[i][j]='*';
}
}
ans.push_back(node(x,1,1));
}
#define idx(x,y) (((x)-1)*m+(y))
inline void move(char ch,int x,int y,int p){
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(a[i][j]^ch){
continue;
}
if(i<=px[p]&&j<=py[p]&&idx(i,j)<idx(x,y)){
continue;
}
if(i<=x){
while(i<x)
{
swap(i,j,1);
}
while(j<y)
{
swap(i,j,3);
}
while(j>y)
{
swap(i,j,2);
}
}
else{
while(j<y)
{
swap(i,j,3);
}
while(j>y)
{
swap(i,j,2);
}
while(i>x)
{
swap(i,j,0);
}
}
return ;
}
}
}
inline void work_fir(int x){
for(int i=1;i<=px[x];i++)
{
for(int j=1;j<=py[x];j++)
{
if(cnt[c[x][i][j]]){
move(c[x][i][j],i,j,x);
all++;
cnt[c[x][i][j]]--;
stamp(x);
return ;
}
}
}
}
inline void work(int x){
for(int i=1;i<=px[x];i++)
{
for(int j=1;j<=py[x];j++)
{
if(cnt[c[x][i][j]]){
move(c[x][i][j],i,j,x);
all++;
cnt[c[x][i][j]]--;
}
else{
move('*',i,j,x);
}
}
}
stamp(x);
}
signed main(){
scanf("%d%d%d",&n,&m,&k);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
scanf(" %c",&c[0][i][j]);
tot[0][c[0][i][j]]++;
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
scanf(" %c",&a[i][j]);
cnt[a[i][j]]++;
}
}
for(int t=1;t<=k;t++)
{
scanf("%d%d",&px[t],&py[t]);
for(int i=1;i<=px[t];i++)
{
for(int j=1;j<=py[t];j++)
{
scanf(" %c",&c[t][i][j]);
tot[t][c[t][i][j]]++;
}
}
}
int now=0;
for(int i=1;i<=k;i++)
{
if(check(i)){
now=i;
break;
}
}
while(now)
{
work_fir(now);
while(check(now))
{
work(now);
}
now=0;
for(int i=1;i<=k;i++)
{
if(check(i)){
now=i;
break;
}
}
}
if(need(0)<=all){
if(value(0)){
work_fir(0);
ans.pop_back();
}
printf("%d\n",ans.size());
for(auto [opt,x,y]:ans)
{
printf("%d %d %d\n",opt,x,y);
}
}
else{
puts("-1");
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3956kb
input:
3 3 1 OOO GOG BGB OOO GGG BBB 3 1 B G B
output:
17 -4 3 1 -4 2 1 1 1 1 -2 3 2 -4 3 1 -4 2 1 -2 2 2 -2 3 3 -2 3 2 1 1 1 -2 2 3 -2 2 2 -3 2 2 -2 3 2 1 1 1 -3 2 2 -2 3 2
result:
wrong answer puzzle remain unsolved