QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#757999#5416. Fabulous Fungus FrenzyMitsubachiWA 4ms3816kbC++145.4kb2024-11-17 15:04:042024-11-17 15:04:11

Judging History

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

  • [2024-11-17 15:04:11]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:3816kb
  • [2024-11-17 15:04:04]
  • 提交

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);
      }
      if(i==1&&f==19)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]&&nw[j][k]!='#'){
            cout<<"ERROR in fix"<<endl;
            cout<<"step "<<i<<" :: "<<j<<" "<<k<<" "<<nw[j][k]<<" "<<s[f].g[j][k]<<endl;
            cout<<f<<" "<<s[f].n<<" "<<s[f].m<<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: 100
Accepted
time: 0ms
memory: 3524kb

input:

3 3 1
OOO
GOG
BGB

OOO
GGG
BBB

3 1
B
G
B

output:

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:

ok puzzle solved

Test #2:

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

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: 3816kb

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:

102
1 1 1
-1 2 3
-1 2 4
-1 2 5
-1 2 6
-1 2 7
-3 2 8
-3 3 8
1 1 1
-1 2 3
-1 2 4
-1 2 5
-1 2 6
-3 2 7
-3 3 7
1 1 1
-1 2 3
-1 2 4
-1 2 5
-3 2 6
-3 3 6
1 1 1
-1 2 3
-1 2 4
-3 2 5
-3 3 5
1 1 1
-1 2 3
-3 2 4
-3 3 4
2 1 1
-3 3 8
-3 3 7
-3 3 6
-3 3 5
-3 3 3
-3 3 2
-3 3 1
-3 2 8
-1 3 7
-1 3 6
-3 2 7
-1 3 6
-...

result:

ok puzzle solved

Test #4:

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

input:

2 2 1
OO
OO

OP
PP

1 2
PP

output:

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

result:

ok puzzle solved

Test #5:

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

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: 3580kb

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: 3588kb

input:

2 2 1
OO
OO

OP
PP

1 2
OP

output:

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

result:

ok puzzle solved

Test #8:

score: -100
Wrong Answer
time: 4ms
memory: 3704kb

input:

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

output:

19 -> 1 * 1 %% 0 : 1
9979
1 1 1
-1 1 1
-1 1 2
-1 1 3
-1 1 4
-1 1 5
-1 1 6
-1 1 7
-1 1 8
-1 1 9
-1 1 10
-1 1 11
-1 1 12
-1 1 13
-1 1 14
-1 1 15
-1 1 16
-1 1 17
-1 1 18
-1 1 19
-3 1 20
-3 2 20
-3 3 20
-3 4 20
-3 5 20
-3 6 20
-3 7 20
-3 8 20
-3 9 20
-3 10 20
-3 11 20
-3 12 20
-3 13 20
-3 14 20
-3 15 20...

result:

wrong output format Expected integer, but "->" found