QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#119556 | #6669. Mapa | hos_lyric# | 0 | 2ms | 4100kb | C++14 | 4.8kb | 2023-07-05 12:32:03 | 2024-07-04 00:17:51 |
Judging History
answer
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
constexpr int MO = 131063;
int myhash(int x) {
x = (20230705LL * x) % 1'000'000'403;
return x % MO;
}
constexpr int E = 30;
constexpr int F = 17;
constexpr int G = 4;
constexpr int M0 = 150;
string toBinary(int len, int x) {
string s(len, '?');
for (int e = 0; e < len; ++e) s[e] = "01"[x >> e & 1];
return s;
}
int fromBinary(const string &s) {
const int len = s.size();
int x = 0;
for (int e = 0; e < len; ++e) x |= (s[e] - '0') << e;
return x;
}
string encode(int N, const vector<int> &X, const vector<int> &Y) {
vector<int> H(N);
for (int i = 0; i < N; ++i) {
H[i] = myhash(X[i]);
}
int minCost = 1001001001;
int am = -1;
for (int a = 0; a < 1 << G; ++a) {
const int M = M0 + a;
vector<int> freq(M);
for (int i = 0; i < N; ++i) {
++freq[H[i] % M];
}
int cost = M;
for (int m = 0; m < M; ++m) {
cost += F * max(freq[m] - 1, 0);
}
cerr<<"M = "<<M<<": cost = "<<cost<<endl;
if (chmin(minCost, cost)) {
am = a;
}
}
const int M = M0 + am;
vector<vector<pair<int, int>>> hiss(M);
for (int i = 0; i < N; ++i) {
hiss[H[i] % M].emplace_back(H[i], i);
}
for (int m = 0; m < M; ++m) {
auto &his = hiss[m];
sort(his.begin(), his.end());
}
// cerr<<"hiss = "<<hiss<<endl;
string S;
S += toBinary(G, am);
for (int m = 0; m < M; ++m) {
const auto &his = hiss[m];
for (const auto &hi : his) {
const int i = hi.second;
S += toBinary(E, Y[i]);
}
}
for (int m = 0; m < M; ++m) {
const auto &his = hiss[m];
S += (!his.empty()) ? '1' : '0';
}
for (int m = 0; m < M; ++m) {
const auto &his = hiss[m];
for (int j = 1; j < (int)his.size(); ++j) {
S += toBinary(F, his[j].first);
}
}
return S;
}
vector<int> decode(int N, int Q, int K, const string &S, const vector<int> &Z) {
int M;
map<int, int> mapa, nazo;
{
int cur = 0;
const int am = fromBinary(S.substr(cur, G)); cur += G;
M = M0 + am;
vector<int> Y(N);
for (int i = 0; i < N; ++i) {
Y[i] = fromBinary(S.substr(cur, E)); cur += E;
}
vector<vector<int>> hss(M);
for (int m = 0; m < M; ++m) {
const char any = S[cur++];
if (any != '0') {
hss[m].push_back(-1);
}
}
for (; cur < K; ) {
const int h = fromBinary(S.substr(cur, F)); cur += F;
hss[h % M].push_back(h);
}
// cerr<<"hss = "<<hss<<endl;
{
int i = 0;
for (int m = 0; m < M; ++m) {
for (const int h : hss[m]) {
const int y = Y[i++];
if (~h) {
mapa[h] = y;
} else {
nazo[m] = y;
}
}
}
}
assert(cur == K);
}
vector<int> ans(Q);
for (int q = 0; q < Q; ++q) {
const int h = myhash(Z[q]);
auto it = mapa.find(h);
if (it != mapa.end()) {
ans[q] = it->second;
} else {
ans[q] = nazo[h % M];
}
}
return ans;
}
int main() {
int T;
scanf("%d", &T);
if (T == 1) {
int N;
scanf("%d", &N);
vector<int> X(N), Y(N);
for (int i = 0; i < N; ++i) {
scanf("%d%d", &X[i], &Y[i]);
}
const string S = encode(N, X, Y);
const int K = S.size();
printf("%d\n", K);
puts(S.c_str());
} else {
int N, Q, K;
scanf("%d%d%d", &N, &Q, &K);
char buf[6010];
scanf("%s", buf);
const string S = buf;
vector<int> Z(Q);
for (int q = 0; q < Q; ++q) {
scanf("%d", &Z[q]);
}
const auto ans = decode(N, Q, K, S, Z);
for (int q = 0; q < Q; ++q) {
printf("%d\n", ans[q]);
}
}
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 83.4667
Acceptable Answer
time: 1ms = 1ms + 0ms
memory: 3704kb,3824kb
input:
1 100 495528311 963488152 269613430 443544124 700489871 792354118 151890319 506569919 180452297 13229948 684464994 543841485 978085128 903812192 238355172 441140842 28061035 783291471 530823766 718942732 936853023 439421263 201361623 226633955 304644844 778868118 864860135 461524170 88300500 6959354...
output:
3496 0100111001100110100101011010101010110101110100110100001111000011110010100110000101010110001010010011000111111110100001010100011101110010010111101110010001101100110011101001010110000001100101101110101100000010101101011101010000110010001101001011100100000101000011010011110011100100101111001000101...
input:
2 100 79 3496 0100111001100110100101011010101010110101110100110100001111000011110010100110000101010110001010010011000111111110100001010100011101110010010111101110010001101100110011101001010110000001100101101110101100000010101101011101010000110010001101001011100100000101000011010011110011100100101111...
output:
310305144 821194635 174780370 903812192 805026231 996046536 439421263 645287342 90686849 20101025 440972097 543841485 176553522 249563964 461524170 348624865 848301562 506569919 306718453 206848250 382805509 278712030 964702808 868944393 493895143 39665197 574757075 441140842 785665865 229376884 551...
result:
points 0.83466666670 ok K = 3496
Test #2:
score: 0
Wrong Answer
time: 2ms = 1ms + 1ms
memory: 3832kb,4100kb
input:
1 100 743248071 842720888 367650901 130970775 297946283 705168964 771526942 537186020 245003150 707948455 643491261 668001146 311535032 293708068 183828318 18515526 593973840 915870006 102456762 64193833 729806890 839221652 47145974 35682954 668676377 228428310 370700393 569441954 250911162 48980047...
output:
3475 1111011010110110110111000101101110001101010101111111110110001010100110111100100001011010001001110010101100110101000110000100111001010101100000010010010001000000111100111111111001010101001100111100011001101000111010001010001010110000110000001000011000100110000101011000100000001000110000010000111...
input:
2 100 79 3475 1111011010110110110111000101101110001101010101111111110110001010100110111100100001011010001001110010101100110101000110000100111001010101100000010010010001000000111100111111111001010101001100111100011001101000111010001010001010110000110000001000011000100110000101011000100000001000110000...
output:
442563406 97578442 469403815 695261672 138158276 720700065 839221652 674386240 810209830 563527225 259979005 668001146 813899310 943777483 569441954 226088806 825435650 537186020 131383422 83733737 830289758 425793016 858146541 609883097 414389335 407054915 47572024 18515526 276587480 810627636 4972...
result:
wrong answer wrong answer on query #4: read 695261672 but expected 293708068