제출 #1008800

#제출 시각아이디문제언어결과실행 시간메모리
1008800biank앵무새 (IOI11_parrots)C++14
100 / 100
677 ms16468 KiB
#include "encoder.h" #include "encoderlib.h" #include <bits/stdc++.h> using namespace std; #define sz(x) int(x.size()) using ll = long long; const int BASE = 1e8; struct BigInt { vector<int> num; BigInt(int x = 0) { num = {}; while (x) { num.push_back(int(x % BASE)); x /= BASE; } } int operator[](int i) const { if (i >= sz(num)) return 0; return num[i]; } friend BigInt operator+(const BigInt &x, const BigInt &y) { BigInt z; int carry = 0; int d = max(sz(x.num), sz(y.num)); for (int i = 0; i < d; i++) { int s = x[i] + y[i] + carry; z.num.push_back(s % BASE); carry = s / BASE; } while (carry) { z.num.push_back(carry % BASE); carry /= BASE; } return z; } friend BigInt operator-(BigInt x, BigInt y) {//x >= y BigInt z; int carry = 0; int d = max(sz(x.num), sz(y.num)); for (int i = 0; i < d; i++) { int s = x[i] - y[i] - carry; if (s < 0) s += BASE, carry = 1; else carry = 0; z.num.push_back(s); } while (sz(z.num) > 1 && z.num.back() == 0) z.num.pop_back(); return z; } friend bool operator<(const BigInt &x, const BigInt &y) { int d = max(sz(x.num), sz(y.num)); for (int i = d - 1; i >= 0; i--) { if (x[i] ^ y[i]) return x[i] < y[i]; } return false; } friend bool operator>=(const BigInt x, const BigInt y) { return !(x < y); } BigInt &operator+=(const BigInt &o) { return *this = *this + o; } BigInt &operator-=(const BigInt &o) { return *this = *this - o; } BigInt operator*(int y) { BigInt z; ll carry = 0; for (int i = 0; i < sz(num); i++) { ll m = 1LL * num[i] * y + carry; z.num.push_back(m % BASE); carry = m / BASE; } while (carry) { z.num.push_back(carry % BASE); carry /= BASE; } return z; } }; BigInt dp[320][255]; bool flag = false; void calcDP() { for (int i = 0; i < 255; i++) { dp[0][i] = 1; } for (int i = 1; i < 320; i++) { dp[i][0] = dp[i - 1][0]; for (int j = 1; j < 255; j++) { dp[i][j] = dp[i - 1][j] + dp[i][j - 1]; } } flag = true; } void encode(int N, int M[]) { if (!flag) calcDP(); BigInt pos = 0; for (int i = 0; i < N; i++) { pos = pos * 256 + M[i]; } pos += 1; for (int i = 5 * N - 1; i >= 0; i--) { int j = 0; while (pos >= dp[i][j]) { pos -= dp[i][j]; j++; } send(j); } }
#include "decoder.h" #include "decoderlib.h" #include <bits/stdc++.h> using namespace std; #define all(x) begin(x), end(x) #define sz(x) int(x.size()) using ll = long long; const int BASE2 = 1e8; struct BigInt2 { vector<int> num; BigInt2(int x = 0) { num = {}; while (x) { num.push_back(int(x % BASE2)); x /= BASE2; } } int operator[](int i) const { if (i >= sz(num)) return 0; return num[i]; } friend BigInt2 operator+(const BigInt2 &x, const BigInt2 &y) { BigInt2 z; int carry = 0; int d = max(sz(x.num), sz(y.num)); for (int i = 0; i < d; i++) { int s = x[i] + y[i] + carry; z.num.push_back(s % BASE2); carry = s / BASE2; } while (carry) { z.num.push_back(carry % BASE2); carry /= BASE2; } return z; } friend BigInt2 operator-(BigInt2 x, BigInt2 y) {//x >= y BigInt2 z; int d = max(sz(x.num), sz(y.num)); int carry = 0; for (int i = 0; i < d; i++) { int s = x[i] - y[i] - carry; if (s < 0) s += BASE2, carry = 1; else carry = 0; z.num.push_back(s); } while (sz(z.num) > 1 && z.num.back() == 0) z.num.pop_back(); return z; } friend bool operator<(const BigInt2 &x, const BigInt2 &y) { int d = max(sz(x.num), sz(y.num)); for (int i = d - 1; i >= 0; i--) { if (x[i] ^ y[i]) return x[i] < y[i]; } return false; } friend bool operator>=(const BigInt2 &x, const BigInt2 &y) { return !(x < y); } BigInt2 &operator+=(BigInt2 o) { return *this = *this + o; } BigInt2 &operator-=(BigInt2 o) { return *this = *this - o; } pair<BigInt2, int> operator/(int k) { BigInt2 z; int carry = 0; for (int i = sz(num) - 1; i >= 0; i--) { ll m = 1LL * carry * BASE2 + num[i]; if (m / k || !z.num.empty()) z.num.push_back(m / k); carry = m % k; } reverse(all(z.num)); return {z, carry}; } }; BigInt2 dp2[320][255]; bool flag2 = false; void calcdp22() { for (int i = 0; i < 255; i++) { dp2[0][i] = 1; } for (int i = 1; i < 320; i++) { dp2[i][0] = dp2[i - 1][0]; for (int j = 1; j < 255; j++) { dp2[i][j] = dp2[i - 1][j] + dp2[i][j - 1]; } } flag2 = true; } void decode(int N, int L, int X[]) { if (!flag2) calcdp22(); sort(X, X + L); BigInt2 pos = 0; for (int i = L - 1; i >= 0; i--) { for (int j = 0; j < X[i]; j++) pos += dp2[i][j]; } pos -= 1; vector<int> res; for (int i = 0; i < N; i++) { int x; tie(pos, x) = pos / 256; res.push_back(x); } for (int i = N - 1; i >= 0; i--) { output(res[i]); } }
#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...