답안 #773421

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
773421 2023-07-05T04:49:30 Z rxlfd314 앵무새 (IOI11_parrots) C++17
81 / 100
3 ms 1116 KB
#include <bits/stdc++.h>
#include "encoder.h"
#include "encoderlib.h"
using namespace std;

static const vector<int> b[4] = {{2, 3, 3}, {1, 2, 3, 2}, {1, 1, 2, 2, 2}, {2, 2, 1, 1, 1, 1}};
static bool check(int u, vector<int> v) {
	bool ret = true;
	for (int i = 0, bsz = 0, prv = 0; i < v.size() && ret; i++) {
		bsz += v[i];
		int x = u >> 8 - bsz;
		x -= x >> v[i] << v[i];
		ret &= (v[i] == 1 ? 6|x : v[i] == 2 ? 4|x : x) >= prv;
		prv = x >= prv ? x : (4|x) >= prv ? 4|x : 6|x;
	}
	return ret;
}

void encode(int N, int *M) {
	for (int i = 0; i < N; i++) {
		vector<int> v;
		for (int j = 0; j < 4; j++) {
			if (check(M[i], b[j])) {
				v = b[j];
				break;
			}
		}
		for (int j = 0, bsz = 0, prv = 0; j < v.size(); j++) {
			bsz += v[j];
			int x = M[i] >> 8 - bsz;
			x -= x >> v[j] << v[j];
			prv = x >= prv ? x : (4|x) >= prv ? 4|x : 6|x;
			send(i << 3 | prv);
		}
	}
}
#include <bits/stdc++.h>
#include "decoder.h"
#include "decoderlib.h"
using namespace std;

static const vector<int> b[4] = {{2, 3, 3}, {1, 2, 3, 2}, {1, 1, 2, 2, 2}, {2, 2, 1, 1, 1, 1}};

void decode(int N, int L, int *X) {
	sort(X, X+L);
	for (int l = 0, r = 0; l < L && r < L; ) {
		for (; r < L && (X[r] >> 3) == (X[l] >> 3); r++);
		int v = 0;
		for (int i = l; i < r; i++) {
			v = v << b[r-l-3][i-l] | X[i] - (X[i] >> b[r-l-3][i-l] << b[r-l-3][i-l]);
		}
		output(v);
		l = r;
	}
}

Compilation message

encoder.cpp: In function 'bool check(int, std::vector<int>)':
encoder.cpp:9:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 |  for (int i = 0, bsz = 0, prv = 0; i < v.size() && ret; i++) {
      |                                    ~~^~~~~~~~~~
encoder.cpp:11:18: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
   11 |   int x = u >> 8 - bsz;
      |                ~~^~~~~
encoder.cpp: In function 'void encode(int, int*)':
encoder.cpp:28:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |   for (int j = 0, bsz = 0, prv = 0; j < v.size(); j++) {
      |                                     ~~^~~~~~~~~~
encoder.cpp:30:22: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
   30 |    int x = M[i] >> 8 - bsz;
      |                    ~~^~~~~

decoder.cpp: In function 'void decode(int, int, int*)':
decoder.cpp:14:34: warning: suggest parentheses around arithmetic in operand of '|' [-Wparentheses]
   14 |    v = v << b[r-l-3][i-l] | X[i] - (X[i] >> b[r-l-3][i-l] << b[r-l-3][i-l]);
      |                             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1032 KB Output is correct
2 Correct 1 ms 1048 KB Output is correct
3 Correct 2 ms 1036 KB Output is correct
4 Correct 2 ms 1048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1036 KB Output is correct
2 Correct 1 ms 1036 KB Output is correct
3 Correct 2 ms 1048 KB Output is correct
4 Correct 2 ms 1116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1040 KB Output is correct
2 Correct 2 ms 1048 KB Output is correct
3 Correct 3 ms 1048 KB Output is correct
4 Correct 3 ms 1056 KB Output is correct
5 Correct 3 ms 1064 KB Output is correct
6 Correct 3 ms 1056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1040 KB Output is correct - P = 4.625000
2 Correct 3 ms 1056 KB Output is correct - P = 4.468750
3 Incorrect 1 ms 528 KB Error : Bad encoded integer
4 Incorrect 1 ms 652 KB Error : Bad encoded integer
5 Incorrect 1 ms 524 KB Error : Bad encoded integer
6 Incorrect 1 ms 532 KB Error : Bad encoded integer
7 Incorrect 1 ms 524 KB Error : Bad encoded integer