Submission #328275

# Submission time Handle Problem Language Result Execution time Memory
328275 2020-11-16T04:17:57 Z seedkin Get Hundred Points! (FXCUP4_hundred) C++17
100 / 100
3 ms 748 KB
#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;
	int allBit = 7;
	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');
	std::string ans = 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;
	int mid = A;
	if (A == 0) mid = A + B;


	for (int i = mid; i < A + B + C; i++) {
		char temp = str[0];
		str[0] = str[i];
		str[i] = temp;
		result = Mark(str);
		if (result == A + B + C) return str;
		temp = str[0];
		str[0] = str[i];
		str[i] = temp;
		int r = result - prevResult;
		if (r == 0) {
			dir[0][bit['A']][i] = bit['A'];
			dir[0][bit['B']][i] = bit['B'];
			dir[0][bit['C']][i] = bit['C'];
		}
		else if (r == 1) {
			int other = allBit & ~bit[str[0]] & ~bit[str[i]];
			candi[0] &= ~bit[str[0]];
			candi[i] &= ~bit[str[i]];
			dir[0][bit[str[i]]][i] = other;
			dir[0][other][i] = bit[str[0]];
		}
		else if (r == 2) {
			candi[0] = bit[str[i]];
			candi[i] = bit[str[0]];
			isCorret[0] = 1;
			isCorret[i] = 1;
		}
		else if (r == -1) {
			int other = allBit & ~bit[str[0]] & ~bit[str[i]];
			candi[0] &= ~bit[str[i]];
			candi[i] &= ~bit[str[0]];
			dir[0][other][i] = bit[str[i]];
			dir[0][bit[str[0]]][i] = other;
		}
		else {
			candi[0] = bit[str[0]];
			candi[i] = bit[str[i]];
			isCorret[0] = 1;
			isCorret[i] = 1;
		}
	}

	for (int i = 1; i < mid; i++) {
		char temp = str[mid];
		str[mid] = str[i];
		str[i] = temp;
		result = Mark(str);
		if (result == A + B + C) return str;
		temp = str[mid];
		str[mid] = str[i];
		str[i] = temp;
		int r = result - prevResult;
		if (r == 0) {
			dir[mid][bit['A']][i] = bit['A'];
			dir[mid][bit['B']][i] = bit['B'];
			dir[mid][bit['C']][i] = bit['C'];
		}
		else if (r == 1) {
			int other = allBit & ~bit[str[mid]] & ~bit[str[i]];
			candi[mid] &= ~bit[str[mid]];
			candi[i] &= ~bit[str[i]];
			dir[mid][bit[str[i]]][i] = other;
			dir[mid][other][i] = bit[str[mid]];
		}
		else if (r == 2) {
			candi[mid] = bit[str[i]];
			candi[i] = bit[str[mid]];
			isCorret[mid] = 1;
			isCorret[i] = 1;
		}
		else if (r == -1) {
			int other = allBit & ~bit[str[mid]] & ~bit[str[i]];
			candi[mid] &= ~bit[str[i]];
			candi[i] &= ~bit[str[mid]];
			dir[mid][other][i] = bit[str[i]];
			dir[mid][bit[str[mid]]][i] = other;
		}
		else {
			candi[mid] = bit[str[mid]];
			candi[i] = bit[str[i]];
			isCorret[mid] = 1;
			isCorret[i] = 1;
		}
	}

	for (int i = 0; i < A + B + C; i++) {
		if (isCorret[i]) ans[i] = c[candi[i]];
	}

	if (isCorret[mid] == 0) {
		ans[mid] = c[dir[0][bit[ans[0]]][mid]];
	}

	for (int i = 1; i < A + B + C; i++) {
		if (isCorret[i]) continue;
		int zero = dir[0][bit[ans[0]]][i];
		int midV = dir[mid][bit[ans[mid]]][i];
		if (zero != -1) {
			ans[i] = c[zero];
		}
		if (midV != -1) {
			ans[i] = c[midV];
		}
	}

	return ans;
}

Compilation message

hundred.cpp: In function 'std::string GetHundredPoints(int, int, int)':
hundred.cpp:67:36: warning: array subscript has type 'char' [-Wchar-subscripts]
   67 |    int other = allBit & ~bit[str[0]] & ~bit[str[i]];
      |                                    ^
hundred.cpp:67:51: warning: array subscript has type 'char' [-Wchar-subscripts]
   67 |    int other = allBit & ~bit[str[0]] & ~bit[str[i]];
      |                                                   ^
hundred.cpp:68:27: warning: array subscript has type 'char' [-Wchar-subscripts]
   68 |    candi[0] &= ~bit[str[0]];
      |                           ^
hundred.cpp:69:27: warning: array subscript has type 'char' [-Wchar-subscripts]
   69 |    candi[i] &= ~bit[str[i]];
      |                           ^
hundred.cpp:70:21: warning: array subscript has type 'char' [-Wchar-subscripts]
   70 |    dir[0][bit[str[i]]][i] = other;
      |                     ^
hundred.cpp:71:33: warning: array subscript has type 'char' [-Wchar-subscripts]
   71 |    dir[0][other][i] = bit[str[0]];
      |                                 ^
hundred.cpp:74:25: warning: array subscript has type 'char' [-Wchar-subscripts]
   74 |    candi[0] = bit[str[i]];
      |                         ^
hundred.cpp:75:25: warning: array subscript has type 'char' [-Wchar-subscripts]
   75 |    candi[i] = bit[str[0]];
      |                         ^
hundred.cpp:80:36: warning: array subscript has type 'char' [-Wchar-subscripts]
   80 |    int other = allBit & ~bit[str[0]] & ~bit[str[i]];
      |                                    ^
hundred.cpp:80:51: warning: array subscript has type 'char' [-Wchar-subscripts]
   80 |    int other = allBit & ~bit[str[0]] & ~bit[str[i]];
      |                                                   ^
hundred.cpp:81:27: warning: array subscript has type 'char' [-Wchar-subscripts]
   81 |    candi[0] &= ~bit[str[i]];
      |                           ^
hundred.cpp:82:27: warning: array subscript has type 'char' [-Wchar-subscripts]
   82 |    candi[i] &= ~bit[str[0]];
      |                           ^
hundred.cpp:83:33: warning: array subscript has type 'char' [-Wchar-subscripts]
   83 |    dir[0][other][i] = bit[str[i]];
      |                                 ^
hundred.cpp:84:21: warning: array subscript has type 'char' [-Wchar-subscripts]
   84 |    dir[0][bit[str[0]]][i] = other;
      |                     ^
hundred.cpp:87:25: warning: array subscript has type 'char' [-Wchar-subscripts]
   87 |    candi[0] = bit[str[0]];
      |                         ^
hundred.cpp:88:25: warning: array subscript has type 'char' [-Wchar-subscripts]
   88 |    candi[i] = bit[str[i]];
      |                         ^
hundred.cpp:110:38: warning: array subscript has type 'char' [-Wchar-subscripts]
  110 |    int other = allBit & ~bit[str[mid]] & ~bit[str[i]];
      |                                      ^
hundred.cpp:110:53: warning: array subscript has type 'char' [-Wchar-subscripts]
  110 |    int other = allBit & ~bit[str[mid]] & ~bit[str[i]];
      |                                                     ^
hundred.cpp:111:31: warning: array subscript has type 'char' [-Wchar-subscripts]
  111 |    candi[mid] &= ~bit[str[mid]];
      |                               ^
hundred.cpp:112:27: warning: array subscript has type 'char' [-Wchar-subscripts]
  112 |    candi[i] &= ~bit[str[i]];
      |                           ^
hundred.cpp:113:23: warning: array subscript has type 'char' [-Wchar-subscripts]
  113 |    dir[mid][bit[str[i]]][i] = other;
      |                       ^
hundred.cpp:114:37: warning: array subscript has type 'char' [-Wchar-subscripts]
  114 |    dir[mid][other][i] = bit[str[mid]];
      |                                     ^
hundred.cpp:117:27: warning: array subscript has type 'char' [-Wchar-subscripts]
  117 |    candi[mid] = bit[str[i]];
      |                           ^
hundred.cpp:118:27: warning: array subscript has type 'char' [-Wchar-subscripts]
  118 |    candi[i] = bit[str[mid]];
      |                           ^
hundred.cpp:123:38: warning: array subscript has type 'char' [-Wchar-subscripts]
  123 |    int other = allBit & ~bit[str[mid]] & ~bit[str[i]];
      |                                      ^
hundred.cpp:123:53: warning: array subscript has type 'char' [-Wchar-subscripts]
  123 |    int other = allBit & ~bit[str[mid]] & ~bit[str[i]];
      |                                                     ^
hundred.cpp:124:29: warning: array subscript has type 'char' [-Wchar-subscripts]
  124 |    candi[mid] &= ~bit[str[i]];
      |                             ^
hundred.cpp:125:29: warning: array subscript has type 'char' [-Wchar-subscripts]
  125 |    candi[i] &= ~bit[str[mid]];
      |                             ^
hundred.cpp:126:35: warning: array subscript has type 'char' [-Wchar-subscripts]
  126 |    dir[mid][other][i] = bit[str[i]];
      |                                   ^
hundred.cpp:127:25: warning: array subscript has type 'char' [-Wchar-subscripts]
  127 |    dir[mid][bit[str[mid]]][i] = other;
      |                         ^
hundred.cpp:130:29: warning: array subscript has type 'char' [-Wchar-subscripts]
  130 |    candi[mid] = bit[str[mid]];
      |                             ^
hundred.cpp:131:25: warning: array subscript has type 'char' [-Wchar-subscripts]
  131 |    candi[i] = bit[str[i]];
      |                         ^
hundred.cpp:142:33: warning: array subscript has type 'char' [-Wchar-subscripts]
  142 |   ans[mid] = c[dir[0][bit[ans[0]]][mid]];
      |                                 ^
hundred.cpp:147:31: warning: array subscript has type 'char' [-Wchar-subscripts]
  147 |   int zero = dir[0][bit[ans[0]]][i];
      |                               ^
hundred.cpp:148:35: warning: array subscript has type 'char' [-Wchar-subscripts]
  148 |   int midV = dir[mid][bit[ans[mid]]][i];
      |                                   ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 620 KB Output is correct
2 Correct 2 ms 620 KB Output is correct
3 Correct 2 ms 620 KB Output is correct
4 Correct 1 ms 620 KB Output is correct
5 Correct 2 ms 620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 620 KB Output is correct
2 Correct 2 ms 620 KB Output is correct
3 Correct 2 ms 620 KB Output is correct
4 Correct 1 ms 620 KB Output is correct
5 Correct 2 ms 620 KB Output is correct
6 Correct 2 ms 620 KB Output is correct
7 Correct 3 ms 620 KB Output is correct
8 Correct 2 ms 620 KB Output is correct
9 Correct 2 ms 620 KB Output is correct
10 Correct 1 ms 620 KB Output is correct
11 Correct 1 ms 620 KB Output is correct
12 Correct 1 ms 620 KB Output is correct
13 Correct 2 ms 748 KB Output is correct
14 Correct 2 ms 620 KB Output is correct
15 Correct 2 ms 620 KB Output is correct
16 Correct 2 ms 620 KB Output is correct