Submission #114462

# Submission time Handle Problem Language Result Execution time Memory
114462 2019-06-01T12:02:57 Z 김세빈(#2861) Question (Grader is different from the original contest) (CEOI14_question_grader) C++14
100 / 100
2142 ms 80424 KB
int encode(int n, int x, int y)
{
	int C[15][15];
	int i, j, a, b, s;
	
	C[0][0] = 1;
	
	for(i=1; i<=12; i++){
		C[i][0] = 1;
		for(j=1; j<i; j++){
			C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
		}
		C[i][i] = C[i - 1][i - 1];
	}
	
	a = 6, b = 6;
	
	for(i=0, s=0; i<12; i++){
		if(a == 0) b --, s = s << 1 | 1;
		else if(b == 0) a --, s = s << 1;
		else if(x <= C[a + b - 1][a - 1]) a --, s <<= 1;
		else x -= C[a + b - 1][a - 1], b --, s = s << 1 | 1;
	}
	
	x ^= s ^= x ^= s;
	
	a = 6, b = 6;
	
	for(i=0, s=0; i<12; i++){
		if(a == 0) b --, s = s << 1 | 1;
		else if(b == 0) a --, s = s << 1;
		else if(y <= C[a + b - 1][a - 1]) a --, s <<= 1;
		else y -= C[a + b - 1][a - 1], b --, s = s << 1 | 1;
	}
	
	y ^= s ^= y ^= s;
	
	for(i=0; i<12; i++){
		if((x & (1 << i)) && !(y & (1 << i))){
			return i + 1;
		}
	}
	
	return 0;
}
int decode(int n, int q, int h)
{
	int C[15][15];
	int i, j, a, b, s;
	
	C[0][0] = 1;
	
	for(i=1; i<=12; i++){
		C[i][0] = 1;
		for(j=1; j<=i; j++){
			C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
		}
	}
	
	a = 6, b = 6;
	
	for(i=0, s=0; i<12; i++){
		if(a == 0) b --, s = s << 1 | 1;
		else if(b == 0) a --, s = s << 1;
		else if(q <= C[a + b - 1][a - 1]) a --, s <<= 1;
		else q -= C[a + b - 1][a - 1], b --, s = s << 1 | 1;
	}
	
	return s & (1 << h - 1)? 1 : 0;
}

Compilation message

decoder.cpp: In function 'int decode(int, int, int)':
decoder.cpp:24:21: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
  return s & (1 << h - 1)? 1 : 0;
                   ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 2142 ms 80424 KB Output is correct - maxh = 12
2 Correct 2115 ms 80360 KB Output is correct - maxh = 12