QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#520886#5416. Fabulous Fungus FrenzyqWA 1ms3736kbC++232.4kb2024-08-15 17:10:542024-08-15 17:10:55

Judging History

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

  • [2024-08-15 17:10:55]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3736kb
  • [2024-08-15 17:10:54]
  • 提交

answer

#include<bits/stdc++.h>
const int N=25;
int n,m,k,mp[305],c[N][N][N],h[N],w[N],a[N][N];
std::vector<std::tuple<int,int,int> > ans;
inline void get_mp(){
    int tot=0;
    for(char i='0';i<='9';i++) mp[(int)i]=++tot;
    for(char i='a';i<='z';i++) mp[(int)i]=++tot;
    for(char i='A';i<='Z';i++) mp[(int)i]=++tot;
}
inline int chk(int k){
    static int cnt[N]; memset(cnt,0,sizeof cnt);
    for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) cnt[a[i][j]]++;
    int tot=0;
    for(int i=1;i<=h[k];i++) for(int j=1;j<=w[k];j++){
        if(cnt[c[k][i][j]]) cnt[c[k][i][j]]--,tot++;
        else if(cnt[0]) cnt[0]--;
        else return -1;
    }
    return tot;
}
inline void work(int k){
    static bool vis[N][N]; memset(vis,false,sizeof vis);
    for(int i=1;i<=h[k];i++) for(int j=1;j<=w[k];j++){
        int x=0,y=0;
        for(int l=1;!x&&l<=n;l++) for(int o=1;o<=m;o++) if(!vis[l][o]&&a[l][o]==c[k][i][j]) x=l,y=o;
        for(int l=1;!x&&l<=n;l++) for(int o=1;o<=m;o++) if(!vis[l][o]&&!a[l][o]) x=l,y=o;
        for(;x<i;x++) std::swap(a[x][y],a[x+1][y]),ans.push_back(std::make_tuple(-3,x,y));
        for(;y<j;y++) std::swap(a[x][y],a[x][y+1]),ans.push_back(std::make_tuple(-1,x,y));
        for(;x>i;x--) std::swap(a[x][y],a[x-1][y]),ans.push_back(std::make_tuple(-4,x,y));
        for(;y>j;y--) std::swap(a[x][y],a[x][y-1]),ans.push_back(std::make_tuple(-2,x,y));
        vis[i][j]=true;
    }
    for(int i=1;i<=h[k];i++) for(int j=1;j<=w[k];j++) a[i][j]=0;
    if(k) ans.push_back(std::make_tuple(k,1,1));
}
int main(){
    std::ios::sync_with_stdio(false),std::cin.tie(nullptr),std::cout.tie(nullptr);
    get_mp();
    std::cin>>n>>m>>k,h[0]=n,w[0]=m;
    for(int i=1;i<=n;i++) for(int j=1;j<=m;j++){ char ch; std::cin>>ch; c[0][i][j]=mp[(int)ch]; }
    for(int i=1;i<=n;i++) for(int j=1;j<=m;j++){ char ch; std::cin>>ch; a[i][j]=mp[(int)ch]; }
    for(int i=1;i<=k;i++){
        std::cin>>h[i]>>w[i];
        for(int j=1;j<=h[i];j++) for(int l=1;l<=w[i];l++){ char ch; std::cin>>ch; c[i][j][l]=mp[(int)ch]; }
    }
    for(;chk(0)<0;){
        bool flag=false;
        for(int i=1;i<=k;i++) if(chk(i)>0) flag=true,work(i);
        if(!flag) return std::cout<<-1,0;
    }
    work(0);
    std::reverse(ans.begin(),ans.end());
    std::cout<<ans.size()<<"\n";
    for(auto [op,x,y]:ans) std::cout<<op<<" "<<x<<" "<<y<<"\n";
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3 3 1
OOO
GOG
BGB

OOO
GGG
BBB

3 1
B
G
B

output:

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

result:

ok puzzle solved

Test #2:

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

input:

2 2 1
OO
OO

PP
PP

1 2
OP

output:

-1

result:

ok puzzle solved

Test #3:

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

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:

508
-2 4 8
-2 4 7
-2 4 8
-2 4 6
-2 4 7
-2 4 8
-2 4 5
-2 4 6
-2 4 7
-2 4 8
-2 4 4
-2 4 5
-2 4 6
-2 4 7
-2 4 8
-2 4 3
-2 4 4
-2 4 5
-2 4 6
-2 4 7
-2 4 8
-2 4 2
-2 4 3
-2 4 4
-2 4 5
-2 4 6
-2 4 7
-2 4 8
-2 3 8
-2 3 7
-2 3 8
-2 3 6
-2 3 7
-2 3 8
-2 3 5
-2 3 6
-2 3 7
-2 3 8
-2 3 4
-2 3 5
-2 3 6
-2 3 7
-2...

result:

ok puzzle solved

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 3700kb

input:

2 2 1
OO
OO

OP
PP

1 2
PP

output:

10
-1 2 1
-1 2 0
-3 1 0
-3 0 0
-2 2 2
-2 1 2
-4 2 2
1 1 1
-4 2 2
-2 1 2

result:

wrong answer Integer parameter [name=y_1] equals to 0, violates the range [1, 2]