Advertisement
999ms

Untitled

Aug 22nd, 2021
1,116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.08 KB | None | 0 0
  1. #pragma GCC Optimize("Ofast")
  2.  
  3. #include <bits/stdc++.h>
  4. #define all(x) begin(x), end(x)
  5. #define sum(v) accumulate(all(v), 0ll)
  6.  
  7. using namespace std;
  8. using ll = long long;
  9. using ld = double;
  10.  
  11. const bool TEST = false;
  12.  
  13. enum {
  14.   OK_0,
  15.   OK_1,
  16.   WA_0,
  17.   WA_1
  18. };
  19.  
  20. int getNumber(int x) {
  21.   if (x < 4) return x;
  22.   x -= 5;
  23.   if (x < 4) return x;
  24.   x -= 7;
  25.   if (x < 4) return x;
  26.   x -= 5;
  27.   return x;
  28. }
  29.  
  30. vector<vector<string>> DIGITS = {
  31.   {
  32.     ".XX.",
  33.     "X..X",
  34.     "X..X",
  35.     "....",
  36.     "X..X",
  37.     "X..X",
  38.     ".XX."
  39.   },
  40.   {
  41.     "....",
  42.     "...X",
  43.     "...X",
  44.     "....",
  45.     "...X",
  46.     "...X",
  47.     "...."
  48.   },
  49.   {
  50.     ".XX.",
  51.     "...X",
  52.     "...X",
  53.     ".XX.",
  54.     "X...",
  55.     "X...",
  56.     ".XX."
  57.   },
  58.   {
  59.     ".XX.",
  60.     "...X",
  61.     "...X",
  62.     ".XX.",
  63.     "...X",
  64.     "...X",
  65.     ".XX."
  66.   },
  67.   {
  68.     "....",
  69.     "X..X",
  70.     "X..X",
  71.     ".XX.",
  72.     "...X",
  73.     "...X",
  74.     "...."
  75.   },
  76.   {
  77.     ".XX.",
  78.     "X...",
  79.     "X...",
  80.     ".XX.",
  81.     "...X",
  82.     "...X",
  83.     ".XX."
  84.   },
  85.   {
  86.     ".XX.",
  87.     "X...",
  88.     "X...",
  89.     ".XX.",
  90.     "X..X",
  91.     "X..X",
  92.     ".XX."
  93.   },
  94.   {
  95.     ".XX.",
  96.     "...X",
  97.     "...X",
  98.     "....",
  99.     "...X",
  100.     "...X",
  101.     "...."
  102.   },
  103.   {
  104.     ".XX.",
  105.     "X..X",
  106.     "X..X",
  107.     ".XX.",
  108.     "X..X",
  109.     "X..X",
  110.     ".XX."
  111.   },
  112.   {
  113.     ".XX.",
  114.     "X..X",
  115.     "X..X",
  116.     ".XX.",
  117.     "...X",
  118.     "...X",
  119.     ".XX."
  120.   },
  121.   {
  122.     "....",
  123.     "....",
  124.     "....",
  125.     "....",
  126.     "....",
  127.     "....",
  128.     "...."
  129.   }
  130. };
  131.  
  132. vector<vector<string>> LINES = {
  133.   {
  134.     ".",
  135.     ".",
  136.     ".",
  137.     ".",
  138.     ".",
  139.     ".",
  140.     ".",
  141.   },
  142.   {
  143.     ".",
  144.     ".",
  145.     "X",
  146.     ".",
  147.     "X",
  148.     ".",
  149.     ".",
  150.   }
  151. };
  152.  
  153. int getFromEnum(char need, char cur) {
  154.   if (need == '.') {
  155.     if (cur == '.') {
  156.       return OK_0;
  157.     } else {
  158.       return WA_1;
  159.     }
  160.   } else {
  161.     if (cur == '.') {
  162.       return WA_0;
  163.     } else {
  164.       return OK_1;
  165.     }
  166.   }
  167. }
  168.  
  169. struct Item {
  170.   int mask = 0;
  171.   void add(int i) { mask |= 1 << i; }
  172.   bool has(int i) { return (mask >> i) & 1; }
  173. };
  174.  
  175. vector<string>& getFromChar(char ch, bool first = false) {
  176.   if (ch >= '0' && ch <= '9') {
  177.     if (first && ch == '0') {
  178.       return DIGITS.back();
  179.     }
  180.     return DIGITS[ch - '0'];
  181.   }
  182.   if (ch == ':') {
  183.     return LINES[1];
  184.   } else {
  185.     return LINES[0];
  186.   }
  187. }
  188.  
  189. void connect(vector<string>& a, const vector<string>& b) {
  190.   for (int i = 0; i < a.size(); i++) {
  191.     a[i] += b[i];
  192.   }
  193. }
  194.  
  195. vector<string> getFromTime(string& s) {
  196.   vector<string> ans = getFromChar(s[0], s[0] == '0');
  197.   connect(ans, getFromChar(' '));
  198.   connect(ans, getFromChar(s[1]));
  199.   connect(ans, getFromChar(' '));
  200.   connect(ans, getFromChar(s[2]));
  201.   connect(ans, getFromChar(' '));
  202.   connect(ans, getFromChar(s[3]));
  203.   connect(ans, getFromChar(' '));
  204.   connect(ans, getFromChar(s[4]));
  205.   return ans;
  206. }
  207.  
  208. vector<string> compare(const vector<string>& need, const vector<string>& cur) {
  209.   vector<string> ans(7, string(21, char(0)));
  210.   for (int x = 0; x < 7; x++) {
  211.     for (int y = 0; y < 21; y++) {
  212.       ans[x][y] = getFromEnum(need[x][y], cur[x][y]);
  213.     }
  214.   }
  215.   return ans;
  216. }
  217.  
  218.  
  219. bool relaxInfo(vector<vector<Item>>& info, vector<string>& add) {
  220.   for (int x = 0; x < 7; x++) {
  221.     for (int y = 0; y < 21; y++) {
  222.       int cur = add[x][y];
  223.       if (cur == OK_0) {
  224.         if (info[x][y].has(WA_1) || info[x][y].has(WA_0) && info[x][y].has(OK_1)) {
  225.           return false;
  226.         }
  227.       }
  228.      
  229.       if (cur == OK_1) {
  230.         if (info[x][y].has(WA_0) || info[x][y].has(WA_1) && info[x][y].has(OK_0)) {
  231.           return false;
  232.         }
  233.       }
  234.      
  235.       if (cur == WA_0) {
  236.         if (info[x][y].has(WA_1) || info[x][y].has(OK_1)) {
  237.           return false;
  238.         }
  239.       }
  240.      
  241.       if (cur == WA_1) {
  242.         if (info[x][y].has(WA_0) || info[x][y].has(OK_0)) {
  243.           return false;
  244.         }
  245.       }
  246.      
  247.       info[x][y].add(cur);
  248.     }
  249.   }
  250.   return true;
  251. }
  252.  
  253.  
  254. void solve() {
  255.   int n;
  256.   cin >> n;
  257.   vector<vector<string>> arr(n, vector<string>(7, ""));
  258.  
  259.   vector<vector<string>> data;
  260.   for (int h = 0; h < 24; h++) {
  261.     for (int m = 0; m < 60; m++) {
  262.       auto t = (h >= 10 ? to_string(h) : "0" + to_string(h))
  263.             + ":"
  264.             + (m >= 10 ? to_string(m) : "0" + to_string(m));
  265.       data.push_back(getFromTime(t));
  266.     }
  267.   }
  268.  
  269.   for (auto& data : arr) {
  270.     for (auto& s : data) {
  271.       cin >> s;
  272.     }
  273.   }
  274.  
  275.   vector<int> goodTime;
  276.   for (int h = 0; h < 24; h++) {
  277.     for (int m = 0; m < 60; m++) {
  278.       bool good = true;
  279.       vector<vector<Item>> info(7, vector<Item>(21));
  280.  
  281.       for (int i = 0; i < n && good; i++) {
  282.         int cm = (m + i);
  283.         int ch = (h + cm / 60) % 24;
  284.         cm %= 60;
  285.         auto& needTime = data[ch * 60 + cm];
  286.         auto& curTime = arr[i];
  287.        
  288.         auto result = compare(needTime, curTime);
  289.        
  290.         good &= relaxInfo(info, result);
  291.       }
  292.      
  293.       if (good) {
  294.         goodTime.push_back(h * 60 + m);
  295.       }
  296.     }
  297.   }
  298.  
  299.   if (goodTime.size() == 0) {
  300.     cout << "impossible" << endl;
  301.     return;
  302.   }
  303.  
  304.   vector<string> isConstant(7, string(21, 1));
  305.  
  306.   for (int i = 0; i < n; i++) {
  307.     for (int x = 0; x < 7; x++) {
  308.       for (int y = 0; y < 21; y++) {
  309.         isConstant[x][y] &= arr[i][x][y] == arr[0][x][y];
  310.       }
  311.     }
  312.   }
  313.  
  314.   vector<string> ans(7, string(21, '*'));
  315.   vector<pair<int,int>> pointsForCheck;
  316.   for (int x = 0; x < 7; x++) {
  317.     for (int y = 0; y < 21; y++) {
  318.       if (!isConstant[x][y]) {
  319.         ans[x][y] = 'W';
  320.       } else if (y == 4 || y == 9 || y == 10 || y == 11 || y == 16 || DIGITS[8][x][getNumber(y)] == '.') {
  321.         if (y == 10 && (x == 2 || x == 4)) {
  322.           if (arr[0][x][y] == 'X') {
  323.             ans[x][y] = '?';
  324.           } else {
  325.             ans[x][y] = '0';
  326.           }
  327.         } else {
  328.           if (arr[0][x][y] == 'X') {
  329.             ans[x][y] = '1';
  330.           } else {
  331.             ans[x][y] = '.';
  332.           }
  333.         }
  334.       } else {
  335.         pointsForCheck.push_back({x, y});
  336.       }
  337.     }
  338.   }
  339.  
  340.   for (auto [x, y] : pointsForCheck) {
  341.     vector<pair<int,int>> tmp;
  342.     for (int t : goodTime) {
  343.       int badCount = 0;
  344.       int goodCount = 0;
  345.       for (int i = 0; i < n; i++) {
  346.         auto& needTime = data[(t + i) % (24 * 60)];
  347.         auto& curTime = arr[i];
  348.         goodCount += needTime[x][y] == curTime[x][y];
  349.         badCount += needTime[x][y] != curTime[x][y];
  350.       }
  351.       tmp.push_back({goodCount, badCount});
  352.     }
  353.     bool probablyGood = false;
  354.    
  355.    
  356.     for (auto [g, b] : tmp) {
  357.       if (b == 0) {
  358.         probablyGood = true;
  359.       }
  360.     }
  361.    
  362.     if (probablyGood) {
  363.       ans[x][y] = '?';
  364.     } else {
  365.       ans[x][y] = arr[0][x][y] == 'X' ? '1' : '0';
  366.     }
  367.    
  368.   }
  369.  
  370.   for (auto& s : ans) {
  371.     cout << s << '\n';
  372.   }
  373. }
  374.  
  375. int main() {  
  376.   ios_base::sync_with_stdio(false);
  377.   cin.tie(nullptr);
  378.   cout.tie(nullptr);
  379.  
  380.   int t;
  381.   if (TEST) {
  382.     cin >> t;
  383.   } else {
  384.     t = 1;
  385.   }
  386.   while (t--) solve();
  387. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement