QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#296765 | #4824. Bracket-and-bar Sequences | defyers# | 0 | 0ms | 0kb | C++17 | 5.7kb | 2024-01-03 15:49:07 | 2024-01-03 15:49:07 |
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];
}
}
cout << "(" << x << "+"<< a[i][j] << ") ";
x = (x + a[i][j]) % 256;
ans.push_back(x);
j += jlen;
jlen = 7 - jlen;
}
cout << endl;
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 (i == 1 && j == 3) {
cout << "to get " << H(i, j, i + 2, j + 3) << ", from:\n";
int tmp = 0;
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]) << " ";
tmp ^= (qa[ii][jj] ^ qa[ii - 1][jj] ^ qa[ii][jj - 1] ^ qa[ii - 1][jj - 1]);
}
cout << (qa[i][j] ^ qa[i - 1][j] ^ qa[i][j - 1] ^ qa[i - 1][j - 1]) << "+" << tmp << endl;
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: 0
Wrong Answer on the first run
input:
encode 3 1 (|) 4 ((((|)|)|)|) 5 (|(|))((|(|))|)
output:
to get 0, from: 0 0 0 0 0+0 0 0 0 0 0+0 0 0 0 0 0+0 0 0 0 0 0 0 to get 0, from: 0 0 0 0 0+0 0 0 0 0 0+0 0 0 0 0 0+0 0 0 0 0 0 0 to get 0, from: 0 0 0 0 0+0 0 0 0 0 0+0 0 0 0 0 0+0 0 0 0 0 0 0 to get 0, from: 0 0 0 0 0+0 0 0 0 0 0+0 0 0 0 0 0+0 0 0 0 0 0 0 to get 0, from: 0 0 0 0 0+0 0 0...
input:
output:
result:
wrong output format Expected integer, but "to" found (test case 1)