QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#757950 | #5416. Fabulous Fungus Frenzy | Mitsubachi | WA | 1ms | 3592kb | C++14 | 5.2kb | 2024-11-17 14:50:20 | 2024-11-17 14:50:21 |
Judging History
answer
// g++-13 1.cpp -std=c++17 -O2 -I .
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/tag_and_trait.hpp>
using namespace __gnu_pbds;
// #include <atcoder/segtree>
// using namespace atcoder;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vst = vector<string>;
using vvst = vector<vst>;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define pq_big(T) priority_queue<T,vector<T>,less<T>>
#define pq_small(T) priority_queue<T,vector<T>,greater<T>>
#define all(a) a.begin(),a.end()
#define rep(i,start,end) for(ll i=start;i<(ll)(end);i++)
#define per(i,start,end) for(ll i=start;i>=(ll)(end);i--)
#define uniq(a) sort(all(a));a.erase(unique(all(a)),a.end())
random_device seed;
mt19937_64 randint(seed());
ll grr(ll mi, ll ma) { // [mi, ma)
return mi + randint() % (ma - mi);
}
int kind=63;
struct stamp{
int n;
int m;
vst g;
vi cnt;
int ind;
};
bool comp(stamp &l,stamp &r){
if(l.n*l.m!=r.n*r.m){
return (l.n*l.m)<(r.n*r.m);
}
return l.ind<r.ind;
}
// # a b c ... z A B C ... Z 0 1 2 ... 9
int code(char c){
if(c=='#')return 0;
if('a'<=c&&c<='z')return 1+(c-'a');
if('A'<=c&&c<='Z')return 27+(c-'A');
if('0'<=c&&c<='9')return 53+(c-'0');
cerr<<"ERROR in code(char c)"<<" : "<<c<<endl;
return -1;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n,m,k;cin>>n>>m>>k;
vector<stamp> s(k+1);
{
vst g(n);
rep(i,0,n)cin>>g[i];
vi cnt(kind);
rep(i,0,n)rep(j,0,m)cnt[code(g[i][j])]++;
s[0]={n,m,g,cnt,0};
}
vst tar(n);
rep(i,0,n)cin>>tar[i];
rep(t,0,k){
int nt,mt;cin>>nt>>mt;
vst g(nt);
rep(i,0,nt)cin>>g[i];
vi cnt(kind);
rep(i,0,nt)rep(j,0,mt)cnt[code(g[i][j])]++;
s[t+1]={nt,mt,g,cnt,(int)t+1};
}
sort(all(s),comp);
// rep(i,0,k+1){
// cout<<s[i].n<<" "<<s[i].m<<" "<<s[i].ind<<endl;
// rep(j,0,s[i].n){
// cout<<s[i].g[j]<<endl;
// }
// }
vst nw=tar;
int flg=0;
vector<tuple<int,int,int>> op;
// cout<<"start op"<<endl;
rep(i,0,n*m){
// cout<<"now state"<<endl;
// rep(j,0,n)cout<<nw[j]<<endl;
// cout<<endl;
vi cnt(kind,0);
rep(j,0,n)rep(k,0,m){
cnt[code(nw[j][k])]++;
}
if(cnt[0]==n*m){
flg=1;
break;
}
int use=-1;
per(f,k,0){
int nd=0;
rep(j,1,kind){
int p=cnt[j],q=s[f].cnt[j];
nd+=max(q-p,0);
}
// cout<<f<<" -> "<<s[f].n<<" * "<<s[f].m<<" %% "<<nd<<" : "<<cnt[0]<<endl;
if(nd>cnt[0]||s[f].n*s[f].m-nd==0){
continue;
}
use=s[f].ind;
// cout<<f<<" = use"<<endl;
// cout<<s[f].n<<" &&& "<<s[f].m<<endl;
// rep(w,0,s[f].n)cout<<s[f].g[w]<<endl;
vi sm(kind,0);
rep(j,0,s[f].n){
rep(k,0,s[f].m){
// cout<<"fij = "<<f<<" "<<s[f].g[j][k]<<endl;
int id=code(s[f].g[j][k]);
int tar;
// cout<<id<<" "<<sm[id]<<" :: "<<cnt[id]<<endl;
if(sm[id]<cnt[id])tar=id;
else tar=0;
// nw[j][k] を tar にしたい
if(code(nw[j][k])==tar)continue;
// cout<<j<<" "<<k<<" ----> "<<tar<<" = tar"<<endl;
int change=0;
rep(sj,0,n){
rep(sk,0,m){
if(change)break;
if(sj<j&&sk<s[f].m)continue;
if(sj==j&&sk<k)continue;
if(code(nw[sj][sk])==tar){
// (sj, sk) -> (j, k)
// cout<<sj<<" "<<sk<<" --> "<<j<<" "<<k<<endl;
int nj=sj,nk=sk;
while(nj!=j||nk!=k){
if(nj<j){
op.emplace_back(-3,nj,nk);
swap(nw[nj][nk],nw[nj+1][nk]);
nj++;
}
else if(nk<k){
op.emplace_back(-1,nj,nk);
swap(nw[nj][nk],nw[nj][nk+1]);
nk++;
}
else if(j<nj){
op.emplace_back(-3,nj-1,nk);
swap(nw[nj][nk],nw[nj-1][nk]);
nj--;
}
else{
op.emplace_back(-1,nj,nk-1);
swap(nw[nj][nk],nw[nj][nk-1]);
nk--;
}
}
change=1;
break;
}
}
}
sm[id]++;
}
}
rep(j,0,s[f].n){
rep(k,0,s[f].m){
if(nw[j][k]!=s[f].g[j][k]){
cout<<"ERROR in fix"<<endl;
}
nw[j][k]='#';
}
}
if(use!=0)op.emplace_back(use,0,0);
break;
}
if(use==-1){
cout<<-1<<endl;
return 0;
}
}
reverse(all(op));
cout<<op.size()<<endl;
for(auto [o,x,y]:op){
cout<<o<<" "<<x+1<<" "<<y+1<<endl;
}
}
详细
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3592kb
input:
3 3 1 OOO GOG BGB OOO GGG BBB 3 1 B G B
output:
ERROR in fix ERROR in fix ERROR in fix 13 -1 3 1 -3 2 3 -1 3 2 -1 2 1 -3 1 3 -1 2 2 -1 1 2 -1 1 1 1 1 1 -1 3 1 -1 2 1 -3 1 1 -3 2 1
result:
wrong output format Expected integer, but "ERROR" found