QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#296729 | #4829. Mark on a Graph | defyers# | 0 | 0ms | 0kb | C++17 | 5.0kb | 2024-01-03 14:56:13 | 2024-01-03 14:56:14 |
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');
return s += (x + '0');
return s;
}
string tostring(int num) {
int a0 = num / 16;
int a1 = num % 16;
return st(a0) + st(a1);
}
void encode() {
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;
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};
j += jlen;
jlen = 7 - jlen;
}
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++) {
cout << qa[i][j] << " ";
}
cout << endl;
}
cout << endl;
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 <= 3; i++) {
for (int j = 1; j <= 3; 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 <= 3; 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 (i == 1 && j == 3) {
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 <= 3; 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: 0
Wrong Answer on the first run
input:
1000 3560 603 151 415 20 102 569 895 552 678 734 24 614 689 518 440 223 751 919 223 433 711 551 502 634 706 583 812 501 514 535 780 751 720 530 532 384 888 139 864 791 292 675 171 881 30 592 464 557 280 299 654 650 894 335 250 532 792 10 83 969 118 771 579 300 852 983 243 940 957 939 817 889 911 319...
output:
118 56 57 86 36 100 68 35 87 80 113 146 48 135 84 97 128 25 69 96 121 39 96 129 20 37 65 113 48 39 39 137 105 81 96 115 19 120 150 150 152 130 129 134 80 65 40 87 96 144 37 103 56 25 105 133 36 150 38 40 117 17 112 82 18 36 53 113 133 36 150 38 40 117 17 112 82 18 36 53 113 38 120 16 80 54 129 54 3...
input:
output:
result:
wrong answer Token "118" doesn't correspond to pattern "mark"