QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#296752#4829. Mark on a Graphdefyers#0 0ms0kbC++175.6kb2024-01-03 15:18:262024-01-03 15:18:26

Judging History

你现在查看的是最新测评结果

  • [2024-01-03 15:18:26]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2024-01-03 15:18:26]
  • 提交

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() {
	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);
			if (x == 180) {
				cout << "get 180 from: \n";
				for (int ii = i; ii < i + ilen; ii++) {
					for (int jj = j; jj < j + jlen; jj++) {
						cout << a[ii][jj] << " ";
					}
					cout << endl;
				}
			}
			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++) {
			cout << h[i][j] << " ";
		}
		cout << 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";
					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: 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:

r and c : 24597 16672
hashed array size: 1 3557
16 86 137 85 103 115 36 97 104 81 68 34 117 145 34 67 113 85 80 99 112 88 129 80 81 83 120 117 114 83 83 56 136 19 134 121 41 103 23 136 48 89 70 85 40 41 101 101 137 51 37 83 121 16 131 150 17 119 87 48 133 152 36 148 149 147 129 136 145 49 116 34 89 ...

input:


output:


result:

wrong answer Token "r" doesn't correspond to pattern "mark"