Submission #321702

#TimeUsernameProblemLanguageResultExecution timeMemory
321702seedkinGet Hundred Points! (FXCUP4_hundred)C++17
0 / 100
2 ms620 KiB
#include "hundred.h" #include <stdio.h> #define aBit 1 #define bBit 2 #define cBit 4 #define aIdx 0 #define bIdx 1 #define cIdx 2 int dir[100][8][100]; // dir[idx][char bit][target idx] = char bit std::string GetHundredPoints(int A, int B, int C) { // int a, b, c; // a = b = c = 0; int isCorret[105]; int candi[105]; // char ans[100]; int bit[500]; bit['A'] = aBit; bit['B'] = bBit; bit['C'] = cBit; // char c[5]; // c[aBit] = 'A'; // c[bBit] = 'B'; // c[cBit] = 'C'; std::string str = std::string(A, 'A') + std::string(B, 'B') + std::string(C, 'C'); for (int i = 0; i < 100; i++) { isCorret[i] = 0; // ans[i] = 'A'; candi[i] = aBit | bBit | cBit; } for (int i = 0; i < 100; i++) { for (int j = 0; j < 8; j++) { for (int k = 0; k < 100; k++) { dir[i][j][k] = -1; } } } int result = Mark(str); if (result == A + B + C) return str; int prevResult = result; for (int i = 0; i < A + B + C; i++) { if (isCorret[i]) continue; if (candi[i] == aBit && str[i] == 'A') { isCorret[i] = 1; continue; } if (candi[i] == bBit && str[i] == 'B') { isCorret[i] = 1; continue; } if (candi[i] == cBit && str[i] == 'C') { isCorret[i] = 1; continue; } for (int j = i + 1; j < A + B + C; j++) { if (candi[i] == aBit || candi[i] == bBit || candi[i] == cBit) break;; if (candi[j] == aBit && str[j] == 'A') { isCorret[j] = 1; } if (candi[j] == bBit && str[j] == 'B') { isCorret[j] = 1; } if (candi[j] == cBit && str[j] == 'C') { isCorret[j] = 1; } if (str[i] == str[j]) continue; if ((candi[i] & bit[str[j]]) == 0) continue; char temp = str[i]; str[i] = str[j]; str[j] = temp; result = Mark(str); if (result == A + B + C) return str; int r = result - prevResult; if (r == 0) { temp = str[i]; str[i] = str[j]; str[j] = temp; if(isCorret[j]) { candi[i] = bit[str[j]]; break; } else { dir[i][bit['A']][j] = bit['A']; dir[i][bit['B']][j] = bit['B']; dir[i][bit['C']][j] = bit['C']; } continue; } else if (r == 1) { prevResult = result; candi[i] &= ~bit[str[j]]; candi[j] &= ~bit[str[i]]; dir[i][bit[str[i]]][j] = candi[i] & (~bit[str[i]]); dir[i][(candi[i] & (~bit[str[i]]))][j] = bit[str[j]]; continue; } else if (r == 2) { prevResult = result; candi[i] = bit[str[i]]; candi[j] = bit[str[j]]; isCorret[i] = 1; isCorret[j] = 1; for (int k = i + 1; k < j; k++) { if (isCorret[k]) continue; if (dir[i][bit[str[i]]][k] == -1) continue; candi[k] = dir[i][bit[str[i]]][k]; } break; } else if (r == -1) { temp = str[i]; str[i] = str[j]; str[j] = temp; if(isCorret[j]) { candi[i] &= ~bit[str[j]]; candi[i] &= ~bit[str[i]]; break; } else { candi[i] &= ~bit[str[j]]; candi[j] &= ~bit[str[i]]; dir[i][bit[str[i]]][j] = candi[i] & (~bit[str[i]]); dir[i][(candi[i] & (~bit[str[i]]))][j] = bit[str[j]]; } continue; } else { temp = str[i]; str[i] = str[j]; str[j] = temp; candi[i] &= ~bit[str[i]]; candi[j] &= ~bit[str[j]]; isCorret[i] = 1; isCorret[j] = 1; for (int k = i + 1; k < j; k++) { if (isCorret[k]) continue; if (dir[i][bit[str[i]]][k] == -1) continue; candi[k] = dir[i][bit[str[i]]][k]; } break; } } if (isCorret[i]) continue; for (int j = i + 1; j < A + B + C; j++) { if (!(candi[i] == aBit || candi[i] == bBit || candi[i] == cBit)) break;; if (isCorret[j]) continue; if (candi[j] == aBit && str[j] == 'A') { isCorret[j] = 1; continue; } if (candi[j] == bBit && str[j] == 'B') { isCorret[j] = 1; continue; } if (candi[j] == cBit && str[j] == 'C') { isCorret[j] = 1; continue; } if (str[i] == str[j]) continue; if ((candi[i] & bit[str[j]]) == 0) continue; if ((candi[j] & bit[str[i]]) == 0) continue; char temp = str[i]; str[i] = str[j]; str[j] = temp; result = Mark(str); if (result == A + B + C) return str; int r = result - prevResult; if (r == 2) { prevResult = result; candi[i] = bit[str[i]]; candi[j] = bit[str[j]]; isCorret[i] = 1; isCorret[j] = 1; } else if (r == 1) { prevResult = result; candi[i] = bit[str[i]]; candi[j] &= ~bit[str[j]]; candi[j] &= ~bit[str[i]]; isCorret[i] = 1; } else if (r == 0) { prevResult = result; candi[i] = bit[str[i]]; candi[j] = bit[str[i]]; isCorret[i] = 1; } else { printf("err %d\n", r); } for (int k = i + 1; k < j; k++) { if (isCorret[k]) continue; if (dir[i][bit[str[i]]][k] == -1) continue; candi[k] = dir[i][bit[str[i]]][k]; } break; } } return str; }

Compilation message (stderr)

hundred.cpp: In function 'std::string GetHundredPoints(int, int, int)':
hundred.cpp:72:30: warning: array subscript has type 'char' [-Wchar-subscripts]
   72 |    if ((candi[i] & bit[str[j]]) == 0) continue;
      |                              ^
hundred.cpp:85:27: warning: array subscript has type 'char' [-Wchar-subscripts]
   85 |      candi[i] = bit[str[j]];
      |                           ^
hundred.cpp:96:28: warning: array subscript has type 'char' [-Wchar-subscripts]
   96 |     candi[i] &= ~bit[str[j]];
      |                            ^
hundred.cpp:97:28: warning: array subscript has type 'char' [-Wchar-subscripts]
   97 |     candi[j] &= ~bit[str[i]];
      |                            ^
hundred.cpp:98:22: warning: array subscript has type 'char' [-Wchar-subscripts]
   98 |     dir[i][bit[str[i]]][j] = candi[i] & (~bit[str[i]]);
      |                      ^
hundred.cpp:98:53: warning: array subscript has type 'char' [-Wchar-subscripts]
   98 |     dir[i][bit[str[i]]][j] = candi[i] & (~bit[str[i]]);
      |                                                     ^
hundred.cpp:99:36: warning: array subscript has type 'char' [-Wchar-subscripts]
   99 |     dir[i][(candi[i] & (~bit[str[i]]))][j] = bit[str[j]];
      |                                    ^
hundred.cpp:99:56: warning: array subscript has type 'char' [-Wchar-subscripts]
   99 |     dir[i][(candi[i] & (~bit[str[i]]))][j] = bit[str[j]];
      |                                                        ^
hundred.cpp:104:26: warning: array subscript has type 'char' [-Wchar-subscripts]
  104 |     candi[i] = bit[str[i]];
      |                          ^
hundred.cpp:105:26: warning: array subscript has type 'char' [-Wchar-subscripts]
  105 |     candi[j] = bit[str[j]];
      |                          ^
hundred.cpp:110:27: warning: array subscript has type 'char' [-Wchar-subscripts]
  110 |      if (dir[i][bit[str[i]]][k] == -1) continue;
      |                           ^
hundred.cpp:111:34: warning: array subscript has type 'char' [-Wchar-subscripts]
  111 |      candi[k] = dir[i][bit[str[i]]][k];
      |                                  ^
hundred.cpp:120:29: warning: array subscript has type 'char' [-Wchar-subscripts]
  120 |      candi[i] &= ~bit[str[j]];
      |                             ^
hundred.cpp:121:29: warning: array subscript has type 'char' [-Wchar-subscripts]
  121 |      candi[i] &= ~bit[str[i]];
      |                             ^
hundred.cpp:124:29: warning: array subscript has type 'char' [-Wchar-subscripts]
  124 |      candi[i] &= ~bit[str[j]];
      |                             ^
hundred.cpp:125:29: warning: array subscript has type 'char' [-Wchar-subscripts]
  125 |      candi[j] &= ~bit[str[i]];
      |                             ^
hundred.cpp:126:23: warning: array subscript has type 'char' [-Wchar-subscripts]
  126 |      dir[i][bit[str[i]]][j] = candi[i] & (~bit[str[i]]);
      |                       ^
hundred.cpp:126:54: warning: array subscript has type 'char' [-Wchar-subscripts]
  126 |      dir[i][bit[str[i]]][j] = candi[i] & (~bit[str[i]]);
      |                                                      ^
hundred.cpp:127:37: warning: array subscript has type 'char' [-Wchar-subscripts]
  127 |      dir[i][(candi[i] & (~bit[str[i]]))][j] = bit[str[j]];
      |                                     ^
hundred.cpp:127:57: warning: array subscript has type 'char' [-Wchar-subscripts]
  127 |      dir[i][(candi[i] & (~bit[str[i]]))][j] = bit[str[j]];
      |                                                         ^
hundred.cpp:135:28: warning: array subscript has type 'char' [-Wchar-subscripts]
  135 |     candi[i] &= ~bit[str[i]];
      |                            ^
hundred.cpp:136:28: warning: array subscript has type 'char' [-Wchar-subscripts]
  136 |     candi[j] &= ~bit[str[j]];
      |                            ^
hundred.cpp:141:27: warning: array subscript has type 'char' [-Wchar-subscripts]
  141 |      if (dir[i][bit[str[i]]][k] == -1) continue;
      |                           ^
hundred.cpp:142:34: warning: array subscript has type 'char' [-Wchar-subscripts]
  142 |      candi[k] = dir[i][bit[str[i]]][k];
      |                                  ^
hundred.cpp:166:30: warning: array subscript has type 'char' [-Wchar-subscripts]
  166 |    if ((candi[i] & bit[str[j]]) == 0) continue;
      |                              ^
hundred.cpp:167:30: warning: array subscript has type 'char' [-Wchar-subscripts]
  167 |    if ((candi[j] & bit[str[i]]) == 0) continue;
      |                              ^
hundred.cpp:178:26: warning: array subscript has type 'char' [-Wchar-subscripts]
  178 |     candi[i] = bit[str[i]];
      |                          ^
hundred.cpp:179:26: warning: array subscript has type 'char' [-Wchar-subscripts]
  179 |     candi[j] = bit[str[j]];
      |                          ^
hundred.cpp:185:26: warning: array subscript has type 'char' [-Wchar-subscripts]
  185 |     candi[i] = bit[str[i]];
      |                          ^
hundred.cpp:186:28: warning: array subscript has type 'char' [-Wchar-subscripts]
  186 |     candi[j] &= ~bit[str[j]];
      |                            ^
hundred.cpp:187:28: warning: array subscript has type 'char' [-Wchar-subscripts]
  187 |     candi[j] &= ~bit[str[i]];
      |                            ^
hundred.cpp:192:26: warning: array subscript has type 'char' [-Wchar-subscripts]
  192 |     candi[i] = bit[str[i]];
      |                          ^
hundred.cpp:193:26: warning: array subscript has type 'char' [-Wchar-subscripts]
  193 |     candi[j] = bit[str[i]];
      |                          ^
hundred.cpp:202:26: warning: array subscript has type 'char' [-Wchar-subscripts]
  202 |     if (dir[i][bit[str[i]]][k] == -1) continue;
      |                          ^
hundred.cpp:203:33: warning: array subscript has type 'char' [-Wchar-subscripts]
  203 |     candi[k] = dir[i][bit[str[i]]][k];
      |                                 ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...