Submission #321315

# Submission time Handle Problem Language Result Execution time Memory
321315 2020-11-12T05:12:03 Z seedkin Get Hundred Points! (FXCUP4_hundred) C++17
0 / 100
1 ms 620 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[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;		
	}
	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;
		for(int j =i+1; j < A+B+C; j++) {
			
		}

		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;
			} 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

hundred.cpp: In function 'std::string GetHundredPoints(int, int, int)':
hundred.cpp:57:29: warning: array subscript has type 'char' [-Wchar-subscripts]
   57 |    if((candi[i] & bit[str[j]]) == 0) continue;
      |                             ^
hundred.cpp:58:29: warning: array subscript has type 'char' [-Wchar-subscripts]
   58 |    if((candi[j] & bit[str[i]]) == 0) continue;
      |                             ^
hundred.cpp:69:26: warning: array subscript has type 'char' [-Wchar-subscripts]
   69 |     candi[i] = bit[str[i]];
      |                          ^
hundred.cpp:70:26: warning: array subscript has type 'char' [-Wchar-subscripts]
   70 |     candi[j] = bit[str[j]];
      |                          ^
hundred.cpp:75:26: warning: array subscript has type 'char' [-Wchar-subscripts]
   75 |     candi[i] = bit[str[i]];
      |                          ^
hundred.cpp:76:28: warning: array subscript has type 'char' [-Wchar-subscripts]
   76 |     candi[j] &= ~bit[str[j]];
      |                            ^
hundred.cpp:77:28: warning: array subscript has type 'char' [-Wchar-subscripts]
   77 |     candi[j] &= ~bit[str[i]];
      |                            ^
hundred.cpp:81:26: warning: array subscript has type 'char' [-Wchar-subscripts]
   81 |     candi[i] = bit[str[i]];
      |                          ^
hundred.cpp:82:26: warning: array subscript has type 'char' [-Wchar-subscripts]
   82 |     candi[j] = bit[str[i]];
      |                          ^
hundred.cpp:90:25: warning: array subscript has type 'char' [-Wchar-subscripts]
   90 |     if(dir[i][bit[str[i]]][k] == -1) continue;
      |                         ^
hundred.cpp:91:33: warning: array subscript has type 'char' [-Wchar-subscripts]
   91 |     candi[k] = dir[i][bit[str[i]]][k];
      |                                 ^
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 620 KB Execution killed with signal 13 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 620 KB Execution killed with signal 13 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -