QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#296755 | #4826. Find the Parts | defyers# | 0 | 1ms | 7888kb | C++17 | 5.3kb | 2024-01-03 15:24:34 | 2024-01-03 15:24:34 |
answer
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using LL = long long;
int r, c;
string s;
int a[2005][2005];
vector<int> ans;
int h[2005][2005];
pair<int, int> p[2005][2005];
int qa[55][55];
unordered_map<LL, pair<int, int>> M;
int sw(char c) {
if (c >= '0' && c <= '9') {
return c - '0';
}
return c - 'A' + 10;
}
int H(int r1, int c1, int r2, int c2) {
return qa[r2][c2] ^ qa[r1 - 1][c2] ^ qa[r2][c1 - 1] ^ qa[r1 - 1][c1 - 1];
}
int tonum(string s) {
int a0 = sw(s[0]);
int a1 = sw(s[1]);
return a0 * 16 + a1;
}
string st(int x) {
string s;
if (x > 9) s += (x - 10 + 'A');
else s += (x + '0');
return s;
}
string tostring(int num) {
int a0 = num / 16;
int a1 = num % 16;
return st(a0) + st(a1);
}
void encode() {
//cout << tostring(255) << endl;
cin >> r >> c;
ans.push_back(r / 256);
ans.push_back(r % 256);
ans.push_back(c / 256);
ans.push_back(c % 256);
for (int i = 1; i <= r; i++) {
for (int j = 1; j <= c; j++) {
cin >> s;
int num = tonum(s);
a[i][j] = num;
}
}
int ilen = 3;
for (int i = 1; i + ilen - 1 <= r; ) {
int jlen = 3;
for (int j = 1; j + jlen - 1 <= c; ) {
int x = 0;
for (int ii = i; ii < i + ilen; ii++) {
for (int jj = j; jj < j + jlen; jj++) {
x ^= a[ii][jj];
}
}
ans.push_back(x);
j += jlen;
jlen = 7 - jlen;
}
i += ilen;
ilen = 7 - ilen;
}
cout << (int)ans.size() << "\n";
for (int i = 0; i < ans.size(); i++) {
cout << tostring(ans[i]);
cout << " \n"[i == ans.size() - 1];
}
}
void decode() {
int n;
cin >> n;
string s1, s2, s3, s4;
cin >> s1 >> s2 >> s3 >> s4;
int a1 = tonum(s1), a2 = tonum(s2), a3 = tonum(s3), a4 = tonum(s4);
r = a1 * 256 + a2;
c = a3 * 256 + a4;
//cout << "r and c : " << r << " " << c << endl;
int i = 1, j = 1, ilen = 3, jlen = 3;
int hi = 1, hj = 1;
for (int t = 5; t <= n; t++) {
string s;
cin >> s;
if (j + jlen - 1 > c) {
i += ilen;
j = 1;
hi++;
hj = 1;
ilen = 7 - ilen;
jlen = 3;
}
h[hi][hj] = tonum(s);
p[hi][hj] = {i, j};
hj++;
j += jlen;
jlen = 7 - jlen;
}
//cout << "hashed array size: " << hi << " " << hj << endl;
for (int i = 1; i < hi; i++) {
for (int j = 1; j < hj; j++) {
ll num = h[i][j];
num = num * 256 + h[i][j + 1];
num = num * 256 + h[i + 1][j];
num = num * 256 + h[i + 1][j + 1];
M[num] = p[i][j];
}
}
int q;
cin >> q;
for (int qi = 1; qi <= q; qi++) {
int qr, qc;
cin >> qr >> qc;
for (int j = 1; j <= qr; j++) {
for (int k = 1; k <= qc; k++) {
string tmp;
cin >> tmp;
int num = tonum(tmp);
qa[j][k] = num;
}
}
for (int i = 1; i <= qr; i++) {
for (int j = 1; j <= qc; j++) {
qa[i][j] = qa[i][j] ^ qa[i][j - 1] ^ qa[i - 1][j] ^ qa[i - 1][j - 1];
}
}
pair<int, int> position;
for (int i = 1; i <= 4; i++) {
for (int j = 1; j <= 4; j++) {
LL num = H(i, j, i + 2, j + 2);
num = num * 256 + H(i, j + 3, i + 2, j + 6);
num = num * 256 + H(i + 3, j, i + 6, j + 2);
num = num * 256 + H(i + 3, j + 3, i + 6, j + 6);
if (M.find(num) != M.end()) {
auto pr = M[num];
position.first = pr.first - i + 1;
position.second = pr.second - j + 1;
}
}
}
for (int i = 1; i <= 4; i++) {
for (int j = 1; j <= 4; j++) {
LL num = H(i, j, i + 2, j + 3);
num = num * 256 + H(i, j + 4, i + 2, j + 6);
num = num * 256 + H(i + 3, j, i + 6, j + 3);
num = num * 256 + H(i + 3, j + 4, i + 6, j + 6);
if (0 && i == 1 && j == 3) {
cout << "to get " << H(i, j, i + 2, j + 3) << ", from:\n";
for (int ii = i; ii <= i + 2; ii++) {
for (int jj = j; jj <= j + 3; jj++) {
cout << (qa[ii][jj] ^ qa[ii - 1][jj] ^ qa[ii][jj - 1] ^ qa[ii - 1][jj - 1]) << " ";
}
cout << endl;
}
cout << H(i, j, i + 2, j + 3) << " ";
cout << H(i, j + 4, i + 2, j + 6) << endl;
cout << H(i + 3, j, i + 6, j + 3) << " ";
cout << H(i + 3, j + 4, i + 6, j + 6) << endl;
}
if (M.find(num) != M.end()) {
auto pr = M[num];
position.first = pr.first - i + 1;
position.second = pr.second - j + 1;
}
}
}
for (int i = 1; i <= 4; i++) {
for (int j = 1; j <= 4; j++) {
LL num = H(i, j, i + 3, j + 2);
num = num * 256 + H(i, j + 3, i + 3, j + 6);
num = num * 256 + H(i + 4, j, i + 6, j + 2);
num = num * 256 + H(i + 4, j + 3, i + 6, j + 6);
if (M.find(num) != M.end()) {
auto pr = M[num];
position.first = pr.first - i + 1;
position.second = pr.second - j + 1;
}
}
}
for (int i = 1; i <= 4; i++) {
for (int j = 1; j <= 4; j++) {
LL num = H(i, j, i + 3, j + 3);
num = num * 256 + H(i, j + 4, i + 3, j + 6);
num = num * 256 + H(i + 4, j, i + 6, j + 3);
num = num * 256 + H(i + 4, j + 3, i + 6, j + 6);
if (M.find(num) != M.end()) {
auto pr = M[num];
position.first = pr.first - i + 1;
position.second = pr.second - j + 1;
}
}
}
cout << position.first << " " << position.second << "\n";
}
}
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
cout << fixed << setprecision(10);
string s;
cin >> s;
if (s[0] == 'm') {
encode();
}
else {
decode();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7676kb
input:
message 20 24 33 39 73 4A 5A AA E0 86 96 4B 0B 83 A0 FA 82 9B B0 6E DC 03 1C B9 5B 81 86 3E 23 7B C9 38 77 82 7D 62 EA CE A8 DE 85 6C 36 B3 10 EE 85 6A D5 92 14 BD 58 74 20 7B 36 E1 89 B8 6F 4A F4 8F 17 2E 2F 0F 79 DD AA 9F 6F AD 85 21 B6 2F 58 37 87 7B 3F EE D9 7D 9A E6 AA 12 E0 B6 BB 3D 72 BD 34 A...
output:
39 00 14 00 18 13 BE 16 DE 60 64 13 0C 1F 8D 3C 41 01 29 99 7F 33 21 BB 2F B7 52 3A 23 F5 72 90 B8 AA 5E 7B 9A 24 55 EC
input:
parts 39 00 14 00 18 13 BE 16 DE 60 64 13 0C 1F 8D 3C 41 01 29 99 7F 33 21 BB 2F B7 52 3A 23 F5 72 90 B8 AA 5E 7B 9A 24 55 EC 2 10 10 39 73 4A 5A AA E0 86 96 4B 0B 3E 23 7B C9 38 77 82 7D 62 EA BD 58 74 20 7B 36 E1 89 B8 6F 21 B6 2F 58 37 87 7B 3F EE D9 8A 73 EE 69 BF E0 0D 5C 57 EF F7 4F A7 18 4D 7...
output:
1 2 6 5
result:
ok correct answer
Test #2:
score: 100
Accepted
time: 1ms
memory: 7840kb
input:
message 20 20 85 C4 91 58 77 23 A9 E5 44 8E 28 DC A2 51 13 AE 4E 3C 21 62 37 5A 41 45 8F CA C3 89 01 68 11 72 D8 75 72 ED EE 64 FA B0 05 45 6E F2 FD CE 9A AC 31 CA 88 83 34 D6 23 1F 8C 6D 9E 8C 42 40 7E 18 4C D1 D3 F2 02 20 51 20 14 0F 3D 27 0E 03 73 D7 C0 1F C3 1D D3 55 D9 AF 6E 76 77 28 24 1A 97 E...
output:
29 00 14 00 14 D2 3D 98 20 32 43 8C DA B7 5E B5 69 56 66 74 9B 14 DE 9E 0D 63 66 7A 07 8F
input:
parts 29 00 14 00 14 D2 3D 98 20 32 43 8C DA B7 5E B5 69 56 66 74 9B 14 DE 9E 0D 63 66 7A 07 8F 1 10 10 D0 0A D3 6D B9 31 31 76 54 15 CE 14 02 1A A2 8C 77 EB 8E 02 06 44 E4 F4 22 DB 66 F8 7E 38 C6 6A B7 5F E1 A0 0D F0 F5 8A AC DB B0 FB 26 E6 12 36 37 F1 6C AB B1 4C C0 11 B6 DE 71 C2 09 54 23 45 56 1...
output:
6 6
result:
ok correct answer
Test #3:
score: 0
Wrong Answer
time: 1ms
memory: 7888kb
input:
message 20 20 12 4F 58 0D 8B AB 72 D1 55 0F FC 74 28 E3 B0 02 9E FA 18 C0 82 72 32 EB 29 EF 9D 70 E6 2D AC 15 37 31 40 A4 36 B6 58 2C 4E C2 4D AC C5 0F D1 A8 B2 2D 43 ED 00 63 7C 3B 3E C5 94 49 92 7D 2C 69 2B 6A 15 95 7C FD 67 E4 AC EE 01 F8 78 5F 46 57 54 7D 03 92 36 85 D0 C0 B1 14 22 70 9D 06 4E C...
output:
29 00 14 00 14 06 58 07 31 87 A6 CE 11 3A 49 48 E6 79 9C B6 CB 44 C1 36 BF A1 8A 0C 04 84
input:
parts 29 00 14 00 14 06 58 07 31 87 A6 CE 11 3A 49 48 E6 79 9C B6 CB 44 C1 36 BF A1 8A 0C 04 84 9 10 10 12 4F 58 0D 8B AB 72 D1 55 0F 82 72 32 EB 29 EF 9D 70 E6 2D 4E C2 4D AC C5 0F D1 A8 B2 2D 92 7D 2C 69 2B 6A 15 95 7C FD 54 7D 03 92 36 85 D0 C0 B1 14 A7 42 36 1E F1 E2 B4 20 D7 FE 8D 5E 4F 0C 4E B...
output:
1 1 0 0 1 11 11 1 1 1 11 1 1 1 1 11 1 1
result:
wrong answer wrong answer on query 2: read (0, 0) but expected (11, 11)