답안 #321312

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
321312 2020-11-12T05:05:39 Z seedkin 백점을 받아랏! (FXCUP4_hundred) C++17
0 / 100
2 ms 364 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

std::string GetHundredPoints(int A, int B, int C) {
	// int a, b, c;
	// a = b = c = 0;
	int isCorret[100];
	int candi[100];
	// 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;
	}
	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;
		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 (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 == 0) {
				temp = str[i];
				str[i] = str[j];
				str[j] = temp;
				continue;
			}
			else if (r == 1) {
				prevResult = result;
				candi[i] &= ~bit[str[j]];
				candi[j] &= ~bit[str[i]];
				continue;
			}
			else if (r == 2) {
				prevResult = result;
				candi[i] = bit[str[i]];
				candi[j] = bit[str[j]];
				isCorret[i] = 1;
				isCorret[j] = 1;
				break;
			}
			else if (r == -1) {
				temp = str[i];
				str[i] = str[j];
				str[j] = temp;
				candi[i] &= ~bit[str[j]];
				candi[j] &= ~bit[str[i]];
				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;
				break;
			}
		}

		if (isCorret[i]) continue;

		for (int j = i + 1; j < A + B + C; j++) {
			if (isCorret[j]) 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;
				break;
			}
			else if (r == 1) {
				prevResult = result;
				candi[i] = bit[str[i]];
				candi[j] &= ~bit[str[j]];
				candi[j] &= ~bit[str[i]];
				isCorret[i] = 1;
				break;
			}
			else if (r == 0) {
				prevResult = result;
				candi[i] = bit[str[i]];
				candi[j] = bit[str[i]];
				isCorret[i] = 1;
				break;
			}
			else {
				printf("err %d\n", r);
			}
		}
	}

	return str;
}

Compilation message

hundred.cpp: In function 'std::string GetHundredPoints(int, int, int)':
hundred.cpp:43:30: warning: array subscript has type 'char' [-Wchar-subscripts]
   43 |    if ((candi[i] & bit[str[j]]) == 0) continue;
      |                              ^
hundred.cpp:44:30: warning: array subscript has type 'char' [-Wchar-subscripts]
   44 |    if ((candi[j] & bit[str[i]]) == 0) continue;
      |                              ^
hundred.cpp:60:28: warning: array subscript has type 'char' [-Wchar-subscripts]
   60 |     candi[i] &= ~bit[str[j]];
      |                            ^
hundred.cpp:61:28: warning: array subscript has type 'char' [-Wchar-subscripts]
   61 |     candi[j] &= ~bit[str[i]];
      |                            ^
hundred.cpp:66:26: warning: array subscript has type 'char' [-Wchar-subscripts]
   66 |     candi[i] = bit[str[i]];
      |                          ^
hundred.cpp:67:26: warning: array subscript has type 'char' [-Wchar-subscripts]
   67 |     candi[j] = bit[str[j]];
      |                          ^
hundred.cpp:76:28: warning: array subscript has type 'char' [-Wchar-subscripts]
   76 |     candi[i] &= ~bit[str[j]];
      |                            ^
hundred.cpp:77:28: warning: array subscript has type 'char' [-Wchar-subscripts]
   77 |     candi[j] &= ~bit[str[i]];
      |                            ^
hundred.cpp:84:28: warning: array subscript has type 'char' [-Wchar-subscripts]
   84 |     candi[i] &= ~bit[str[i]];
      |                            ^
hundred.cpp:85:28: warning: array subscript has type 'char' [-Wchar-subscripts]
   85 |     candi[j] &= ~bit[str[j]];
      |                            ^
hundred.cpp:97:30: warning: array subscript has type 'char' [-Wchar-subscripts]
   97 |    if ((candi[i] & bit[str[j]]) == 0) continue;
      |                              ^
hundred.cpp:98:30: warning: array subscript has type 'char' [-Wchar-subscripts]
   98 |    if ((candi[j] & bit[str[i]]) == 0) continue;
      |                              ^
hundred.cpp:109:26: warning: array subscript has type 'char' [-Wchar-subscripts]
  109 |     candi[i] = bit[str[i]];
      |                          ^
hundred.cpp:110:26: warning: array subscript has type 'char' [-Wchar-subscripts]
  110 |     candi[j] = bit[str[j]];
      |                          ^
hundred.cpp:117:26: warning: array subscript has type 'char' [-Wchar-subscripts]
  117 |     candi[i] = bit[str[i]];
      |                          ^
hundred.cpp:118:28: warning: array subscript has type 'char' [-Wchar-subscripts]
  118 |     candi[j] &= ~bit[str[j]];
      |                            ^
hundred.cpp:119:28: warning: array subscript has type 'char' [-Wchar-subscripts]
  119 |     candi[j] &= ~bit[str[i]];
      |                            ^
hundred.cpp:125:26: warning: array subscript has type 'char' [-Wchar-subscripts]
  125 |     candi[i] = bit[str[i]];
      |                          ^
hundred.cpp:126:26: warning: array subscript has type 'char' [-Wchar-subscripts]
  126 |     candi[j] = bit[str[i]];
      |                          ^
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 364 KB Execution killed with signal 13 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 364 KB Execution killed with signal 13 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -