QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#231106#7635. Fairy Chessucup-team484#AC ✓1081ms3516kbC++172.7kb2023-10-29 02:01:392023-10-29 02:01:40

Judging History

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

  • [2023-10-29 02:01:40]
  • 评测
  • 测评结果:AC
  • 用时:1081ms
  • 内存:3516kb
  • [2023-10-29 02:01: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: 84ms
memory: 3464kb

input:

BBAARRCCQQMM

output:

Bob

result:

ok single line: 'Bob'

Test #2:

score: 0
Accepted
time: 10ms
memory: 3448kb

input:

BAMBAMQQRCCR

output:

Alice

result:

ok single line: 'Alice'

Test #3:

score: 0
Accepted
time: 5ms
memory: 3440kb

input:

QQRAACMRMCBB

output:

Alice

result:

ok single line: 'Alice'

Test #4:

score: 0
Accepted
time: 19ms
memory: 3412kb

input:

MBBARQRMACQC

output:

Alice

result:

ok single line: 'Alice'

Test #5:

score: 0
Accepted
time: 5ms
memory: 3408kb

input:

ACQCMQRBBRMA

output:

Alice

result:

ok single line: 'Alice'

Test #6:

score: 0
Accepted
time: 10ms
memory: 3436kb

input:

MRCMABRQCQAB

output:

Alice

result:

ok single line: 'Alice'

Test #7:

score: 0
Accepted
time: 19ms
memory: 3424kb

input:

BBRCMMQAAQRC

output:

Alice

result:

ok single line: 'Alice'

Test #8:

score: 0
Accepted
time: 16ms
memory: 3376kb

input:

RRMCQMACABQB

output:

Alice

result:

ok single line: 'Alice'

Test #9:

score: 0
Accepted
time: 17ms
memory: 3472kb

input:

QMQBMRBACACR

output:

Alice

result:

ok single line: 'Alice'

Test #10:

score: 0
Accepted
time: 6ms
memory: 3420kb

input:

CMRQAQCBBRAM

output:

Alice

result:

ok single line: 'Alice'

Test #11:

score: 0
Accepted
time: 20ms
memory: 3512kb

input:

CABCRQMMRQAB

output:

Alice

result:

ok single line: 'Alice'

Test #12:

score: 0
Accepted
time: 57ms
memory: 3472kb

input:

ARCBBCMQRAQM

output:

Alice

result:

ok single line: 'Alice'

Test #13:

score: 0
Accepted
time: 3ms
memory: 3412kb

input:

ARCMCARMQBBQ

output:

Alice

result:

ok single line: 'Alice'

Test #14:

score: 0
Accepted
time: 45ms
memory: 3444kb

input:

AQABMCQCMRRB

output:

Bob

result:

ok single line: 'Bob'

Test #15:

score: 0
Accepted
time: 9ms
memory: 3396kb

input:

ACMRABRQMCBQ

output:

Alice

result:

ok single line: 'Alice'

Test #16:

score: 0
Accepted
time: 43ms
memory: 3412kb

input:

CBARMBCQMQAR

output:

Bob

result:

ok single line: 'Bob'

Test #17:

score: 0
Accepted
time: 59ms
memory: 3472kb

input:

RBABRQMCAMQC

output:

Bob

result:

ok single line: 'Bob'

Test #18:

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

input:

MBCQBQARRMCA

output:

Alice

result:

ok single line: 'Alice'

Test #19:

score: 0
Accepted
time: 27ms
memory: 3424kb

input:

AMBQRBCQACMR

output:

Bob

result:

ok single line: 'Bob'

Test #20:

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

input:

QRAMQMBBCRAC

output:

Alice

result:

ok single line: 'Alice'

Test #21:

score: 0
Accepted
time: 8ms
memory: 3504kb

input:

ARBCQMMBARQC

output:

Alice

result:

ok single line: 'Alice'

Test #22:

score: 0
Accepted
time: 115ms
memory: 3396kb

input:

CACAMBRQQRBM

output:

Bob

result:

ok single line: 'Bob'

Test #23:

score: 0
Accepted
time: 34ms
memory: 3400kb

input:

CQRRMMBQABCA

output:

Bob

result:

ok single line: 'Bob'

Test #24:

score: 0
Accepted
time: 42ms
memory: 3396kb

input:

ABABCQRMMCRQ

output:

Alice

result:

ok single line: 'Alice'

Test #25:

score: 0
Accepted
time: 18ms
memory: 3400kb

input:

CMBRAAQRQMBC

output:

Bob

result:

ok single line: 'Bob'

Test #26:

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

input:

AQBMRMQRBACC

output:

Alice

result:

ok single line: 'Alice'

Test #27:

score: 0
Accepted
time: 21ms
memory: 3400kb

input:

BRACQQMCAMBR

output:

Bob

result:

ok single line: 'Bob'

Test #28:

score: 0
Accepted
time: 8ms
memory: 3484kb

input:

MCCAQBMQRABR

output:

Bob

result:

ok single line: 'Bob'

Test #29:

score: 0
Accepted
time: 42ms
memory: 3516kb

input:

RBQBCRAACMQM

output:

Bob

result:

ok single line: 'Bob'

Test #30:

score: 0
Accepted
time: 14ms
memory: 3384kb

input:

ACRQARMBBQMC

output:

Bob

result:

ok single line: 'Bob'

Test #31:

score: 0
Accepted
time: 2ms
memory: 3416kb

input:

MRCQBCBQRMAA

output:

Alice

result:

ok single line: 'Alice'

Test #32:

score: 0
Accepted
time: 16ms
memory: 3508kb

input:

ACRQQCMMBBAR

output:

Bob

result:

ok single line: 'Bob'

Test #33:

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

input:

MMACQBRQABRC

output:

Bob

result:

ok single line: 'Bob'

Test #34:

score: 0
Accepted
time: 4ms
memory: 3392kb

input:

QACMQABRMCBR

output:

Alice

result:

ok single line: 'Alice'

Test #35:

score: 0
Accepted
time: 15ms
memory: 3448kb

input:

ACAQRCMRMBQB

output:

Alice

result:

ok single line: 'Alice'

Test #36:

score: 0
Accepted
time: 25ms
memory: 3404kb

input:

RABQCQMCABMR

output:

Bob

result:

ok single line: 'Bob'

Test #37:

score: 0
Accepted
time: 9ms
memory: 3416kb

input:

QQBARCRBMMAC

output:

Alice

result:

ok single line: 'Alice'

Test #38:

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

input:

RQMRQABCABCM

output:

Alice

result:

ok single line: 'Alice'

Test #39:

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

input:

RQAMBRQCCBMA

output:

Alice

result:

ok single line: 'Alice'

Test #40:

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

input:

QQBACMARMRBC

output:

Alice

result:

ok single line: 'Alice'

Test #41:

score: 0
Accepted
time: 9ms
memory: 3380kb

input:

QAQCRRAMMCBB

output:

Alice

result:

ok single line: 'Alice'

Test #42:

score: 0
Accepted
time: 14ms
memory: 3380kb

input:

QQBMCBRARMAC

output:

Bob

result:

ok single line: 'Bob'

Test #43:

score: 0
Accepted
time: 106ms
memory: 3436kb

input:

BABARRCCQQMM

output:

Bob

result:

ok single line: 'Bob'

Test #44:

score: 0
Accepted
time: 591ms
memory: 3412kb

input:

BBARARCCQQMM

output:

Alice

result:

ok single line: 'Alice'

Test #45:

score: 0
Accepted
time: 45ms
memory: 3500kb

input:

BBAARCRCQQMM

output:

Alice

result:

ok single line: 'Alice'

Test #46:

score: 0
Accepted
time: 165ms
memory: 3416kb

input:

BBAARRCQCQMM

output:

Bob

result:

ok single line: 'Bob'

Test #47:

score: 0
Accepted
time: 84ms
memory: 3392kb

input:

BBAARRCCQMQM

output:

Bob

result:

ok single line: 'Bob'

Test #48:

score: 0
Accepted
time: 413ms
memory: 3464kb

input:

BBAACCRQMQRM

output:

Bob

result:

ok single line: 'Bob'

Test #49:

score: 0
Accepted
time: 489ms
memory: 3376kb

input:

BACBACQRRQMM

output:

Bob

result:

ok single line: 'Bob'

Test #50:

score: 0
Accepted
time: 1081ms
memory: 3464kb

input:

RAABBRCCQQMM

output:

Bob

result:

ok single line: 'Bob'

Test #51:

score: 0
Accepted
time: 96ms
memory: 3452kb

input:

RABRBQMCACQM

output:

Bob

result:

ok single line: 'Bob'

Test #52:

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

input:

CMMQQABCRABR

output:

Alice

result:

ok single line: 'Alice'

Test #53:

score: 0
Accepted
time: 224ms
memory: 3444kb

input:

RBAABRCCQQMM

output:

Alice

result:

ok single line: 'Alice'

Extra Test:

score: 0
Extra Test Passed