QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#296758 | #4829. Mark on a Graph | defyers# | 0 | 0ms | 0kb | C++17 | 5.4kb | 2024-01-03 15:31:27 | 2024-01-03 15:31:27 |
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) {
int num = qa[r1][c1] ^ qa[r1 - 1][c1] ^ qa[r1][c1 - 1] ^ qa[r1 - 1][c1 - 1];
return (num + qa[r2][c2] ^ qa[r1 - 1][c2] ^ qa[r2][c1 - 1] ^ qa[r1 - 1][c1 - 1]) % 256;
}
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];
}
}
x = (x + a[i][j]) % 256;
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();
}
}
詳細信息
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:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
input:
output:
result:
wrong answer Token "0" doesn't correspond to pattern "mark"