QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#119603 | #6669. Mapa | hos_lyric# | 0 | 2ms | 4100kb | C++14 | 5.2kb | 2023-07-05 12:48:20 | 2024-07-04 00:18:05 |
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; }
int mix(int x) {
x = (20230705LL * x) % 1'000'000'403;
return x;
}
constexpr int E = 30;
constexpr int F = 10;
constexpr int G = 8;
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) {
string S;
int P;
vector<int> H(N);
for (int a = 0; a < 1 << G; ++a) {
P = (1 << F) - 1 - a;
for (int i = 0; i < N; ++i) {
H[i] = mix(X[i]) % P;
}
if ((int)set<int>(H.begin(), H.end()).size() == N) {
cerr<<"perfect a = "<<a<<", P = "<<P<<endl;
S += toBinary(G, a);
goto foundPerfect;
}
}
assert(false);
foundPerfect:{}
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;
S += toBinary(G, 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;
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 P, M;
map<int, int> mapa, nazo;
{
int cur = 0;
P = (1 << F) - 1 - fromBinary(S.substr(cur, G)); cur += G;
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 = mix(Z[q]) % P;
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;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 89.6
Acceptable Answer
time: 2ms = 2ms + 0ms
memory: 3820kb,3808kb
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:
3312 0111010001011000001011000000010010001011011101001110111001011101011101001001000100110110111001111010110111100101001100001000001100001001000000000101110011000111100100101100011101001101001011011001110000001010000101011011000001011010110100101100011000001000001010110001111101101001100111000111101...
input:
2 100 79 3312 0111010001011000001011000000010010001011011101001110111001011101011101001001000100110110111001111010110111100101001100001000001100001001000000000101110011000111100100101100011101001101001011011001110000001010000101011011000001011010110100101100011000001000001010110001111101101001100111...
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.8960 ok K = 3312
Test #2:
score: 89.5667
Acceptable Answer
time: 0ms = 0ms + 0ms
memory: 4080kb,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:
3313 0100110011101010001010111111011111010110000010011111100000001100101011111000101001100010111111010010101011110010000110011111101100110111001001001000010110000001100010100110010101100000010111110000100010111110010001010101000111001011010001000011010010111100111101100011011010111100000110011011001...
input:
2 100 79 3313 0100110011101010001010111111011111010110000010011111100000001100101011111000101001100010111111010010101011110010000110011111101100110111001001001000010110000001100010100110010101100000010111110000100010111110010001010101000111001011010001000011010010111100111101100011011010111100000110...
output:
442563406 97578442 469403815 293708068 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:
points 0.89566666670 ok K = 3313
Test #3:
score: 0
Runtime Error
input:
1 100 770174568 168127255 893508708 185778664 976425263 477317099 287595878 512153851 621600374 418802856 818787535 612197605 796811122 566496677 789841517 873731343 43178468 619503942 597852289 471053284 66112404 635260765 158101403 199253397 680158192 123081916 626776438 29107026 721141470 5177084...