Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma GCC Optimize("Ofast")
- #include <bits/stdc++.h>
- #define all(x) begin(x), end(x)
- #define sum(v) accumulate(all(v), 0ll)
- using namespace std;
- using ll = long long;
- using ld = double;
- const bool TEST = false;
- enum {
- OK_0,
- OK_1,
- WA_0,
- WA_1
- };
- int getNumber(int x) {
- if (x < 4) return x;
- x -= 5;
- if (x < 4) return x;
- x -= 7;
- if (x < 4) return x;
- x -= 5;
- return x;
- }
- vector<vector<string>> DIGITS = {
- {
- ".XX.",
- "X..X",
- "X..X",
- "....",
- "X..X",
- "X..X",
- ".XX."
- },
- {
- "....",
- "...X",
- "...X",
- "....",
- "...X",
- "...X",
- "...."
- },
- {
- ".XX.",
- "...X",
- "...X",
- ".XX.",
- "X...",
- "X...",
- ".XX."
- },
- {
- ".XX.",
- "...X",
- "...X",
- ".XX.",
- "...X",
- "...X",
- ".XX."
- },
- {
- "....",
- "X..X",
- "X..X",
- ".XX.",
- "...X",
- "...X",
- "...."
- },
- {
- ".XX.",
- "X...",
- "X...",
- ".XX.",
- "...X",
- "...X",
- ".XX."
- },
- {
- ".XX.",
- "X...",
- "X...",
- ".XX.",
- "X..X",
- "X..X",
- ".XX."
- },
- {
- ".XX.",
- "...X",
- "...X",
- "....",
- "...X",
- "...X",
- "...."
- },
- {
- ".XX.",
- "X..X",
- "X..X",
- ".XX.",
- "X..X",
- "X..X",
- ".XX."
- },
- {
- ".XX.",
- "X..X",
- "X..X",
- ".XX.",
- "...X",
- "...X",
- ".XX."
- },
- {
- "....",
- "....",
- "....",
- "....",
- "....",
- "....",
- "...."
- }
- };
- vector<vector<string>> LINES = {
- {
- ".",
- ".",
- ".",
- ".",
- ".",
- ".",
- ".",
- },
- {
- ".",
- ".",
- "X",
- ".",
- "X",
- ".",
- ".",
- }
- };
- int getFromEnum(char need, char cur) {
- if (need == '.') {
- if (cur == '.') {
- return OK_0;
- } else {
- return WA_1;
- }
- } else {
- if (cur == '.') {
- return WA_0;
- } else {
- return OK_1;
- }
- }
- }
- struct Item {
- int mask = 0;
- void add(int i) { mask |= 1 << i; }
- bool has(int i) { return (mask >> i) & 1; }
- };
- vector<string>& getFromChar(char ch, bool first = false) {
- if (ch >= '0' && ch <= '9') {
- if (first && ch == '0') {
- return DIGITS.back();
- }
- return DIGITS[ch - '0'];
- }
- if (ch == ':') {
- return LINES[1];
- } else {
- return LINES[0];
- }
- }
- void connect(vector<string>& a, const vector<string>& b) {
- for (int i = 0; i < a.size(); i++) {
- a[i] += b[i];
- }
- }
- vector<string> getFromTime(string& s) {
- vector<string> ans = getFromChar(s[0], s[0] == '0');
- connect(ans, getFromChar(' '));
- connect(ans, getFromChar(s[1]));
- connect(ans, getFromChar(' '));
- connect(ans, getFromChar(s[2]));
- connect(ans, getFromChar(' '));
- connect(ans, getFromChar(s[3]));
- connect(ans, getFromChar(' '));
- connect(ans, getFromChar(s[4]));
- return ans;
- }
- vector<string> compare(const vector<string>& need, const vector<string>& cur) {
- vector<string> ans(7, string(21, char(0)));
- for (int x = 0; x < 7; x++) {
- for (int y = 0; y < 21; y++) {
- ans[x][y] = getFromEnum(need[x][y], cur[x][y]);
- }
- }
- return ans;
- }
- bool relaxInfo(vector<vector<Item>>& info, vector<string>& add) {
- for (int x = 0; x < 7; x++) {
- for (int y = 0; y < 21; y++) {
- int cur = add[x][y];
- if (cur == OK_0) {
- if (info[x][y].has(WA_1) || info[x][y].has(WA_0) && info[x][y].has(OK_1)) {
- return false;
- }
- }
- if (cur == OK_1) {
- if (info[x][y].has(WA_0) || info[x][y].has(WA_1) && info[x][y].has(OK_0)) {
- return false;
- }
- }
- if (cur == WA_0) {
- if (info[x][y].has(WA_1) || info[x][y].has(OK_1)) {
- return false;
- }
- }
- if (cur == WA_1) {
- if (info[x][y].has(WA_0) || info[x][y].has(OK_0)) {
- return false;
- }
- }
- info[x][y].add(cur);
- }
- }
- return true;
- }
- void solve() {
- int n;
- cin >> n;
- vector<vector<string>> arr(n, vector<string>(7, ""));
- vector<vector<string>> data;
- for (int h = 0; h < 24; h++) {
- for (int m = 0; m < 60; m++) {
- auto t = (h >= 10 ? to_string(h) : "0" + to_string(h))
- + ":"
- + (m >= 10 ? to_string(m) : "0" + to_string(m));
- data.push_back(getFromTime(t));
- }
- }
- for (auto& data : arr) {
- for (auto& s : data) {
- cin >> s;
- }
- }
- vector<int> goodTime;
- for (int h = 0; h < 24; h++) {
- for (int m = 0; m < 60; m++) {
- bool good = true;
- vector<vector<Item>> info(7, vector<Item>(21));
- for (int i = 0; i < n && good; i++) {
- int cm = (m + i);
- int ch = (h + cm / 60) % 24;
- cm %= 60;
- auto& needTime = data[ch * 60 + cm];
- auto& curTime = arr[i];
- auto result = compare(needTime, curTime);
- good &= relaxInfo(info, result);
- }
- if (good) {
- goodTime.push_back(h * 60 + m);
- }
- }
- }
- if (goodTime.size() == 0) {
- cout << "impossible" << endl;
- return;
- }
- vector<string> isConstant(7, string(21, 1));
- for (int i = 0; i < n; i++) {
- for (int x = 0; x < 7; x++) {
- for (int y = 0; y < 21; y++) {
- isConstant[x][y] &= arr[i][x][y] == arr[0][x][y];
- }
- }
- }
- vector<string> ans(7, string(21, '*'));
- vector<pair<int,int>> pointsForCheck;
- for (int x = 0; x < 7; x++) {
- for (int y = 0; y < 21; y++) {
- if (!isConstant[x][y]) {
- ans[x][y] = 'W';
- } else if (y == 4 || y == 9 || y == 10 || y == 11 || y == 16 || DIGITS[8][x][getNumber(y)] == '.') {
- if (y == 10 && (x == 2 || x == 4)) {
- if (arr[0][x][y] == 'X') {
- ans[x][y] = '?';
- } else {
- ans[x][y] = '0';
- }
- } else {
- if (arr[0][x][y] == 'X') {
- ans[x][y] = '1';
- } else {
- ans[x][y] = '.';
- }
- }
- } else {
- pointsForCheck.push_back({x, y});
- }
- }
- }
- for (auto [x, y] : pointsForCheck) {
- vector<pair<int,int>> tmp;
- for (int t : goodTime) {
- int badCount = 0;
- int goodCount = 0;
- for (int i = 0; i < n; i++) {
- auto& needTime = data[(t + i) % (24 * 60)];
- auto& curTime = arr[i];
- goodCount += needTime[x][y] == curTime[x][y];
- badCount += needTime[x][y] != curTime[x][y];
- }
- tmp.push_back({goodCount, badCount});
- }
- bool probablyGood = false;
- for (auto [g, b] : tmp) {
- if (b == 0) {
- probablyGood = true;
- }
- }
- if (probablyGood) {
- ans[x][y] = '?';
- } else {
- ans[x][y] = arr[0][x][y] == 'X' ? '1' : '0';
- }
- }
- for (auto& s : ans) {
- cout << s << '\n';
- }
- }
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- int t;
- if (TEST) {
- cin >> t;
- } else {
- t = 1;
- }
- while (t--) solve();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement