#include <iostream> #include <vector> using namespace std; struct __attribute__((packed)) eight { unsigned int a : 5; unsigned int b : 5; unsigned int c : 5; unsigned int d : 5; unsigned int e : 5; unsigned int f : 5; unsigned int g : 5; unsigned int h : 5; vector<uint> to_vec() { return {a, b, c, d, e, f, g, h}; } void from_vec(vector<uint>& vec) { a = vec[0]; b = vec[1]; c = vec[2]; d = vec[3]; e = vec[4]; f = vec[5]; g = vec[6]; h = vec[7]; } } __attribute((aligned(1))); static_assert(sizeof(eight) == 5, "sz"); static eight chars[500000]; using uint = unsigned int; int main() { int N; cin >> N; char c; vector<uint> tmp(8); uint i = 0, index = 0; int num = 0; while (cin.get(c)) { num++; uint val = (uint) c - 'a'; tmp[i] = val; i = (i + 1) % 8; if (i == 0) { chars[index].from_vec(tmp); index++; } } uint last_i; if (i > 0) { last_i = i - 1; } else { last_i = 7; } while (i < 8) { tmp[i] = 31; i++; } chars[index].from_vec(tmp); int left_chunk = 0, left = 0, right_chunk = last_i, right = index; vector<uint> lv = chars[left].to_vec(); vector<uint> rv = chars[right].to_vec(); while (left * 8 + left_chunk < right * 8 + right_chunk) { if (left_chunk > 7) { left_chunk = 0; left++; lv = chars[left].to_vec(); } if (right_chunk < 0) { right_chunk = 7; right--; rv = chars[right].to_vec(); } if (lv[left_chunk] != rv[right_chunk]) { cout << "NIE\n"; return 0; } else { left_chunk++; right_chunk--; } } cout << "TAK\n"; return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | #include <iostream> #include <vector> using namespace std; struct __attribute__((packed)) eight { unsigned int a : 5; unsigned int b : 5; unsigned int c : 5; unsigned int d : 5; unsigned int e : 5; unsigned int f : 5; unsigned int g : 5; unsigned int h : 5; vector<uint> to_vec() { return {a, b, c, d, e, f, g, h}; } void from_vec(vector<uint>& vec) { a = vec[0]; b = vec[1]; c = vec[2]; d = vec[3]; e = vec[4]; f = vec[5]; g = vec[6]; h = vec[7]; } } __attribute((aligned(1))); static_assert(sizeof(eight) == 5, "sz"); static eight chars[500000]; using uint = unsigned int; int main() { int N; cin >> N; char c; vector<uint> tmp(8); uint i = 0, index = 0; int num = 0; while (cin.get(c)) { num++; uint val = (uint) c - 'a'; tmp[i] = val; i = (i + 1) % 8; if (i == 0) { chars[index].from_vec(tmp); index++; } } uint last_i; if (i > 0) { last_i = i - 1; } else { last_i = 7; } while (i < 8) { tmp[i] = 31; i++; } chars[index].from_vec(tmp); int left_chunk = 0, left = 0, right_chunk = last_i, right = index; vector<uint> lv = chars[left].to_vec(); vector<uint> rv = chars[right].to_vec(); while (left * 8 + left_chunk < right * 8 + right_chunk) { if (left_chunk > 7) { left_chunk = 0; left++; lv = chars[left].to_vec(); } if (right_chunk < 0) { right_chunk = 7; right--; rv = chars[right].to_vec(); } if (lv[left_chunk] != rv[right_chunk]) { cout << "NIE\n"; return 0; } else { left_chunk++; right_chunk--; } } cout << "TAK\n"; return 0; } |