QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#469746#1646. Disk Sortprime-idealWA 0ms3592kbC++203.0kb2024-07-09 22:58:162024-07-09 22:58:17

Judging History

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

  • [2024-07-09 22:58:17]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3592kb
  • [2024-07-09 22:58:16]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define RN return
#define forw(_,l,r) for(auto _=(l);_<(r);++_)
#define fors(_,r,l) for(auto _=(r);_>(l);--_)
// #define DEBUG if((cout<<"line:"<<__LINE__<<'\n'), 1)
#define DEBUG if(0)
// #define int ll
#define fastio cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);

void read(){}
template<typename T,typename...Types>
void read(T& x, Types&...args){
  x=0; char c=' '; bool sgn=0;
  while(isspace(c))c=getchar();
  if(c=='-')c=getchar(),sgn=1;
  while(isdigit(c))x=10*x+c-'0',c=getchar();
  if(sgn)x=-x;
  read(args...);
}

// const int MOD=1e9+7, NUM=3010;
// struct fn{
//   int n; fn(int n=0):n(n){}
//   fn operator+(fn b){int r=n+b.n;RN r>=MOD?r-MOD:r;}
// }dp[NUM]={};

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;

const int NUM=1010;
typedef vector<pii> vpii;
vector<pii> recipe[3][3][3];
vector<pii> ret;
struct game{
  vi rod[NUM];
  int n,empty;
  set<pii> c2pos[NUM]={};
  set<int> hs2c[3][3][3]={};
  game(){
    auto& r=recipe[2];
    r[2][2]={{1,4},{2,4},{3,4},{1,2},{1,3}};
    r[2][1]={{1,4},{2,4},{3,1},{3,4},{3,2}};
    r[2][0]={{1,4},{2,4},{3,1},{3,2},{3,4}};
    r[1][1]={{1,4},{2,1},{2,4},{3,2},{3,4},{3,2}};
    r[1][0]={{1,4},{2,1},{2,4},{3,2},{3,2},{3,4}};
    read(n);
    forw(i,1,n+1)rod[i].resize(3);
    forw(i,0,3)forw(j,1,n+1)read(rod[j][2-i]);
    empty=n+1;
    forw(i,0,3)forw(j,1,n+1){
      c2pos[rod[j][i]].insert({i,j});
    }
    forw(i,1,n+1)update(i);
  }
  void update(int col,bool up=1){
    vi v; set<int> ys;
    for(auto [h,_]:c2pos[col]){
      v.push_back(h);
      ys.insert(_);
    }if(ys.size()==1)RN;
    sort(v.begin(),v.end());
    auto& tmp=hs2c[v[2]][v[1]][v[0]];
    if(up)tmp.insert(col);
    else tmp.erase(col);
  }
  void move(int f,int t){
    int topc=rod[f].back(),fh=rod[f].size()-1;
    auto&pos=c2pos[topc];
    update(topc,0);
    pos.erase({fh,f});
    rod[f].pop_back();
    rod[t].push_back(topc);
    int th=rod[t].size()-1;
    pos.insert({th,t});
    update(topc);
  }
  void move(vpii& recipe,vector<int>& id){
    id.push_back(empty);
    int pile[]={0,3,3,3,0};
    for(auto [f,t]:recipe){
      pile[f]--,pile[t]++;
      f=id[f],t=id[t];
      if(f==t)continue;
      ret.push_back({f,t});
      // cout<<f<<' '<<t<<'\n';
      move(f,t);
    }
    forw(i,1,5){
      if(pile[i]==0){empty=id[i];break;}
    }

  }
  bool move(){
    fors(i,2,0)fors(j,i,-1){
      auto&colors=hs2c[2][i][j];
      if(!colors.empty()){
        int col=*colors.begin();
        auto&pos3=c2pos[col];
        vi v={0}; for(auto [_,x]:pos3)v.push_back(x);
        reverse(v.begin()+1,v.end());
        move(recipe[2][i][j],v);
        RN 1;
      }
    }RN 0;
  }
};

int main()
{
  // fastio;
  game g;
  while(g.move());
  if(g.empty!=g.n+1)forw(i,0,3)ret.push_back({g.n+1,1});
  cout<<ret.size()<<'\n';
  for(auto [f,t]:ret)cout<<f<<' '<<t<<'\n';
  RN 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3592kb

input:

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

output:

8
3 5
3 5
2 3
2 5
2 3
5 1
5 1
5 1

result:

wrong answer Invalid move #5