QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#483620 | #4826. Find the Parts | Bucketsmith | 0 | 1ms | 3972kb | C++20 | 3.7kb | 2024-07-18 20:40:59 | 2024-07-18 20:41:00 |
answer
#include <bits/stdc++.h>
using namespace std;
void message() {
int r, c;
scanf("%d%d", &r, &c);
vector<vector<int> > s(r, vector<int>(c));
for(int i = 0; i < r; i ++)
for(int j = 0; j < c; j ++)
scanf("%X", &s[i][j]);
vector<int> msg;
msg.push_back(r / 256);
msg.push_back(r % 256);
msg.push_back(c / 256);
msg.push_back(c % 256);
int tmp = 0, cnt = 0;
for(int i = 0; i < r; i ++)
for(int j = i % 2; j < c; j += 2) {
tmp = tmp * 2 + (s[i][j] % 2);
cnt ++;
if(cnt == 8) {
cnt = 0;
msg.push_back(tmp);
tmp = 0;
}
}
if(cnt) {
while(cnt < 8) {
tmp *= 2;
cnt ++;
}
msg.push_back(tmp);
}
printf("%u\n", msg.size());
for(int x : msg) printf("%02X ", x);
}
bool check(const vector<vector<int> > &a, vector<vector<int> > &b, int x, int y) {
for(int i = 0; i < b.size(); i ++)
for(int j = (x + y + i) % 2; j < b[i].size(); j += 2)
if(b[i][j] != a[i + x][j + y])
return false;
return true;
}
bool check(const vector<vector<vector<int> > > &a, const vector<int> &b, int x, int y, int l) {
for(int i = 0; i < b.size(); i ++)
if(a[x + i][y][l] != b[i])
return false;
return true;
}
void parts() {
int m;
scanf("%d", &m);
vector<int> v(m);
for(int i = 0; i < m; i ++)
scanf("%X", &v[i]);
int r = v[0] * 256 + v[1], c = v[2] * 256 + v[3];
vector<vector<int> > s(r, vector<int>(c));
for(int i = 0, p = 4, l = 7; i < r; i ++)
for(int j = i % 2; j < c; j += 2) {
s[i][j] = (v[p] >> l) & 1;
l --;
if(l < 0) {
p ++;
l = 7;
}
}
vector<vector<vector<int> > > hashS(r, vector<vector<int> >(c, vector<int>(20)));
map<pair<int, int>, vector<pair<int, int> > > pos;
for(int i = 0; i < r; i ++)
for(int j = 0; j < c; j ++) {
hashS[i][j][0] = s[i][j];
pos[{0, hashS[i][j][0]}].emplace_back(i, j);
for(int k = 1; k < 20 && j + k < c; k ++) {
hashS[i][j][k] = hashS[i][j][k - 1] * 2 + s[i][j + k];
pos[{k, hashS[i][j][k]}].emplace_back(i, j);
}
}
int q;
scanf("%d", &q);
for(int _ = 0, tr, tc; _ < q; _ ++) {
cin >> tr >> tc;
vector<vector<int> > a(tr, vector<int>(tc)), b(tr, vector<int>(tc));
for(int i = 0; i < tr; i ++)
for(int j = 0, x; j < tc; j ++) {
scanf("%X", &x);
((i + j) % 2 ? a : b)[i][j] = x % 2;
}
vector<int> hashA(tr), hashB(tr);
for(int i = 0; i < tr; i ++)
for(int j = 0; j < tc; j ++) {
hashA[i] = hashA[i] * 2 + a[i][j];
hashB[i] = hashB[i] * 2 + b[i][j];
}
bool found = false;
for(auto &[i, j] : pos[{tc - 1, hashA.front()}])
if(check(hashS, (i + j) % 2 ? hashA : hashB, i, j, tc - 1)) {
cout << i + 1 << " " << j + 1 << "\n";
found = true;
break;
}
if(found) continue;
for(auto &[i, j] : pos[{tc - 1, hashB.front()}])
if(check(hashS, (i + j) % 2 ? hashA : hashB, i, j, tc - 1)) {
cout << i + 1 << " " << j + 1 << "\n";
found = true;
break;
}
}
}
int main() {
string op;
cin >> op;
if(op == "message") message();
else parts();
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3972kb
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:
34 00 14 00 18 C4 14 08 0D DF 47 E7 BF 68 E9 2C 75 F9 92 A3 2A CC 87 69 AF 9C 3A 17 CB 36 AE 36 D6 13 71
input:
parts 34 00 14 00 18 C4 14 08 0D DF 47 E7 BF 68 E9 2C 75 F9 92 A3 2A CC 87 69 AF 9C 3A 17 CB 36 AE 36 D6 13 71 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 76 EB EB 3E AA 2...
output:
1 2 6 5
result:
ok correct answer
Test #2:
score: 0
Stage 2: Program answer Runtime Error
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 F1 54 CA 90 8F 75 37 08 25 06 88 10 D9 4B C5 17 61 A1 9A 16 3B A8 72 89 5B
input:
parts 29 00 14 00 14 F1 54 CA 90 8F 75 37 08 25 06 88 10 D9 4B C5 17 61 A1 9A 16 3B A8 72 89 5B 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...