QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#559787 | #9237. Message | alexz1205 | 95.5 | 218ms | 4108kb | C++17 | 5.1kb | 2024-09-12 09:21:47 | 2024-09-12 09:21:47 |
Judging History
answer
#include <bits/stdc++.h>
#include "message.h"
using namespace std;
int arr[31];
const int LIM = 68;
namespace help{
int message[31][LIM];
}
void send_message(std::vector<bool> M, std::vector<bool> C) {
int p = -1;
int f = -1;
memset(arr, 0, sizeof(int) * 31);
memset(help::message, -1, sizeof(int) * 31*LIM);
for (int x = 0; x < 31; x ++){
if (!C[x]){
if (f == -1){
p = x;
f = x;
}else {
arr[p] = x-p;
p = x;
}
}
}
arr[p] = 31+f - p;
/*
for (int x = 0; x < 31; x ++){
printf("%2d ", arr[x]);
}
cout << endl;
*/
int c = 0;
for (int x = 0; x < 31; x ++){
if (!C[x]){
/*
if (arr[x] <= 1){
help::message[x][0] = 0;
//help::message[x][1] = arr[x]-1;
c ++;
c ++;
continue;
}
int ind = 0;
help::message[x][ind++] = 1;
c ++;
arr[x] -= 2;
// do elias omega coding
std::vector<int> res;
res.push_back(0);
int v = arr[x];
while (v != 1){
res.push_back(v);
v = 31-__builtin_clz(v);
}
reverse(res.begin(), res.end());
for (int v: res){
if (v == 0){
help::message[x][ind++] = 0;
c ++;
}else {
for (int i = 31-__builtin_clz(v); i >= 0; i --){
help::message[x][ind++] = (v & (1 << i)) > 0;
c ++;
}
}
}
*/
for (int i = 0; i < arr[x]-1; i ++){
help::message[x][i] = 0;
}
help::message[x][arr[x]-1] = 1;
}
}
/*
char buff[60];
sprintf(buff, "COUNT: %d SIZE %d\n", c, (int)M.size());
perror(buff);
*/
std::vector<std::array<int, 2>> sizeW;
int ind = 0;
int pack = 0;
for (int y = 0; y < LIM; y ++){
for (int x = 0; x < 31; x ++){
if (C[x]) continue;
if (help::message[x][y] != -1){
pack = y;
continue;
}
if (sizeW.size() < 10){
sizeW.push_back({x, y});
help::message[x][y] = -2;
}else if (ind < (int)M.size()){
help::message[x][y] = M[ind++];
pack = y;
}
}
}
pack ++;
/*
for (int y = 0; y < LIM; y ++){
for (int x = 0; x < 31; x ++){
printf("%2d ", help::message[x][y]);
}
cout << endl;
}
*/
assert(ind == (int)M.size());
for (int x = 0; x < 10; x ++){
help::message[sizeW[x][0]][sizeW[x][1]] = (bool)((M.size()-1) & (1 << x));
}
for (int y = 0; y < pack; y ++){
std::vector<bool> res;
for (int x = 0; x < 31; x ++){
res.push_back((bool)help::message[x][y]);
}
send_packet(res);
}
}
int decodeElias(int i, int s){
if (help::message[i][0] == 0){
return help::message[i][1]+1;
}
int ind = 1;
int N = 1;
while (help::message[i][ind] != 0){
int v = 0;
for (int x = 0; x <= N; x ++){
int val = help::message[i][ind];
help::message[i][ind ++] = -2;
if (ind >= 12 || ind >= s){
return 0;
}
v <<= 1;
v += val;
//v += val << x;
}
N = v;
}
help::message[i][ind ++] = -2;
return N+2;
}
namespace check{
int good[31];
int time[31];
void dfs(int i, int t = 1){
if (good[i] != 0){
return;
}
if (time[i] != 0){
if (t - time[i] == 16){
good[i] = 1;
dfs((arr[i] + i) % 31, t+1);
return;
}else {
good[i] = -1;
return;
}
}
time[i] = t;
dfs((arr[i] + i) % 31, t+1);
if (good[i] == 0){
good[i] = -1;
}
}
}
std::vector<bool> receive_message(std::vector<std::vector<bool>> R) {
memset(arr, 0, sizeof(int) * 31);
memset(check::good, 0, sizeof(int) * 31);
memset(help::message, -1, sizeof(int) * 31*LIM);
memset(check::time, 0, sizeof(int) * 31);
for (int y = 0; y < (int)R.size(); y ++){
for (int x = 0; x < 31; x ++){
help::message[x][y] = R[y][x];
}
}
/*
for (int y = 0; y < (int)R.size(); y ++){
for (int x = 0; x < 31; x ++){
printf("%2d ", help::message[x][y]);
}
cout << endl;
}
cout << endl;
*/
for (int x = 0; x < 31; x ++){
//arr[x] = decodeElias(x, R.size());
for (int y = 0; y < R.size(); y ++){
arr[x] ++;
if (help::message[x][y] == 1){
help::message[x][y] = -2;
break;
}
help::message[x][y] = -2;
}
}
/*
for (int x = 0; x < 31; x ++){
printf("%2d ", arr[x]);
}
cout << endl;
cout << endl;
*/
/*
for (int y = 0; y < (int)R.size(); y ++){
for (int x = 0; x < 31; x ++){
printf("%2d ", help::message[x][y]);
}
cout << endl;
}
*/
for (int x = 0; x < 31; x ++){
if (check::good[x] != 0){
continue;
}
check::dfs(x);
}
/*
for (int x = 0; x < 31; x ++){
printf("%2d ", (check::good[x] > 0));
}
cout << endl;
*/
int totLen = 0;
int i = 0;
std::vector<bool> res;
for (int y = 0; y < (int)R.size(); y ++){
for (int x = 0; x < 31; x ++){
if (check::good[x] == 1){
if (help::message[x][y] == -2){
continue;
}
if (i < 10){
totLen += (int)help::message[x][y] << (i ++);
/*
cout << x << " " << y << " ";
cout << help::message[x][y];
cout << endl;
*/
}else {
if (res.empty()){
totLen ++;
}
if ((int)res.size() < totLen){
res.push_back(help::message[x][y]);
}
}
}
}
}
/*
cout << endl;
cout << totLen << endl;
*/
return res;
}
详细
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 24ms
memory: 3824kb
Manager to Aisha
Aisha to Manager
Manager to Basma
Basma to Manager
Manager to Checker
1
result:
points 1.0
Test #2:
score: 10
Accepted
time: 13ms
memory: 3996kb
Manager to Aisha
Aisha to Manager
Manager to Basma
Basma to Manager
Manager to Checker
1
result:
points 1.0
Test #3:
score: 10
Accepted
time: 25ms
memory: 3992kb
Manager to Aisha
Aisha to Manager
Manager to Basma
Basma to Manager
Manager to Checker
1
result:
points 1.0
Test #4:
score: 10
Accepted
time: 30ms
memory: 3992kb
Manager to Aisha
Aisha to Manager
Manager to Basma
Basma to Manager
Manager to Checker
1
result:
points 1.0
Test #5:
score: 10
Accepted
time: 24ms
memory: 4028kb
Manager to Aisha
Aisha to Manager
Manager to Basma
Basma to Manager
Manager to Checker
1
result:
points 1.0
Test #6:
score: 10
Accepted
time: 30ms
memory: 3740kb
Manager to Aisha
Aisha to Manager
Manager to Basma
Basma to Manager
Manager to Checker
1
result:
points 1.0
Test #7:
score: 10
Accepted
time: 24ms
memory: 4024kb
Manager to Aisha
Aisha to Manager
Manager to Basma
Basma to Manager
Manager to Checker
1
result:
points 1.0
Subtask #2:
score: 85.5
Acceptable Answer
Test #8:
score: 85.5
Acceptable Answer
time: 183ms
memory: 3824kb
Manager to Aisha
Aisha to Manager
Manager to Basma
Basma to Manager
Manager to Checker
0.9500
result:
points 0.95
Test #9:
score: 90
Accepted
time: 110ms
memory: 3844kb
Manager to Aisha
Aisha to Manager
Manager to Basma
Basma to Manager
Manager to Checker
1
result:
points 1.0
Test #10:
score: 85.5
Acceptable Answer
time: 193ms
memory: 3820kb
Manager to Aisha
Aisha to Manager
Manager to Basma
Basma to Manager
Manager to Checker
0.9500
result:
points 0.95
Test #11:
score: 85.5
Acceptable Answer
time: 200ms
memory: 3996kb
Manager to Aisha
Aisha to Manager
Manager to Basma
Basma to Manager
Manager to Checker
0.9500
result:
points 0.95
Test #12:
score: 90
Accepted
time: 203ms
memory: 4020kb
Manager to Aisha
Aisha to Manager
Manager to Basma
Basma to Manager
Manager to Checker
1
result:
points 1.0
Test #13:
score: 85.5
Acceptable Answer
time: 112ms
memory: 3808kb
Manager to Aisha
Aisha to Manager
Manager to Basma
Basma to Manager
Manager to Checker
0.9500
result:
points 0.95
Test #14:
score: 85.5
Acceptable Answer
time: 116ms
memory: 3992kb
Manager to Aisha
Aisha to Manager
Manager to Basma
Basma to Manager
Manager to Checker
0.9500
result:
points 0.95
Test #15:
score: 85.5
Acceptable Answer
time: 135ms
memory: 3764kb
Manager to Aisha
Aisha to Manager
Manager to Basma
Basma to Manager
Manager to Checker
0.9500
result:
points 0.95
Test #16:
score: 90
Accepted
time: 101ms
memory: 3748kb
Manager to Aisha
Aisha to Manager
Manager to Basma
Basma to Manager
Manager to Checker
1
result:
points 1.0
Test #17:
score: 90
Accepted
time: 32ms
memory: 3756kb
Manager to Aisha
Aisha to Manager
Manager to Basma
Basma to Manager
Manager to Checker
1
result:
points 1.0
Test #18:
score: 90
Accepted
time: 18ms
memory: 3764kb
Manager to Aisha
Aisha to Manager
Manager to Basma
Basma to Manager
Manager to Checker
1
result:
points 1.0
Test #19:
score: 90
Accepted
time: 62ms
memory: 4024kb
Manager to Aisha
Aisha to Manager
Manager to Basma
Basma to Manager
Manager to Checker
1
result:
points 1.0
Test #20:
score: 90
Accepted
time: 59ms
memory: 3752kb
Manager to Aisha
Aisha to Manager
Manager to Basma
Basma to Manager
Manager to Checker
1
result:
points 1.0
Test #21:
score: 90
Accepted
time: 109ms
memory: 3992kb
Manager to Aisha
Aisha to Manager
Manager to Basma
Basma to Manager
Manager to Checker
1
result:
points 1.0
Test #22:
score: 90
Accepted
time: 126ms
memory: 3748kb
Manager to Aisha
Aisha to Manager
Manager to Basma
Basma to Manager
Manager to Checker
1
result:
points 1.0
Test #23:
score: 90
Accepted
time: 112ms
memory: 3828kb
Manager to Aisha
Aisha to Manager
Manager to Basma
Basma to Manager
Manager to Checker
1
result:
points 1.0
Test #24:
score: 90
Accepted
time: 167ms
memory: 4108kb
Manager to Aisha
Aisha to Manager
Manager to Basma
Basma to Manager
Manager to Checker
1
result:
points 1.0
Test #25:
score: 90
Accepted
time: 141ms
memory: 3800kb
Manager to Aisha
Aisha to Manager
Manager to Basma
Basma to Manager
Manager to Checker
1
result:
points 1.0
Test #26:
score: 90
Accepted
time: 209ms
memory: 3768kb
Manager to Aisha
Aisha to Manager
Manager to Basma
Basma to Manager
Manager to Checker
1
result:
points 1.0
Test #27:
score: 85.5
Acceptable Answer
time: 218ms
memory: 3808kb
Manager to Aisha
Aisha to Manager
Manager to Basma
Basma to Manager
Manager to Checker
0.9500
result:
points 0.95