제출 #837162

#제출 시각아이디문제언어결과실행 시간메모리
837162pavement앵무새 (IOI11_parrots)C++17
0 / 100
2057 ms12008 KiB
#include "encoder.h" #include "encoderlib.h" #include <bitset> #include <cassert> #include <iostream> #include <array> using namespace std; const int LEN = 514, LIM = 517, K = 261; static bitset<LEN> operator+ (const bitset<LEN> &lhs, const bitset<LEN> &rhs) { bitset<LEN> res; res.reset(); bool carry = 0; for (int i = 0; i < LEN; i++) { res[i] = carry ^ lhs[i] ^ rhs[i]; if ((carry && lhs[i]) || (carry && rhs[i]) || (lhs[i] && rhs[i])) { carry = 1; } else { carry = 0; } } assert(carry == 0); return res; } static bool fullSubtractor(bool b1, bool b2, bool& borrow) { bool diff; if (borrow) { diff = !(b1 ^ b2); borrow = !b1 || (b1 && b2); } else { diff = b1 ^ b2; borrow = !b1 && b2; } return diff; } static bitset<LEN> operator- (const bitset<LEN> &lhs, const bitset<LEN> &rhs) { bool borrow = 0; bitset<LEN> ans; for (int i = 0; i < LEN; i++) { ans[i] = fullSubtractor(lhs[i], rhs[i], borrow); } return ans; } static bitset<LEN> nck[LIM][LIM]; static void precompute_binomials() { for (int i = 0; i < LIM; i++) { for (int j = 0; j <= i; j++) { if (i == 0 || j == 0) { nck[i][j] = j == 0; } else { nck[i][j] = nck[i - 1][j] + nck[i - 1][j - 1]; } } } } void encode(int N, int M[]) { precompute_binomials(); bitset<LEN> cur; cur.reset(); for (int i = 0; i < N; i++) { for (int j = 0; j < 8; j++) { cur[i * 8 + j] = !!(M[i] & (1 << j)); } } for (int i = 0, val = 0; i < K; i++) { while (1) { int len_left = K - 1 - i; int vals_left = 256 - val; if (nck[len_left + vals_left][vals_left].to_string() <= cur.to_string()) { cur = cur - nck[len_left + vals_left][vals_left]; val++; } else { break; } } send(val); } }
#include "decoder.h" #include "decoderlib.h" #include <bitset> #include <cassert> #include <iostream> #include <algorithm> #include <array> using namespace std; int A[105]; const int LEN = 514, LIM = 517, K = 261; static bitset<LEN> operator+ (const bitset<LEN> &lhs, const bitset<LEN> &rhs) { bitset<LEN> res; res.reset(); bool carry = 0; for (int i = 0; i < LEN; i++) { res[i] = carry ^ lhs[i] ^ rhs[i]; if ((carry && lhs[i]) || (carry && rhs[i]) || (lhs[i] && rhs[i])) { carry = 1; } else { carry = 0; } } assert(carry == 0); return res; } static bool fullSubtractor(bool b1, bool b2, bool& borrow) { bool diff; if (borrow) { diff = !(b1 ^ b2); borrow = !b1 || (b1 && b2); } else { diff = b1 ^ b2; borrow = !b1 && b2; } return diff; } static bitset<LEN> operator- (const bitset<LEN> &lhs, const bitset<LEN> &rhs) { bool borrow = 0; bitset<LEN> ans; for (int i = 0; i < LEN; i++) { ans[i] = fullSubtractor(lhs[i], rhs[i], borrow); } return ans; } static bitset<LEN> nck[LIM][LIM]; static void precompute_binomials() { for (int i = 0; i < LIM; i++) { for (int j = 0; j <= i; j++) { if (i == 0 || j == 0) { nck[i][j] = j == 0; } else { nck[i][j] = nck[i - 1][j] + nck[i - 1][j - 1]; } } } } void decode(int N, int L, int X[]) { precompute_binomials(); sort(X, X + L); bitset<LEN> num(0); for (int i = 0; i < L; i++) { int len_left = L - i - 1; for (int val = i ? X[i - 1] : 0; val < X[i]; val++) { int val_left = 256 - val; num = num + nck[len_left + val_left][val_left]; } } for (int i = 0; i < N; i++) { for (int j = 0; j < 8; j++) { if (num[i * 8 + j]) { A[i] |= (1 << j); } } output(A[i]); } }

컴파일 시 표준 에러 (stderr) 메시지

decoder.cpp:43:20: warning: 'std::bitset<514> operator-(const std::bitset<514>&, const std::bitset<514>&)' defined but not used [-Wunused-function]
   43 | static bitset<LEN> operator- (const bitset<LEN> &lhs, const bitset<LEN> &rhs) {
      |                    ^~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...