QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#231102#7635. Fairy Chessucup-team484#WA 101ms3616kbC++172.7kb2023-10-29 01:57:392023-10-29 01:57:40

Judging History

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

  • [2023-10-29 01:57:40]
  • 评测
  • 测评结果:WA
  • 用时:101ms
  • 内存:3616kb
  • [2023-10-29 01:57:39]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define sz(x) ((int) (x).size())
typedef long long ll;
typedef pair<int,int> pii;
template<class T> void print(T & x){ cout << x; }
template<class T,class U> void print(pair<T,U> & p){cout << "("; print(p.first); cout << ", "; print(p.second); cout << ")"; }
template<class T> void print(vector<T> & v) {
  cout << "{";
  if (sz(v)) print(v[0]);
  for (int i = 1; i < sz(v); i++) cout << ", ", print(v[i]);
  cout << "}\n";
}

vector<int> order;
vector<char> diag, file, knight;
vector<int> aD1(15), aD2(15), aF1(8), aF2(8);
vector<int> oD1(15), oD2(15), oF1(8), oF2(8);
vector<vector<int>> aB(8, vector<int>(8));
vector<vector<int>> oB(8, vector<int>(8));
vector<int> knX = {1, 2, 2, 1, -1, -2, -2, -1};
vector<int> knY = {2, 1, -1, -2, -2, -1, -1, -2};

int d1(int y, int x){
  return y + x;
}
int d2(int y, int x){
  return y + 7 - x;
}
int f1(int y, int x){
  return y;
}
int f2(int y, int x){
  return x;
}
bool onK(int y, int x){
  for(int i=0; i<8; i++){
    int ny = y + knY[i];
    int nx = x + knX[i];
    if(ny >= 0 && ny < 8 && nx >= 0 && nx < 8 && oB[ny][nx])
      return true;
  }
  return false;
}
void markK(int y, int x, int v){
  for(int i=0; i<8; i++){
    int ny = y + knY[i];
    int nx = x + knX[i];
    if(ny >= 0 && ny < 8 && nx >= 0 && nx < 8)
      aB[ny][nx] += v;
  }
}

int solve(int ind){
  if(ind == sz(order))
    return -1;
  int piece = order[ind];
  for(int y=0; y<8; y++){
    for(int x=0; x<8; x++){
      int xd1 = d1(y, x);
      int xd2 = d2(y, x);
      int xf1 = f1(y, x);
      int xf2 = f2(y, x);
      if(aD1[xd1] || aD2[xd2] || aF1[xf1] || aF2[xf2] || aB[y][x])
        continue;
      if((diag[piece] && (oD1[xd1] || oD2[xd2])) ||
         (file[piece] && (oF1[xf1] || oF2[xf2])) ||
         (knight[piece] && onK(y, x)))
        continue;
      auto addV = [&](int v){
        oD1[xd1] += v;
        oD2[xd2] += v;
        oF1[xf1] += v;
        oF2[xf2] += v;
        oB[y][x] += v;
        if(diag[piece]){
          aD1[xd1] += v;
          aD2[xd2] += v;
        }
        if(file[piece]){
          aF1[xf1] += v;
          aF2[xf2] += v;
        }
        if(knight[piece]){
          markK(y, x, v);
        }
      };
      addV(1);
      int res = solve(ind+1);
      addV(-1);
      if(res == -1){
        return 1;
      }
    }
  }
  return -1;
}


int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  string S;
  cin >> S;
  map<char,int> M;
  string mapping = "BRQACM";
  for(int i=0; i<sz(mapping); i++){
    M[mapping[i]] = i;
  }
  for(char c : S){
    order.push_back(M[c]);
  }
  diag = {1, 0, 1, 1, 0, 1};
  file = {0, 1, 1, 0, 1, 1};
  knight = {0, 0, 0, 1, 1, 1};
  int res = solve(0);
  if(res == 1)
    cout << "Alice" << endl;
  else
    cout << "Bob" << endl;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 101ms
memory: 3616kb

input:

BBAARRCCQQMM

output:

Bob

result:

ok single line: 'Bob'

Test #2:

score: 0
Accepted
time: 11ms
memory: 3468kb

input:

BAMBAMQQRCCR

output:

Alice

result:

ok single line: 'Alice'

Test #3:

score: -100
Wrong Answer
time: 71ms
memory: 3616kb

input:

QQRAACMRMCBB

output:

Bob

result:

wrong answer 1st lines differ - expected: 'Alice', found: 'Bob'