fork download
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<vector>
  4. #include<cstring>
  5. #include<sstream>
  6. #include<fstream>
  7. #include<algorithm>
  8. using namespace std;
  9.  
  10. string t[52];
  11.  
  12. string update(string s)
  13. {
  14. int h1 = s[0] - '0';
  15. int h2 = s[1] - '0';
  16. int m1 = s[3] - '0';
  17. int m2 = s[4] - '0';
  18. //update
  19. m2++;
  20. if (m2 == 10) {
  21. m2 = 0;
  22. m1++;
  23. if (m1 == 6) {
  24. m1 = 0;
  25. h2++;
  26. if (h2 == 10) {
  27. h2 = 0;
  28. h1++;
  29. } else if (h2 == 4 && h1 == 2) {
  30. h2 = 0;
  31. h1 = 0;
  32. }
  33. }
  34. }
  35. string r = "";
  36. r += h1 + '0';
  37. r += h2 + '0';
  38. r += ":";
  39. r += m1 + '0';
  40. r += m2 + '0';
  41. return r;
  42.  
  43. }
  44.  
  45. int valid(int h1, int h2, int m1, int m2)
  46. {
  47. if (h1 > 2)
  48. return 0;
  49. if (h2 > 9)
  50. return 0;
  51. if (m1 > 5)
  52. return 0;
  53. if (m2 > 9)
  54. return 0;
  55. if (h1 == 2 && h2 > 3)
  56. return 0;
  57. return 1;
  58. }
  59.  
  60. int same(int h1, int h2, int m1, int m2, string cur)
  61. {
  62. if (cur[0] == '1') {
  63. if (h1 != 0 and h1 != 1)
  64. return 0;
  65. } else if (cur[0] == '2') {
  66. if (h1 != 2)
  67. return 0;
  68. } else if (cur[0] == '0') {
  69. if (h1 != 0)
  70. return 0;
  71. } else if (cur[0] == '7') {
  72. if (h1 != 0)
  73. return 0;
  74. } else
  75. return 0;
  76.  
  77. if (cur[1] == '1') {
  78. if (h2 != 0 and h2 != 1 and h2 != 3 and h2 != 4 and h2 != 7 and h2 != 8 and h2 != 9)
  79. return 0;
  80. } else if (cur[1] == '2') {
  81. if (h2 != 2 and h2 != 8)
  82. return 0;
  83. } else if (cur[1] == '0') {
  84. if (h2 != 0 and h2 != 8)
  85. return 0;
  86. } else if (cur[1] == '3') {
  87. if (h2 != 8 and h2 != 9 and h2 != 3)
  88. return 0;
  89.  
  90. } else if (cur[1] == '4') {
  91. if (h2 != 4 and h2 != 8 and h2 != 9)
  92. return 0;
  93. } else if (cur[1] == '5') {
  94. if (h2 != 5 and h2 != 6 and h2 != 8 and h2 != 9)
  95. return 0;
  96. } else if (cur[1] == '6') {
  97. if (h2 != 6 and h2 != 8)
  98. return 0;
  99. } else if (cur[1] == '7') {
  100. if (h2 != 0 and h2 != 7 and h2 != 3 and h2 != 8 and h2 != 9)
  101. return 0;
  102. } else if (cur[1] == '8') {
  103. if (h2 != 8)
  104. return 0;
  105. } else if (cur[1] == '9') {
  106. if (h2 != 9 and h2 != 8)
  107. return 0;
  108. } else
  109. return 0;
  110.  
  111.  
  112. if (cur[4] == '1') {
  113. if (m2 != 0 and m2 != 1 and m2 != 3 and m2 != 4 and m2 != 7 and m2 != 8 and m2 != 9)
  114. return 0;
  115. } else if (cur[4] == '2') {
  116. if (m2 != 2 and m2 != 8)
  117. return 0;
  118. } else if (cur[4] == '0') {
  119. if (m2 != 0 and m2 != 8)
  120. return 0;
  121. } else if (cur[4] == '3') {
  122. if (m2 != 8 and m2 != 9 and h2 != 3)
  123. return 0;
  124.  
  125. } else if (cur[4] == '4') {
  126. if (m2 != 4 and m2 != 8 and m2 != 9)
  127. return 0;
  128. } else if (cur[4] == '5') {
  129. if (m2 != 5 and m2 != 6 and m2 != 8 and m2 != 9)
  130. return 0;
  131. } else if (cur[4] == '6') {
  132. if (m2 != 6 and m2 != 8)
  133. return 0;
  134. } else if (cur[4] == '7') {
  135. if (m2 != 0 and m2 != 7 and m2 != 3 and m2 != 8 and m2 != 9)
  136. return 0;
  137. } else if (cur[4] == '8') {
  138. if (m2 != 8)
  139. return 0;
  140. } else if (cur[4] == '9') {
  141. if (m2 != 9 and h2 != 8)
  142. return 0;
  143. } else
  144. return 0;
  145.  
  146.  
  147.  
  148. if (cur[3] == '1') {
  149. if (m1 != 0 and m1 != 1 and m1 != 3 and m1 != 4)
  150. return 0;
  151.  
  152. } else if (cur[3] == '2') {
  153. if (m1 != 2)
  154. return 0;
  155. } else if (cur[3] == '0') {
  156. if (m1 != 0)
  157. return 0;
  158.  
  159. } else if (cur[3] == '3') {
  160. if (m1 != 3)
  161. return 0;
  162.  
  163. } else if (cur[3] == '4') {
  164. if (m1 != 4)
  165. return 0;
  166.  
  167. } else if (cur[3] == '5') {
  168. if (m1 != 5)
  169. return 0;
  170. } else if (cur[3] == '7') {
  171. if (m1 != 9 and m1 != 3)
  172. return 0;
  173.  
  174. } else
  175. return 0;
  176.  
  177. return 1;
  178.  
  179. }
  180.  
  181. int N;
  182. int dfs(int h1, int h2, int m1, int m2, int i)
  183. {
  184. if (i == N)
  185. return 1;
  186. if (!valid(h1, h2, m1, m2))
  187. return 0;
  188. if (!same(h1, h2, m1, m2, t[i]))
  189. return 0;
  190. //update
  191. m2++;
  192. if (m2 == 10) {
  193. m2 = 0;
  194. m1++;
  195. if (m1 == 6) {
  196. m1 = 0;
  197. h2++;
  198. if (h2 == 10) {
  199. h2 = 0;
  200. h1++;
  201. } else if (h2 == 4 && h1 == 2) {
  202. h2 = 0;
  203. h1 = 0;
  204. }
  205. }
  206. }
  207. return dfs(h1, h2, m1, m2, i + 1);
  208. }
  209.  
  210. int main()
  211. {
  212. string s;
  213. while (getline(cin, s)) {
  214. istringstream in(s);
  215. in >> N;
  216. for (int i = 0; i < N; i++) {
  217. in >> t[i];
  218.  
  219. }
  220. vector < int >h1, h2, m1, m2;
  221. h1.clear();
  222. h2.clear();
  223. m1.clear();
  224. m2.clear();
  225. if (t[0][0] == '1') {
  226. h1.push_back(0);
  227. h1.push_back(1);
  228. }
  229. if (t[0][0] == '2')
  230. h1.push_back(2);
  231. if (t[0][0] == '0')
  232. h1.push_back(0);
  233. if (t[0][0] == '7')
  234. h1.push_back(0);
  235.  
  236. // h2
  237. if (t[0][1] == '1') {
  238. h2.push_back(0);
  239. h2.push_back(1);
  240. h2.push_back(3);
  241. h2.push_back(4);
  242. h2.push_back(7);
  243. h2.push_back(8);
  244. h2.push_back(9);
  245. }
  246. if (t[0][1] == '2') {
  247. h2.push_back(2);
  248. h2.push_back(8);
  249. }
  250. if (t[0][1] == '0') {
  251. h2.push_back(0);
  252. h2.push_back(8);
  253. }
  254. if (t[0][1] == '3') {
  255. h2.push_back(3);
  256. h2.push_back(8);
  257. h2.push_back(9);
  258.  
  259. }
  260. if (t[0][1] == '4') {
  261. h2.push_back(4);
  262. h2.push_back(8);
  263. h2.push_back(9);
  264. }
  265. if (t[0][1] == '5') {
  266. h2.push_back(5);
  267. h2.push_back(6);
  268. h2.push_back(8);
  269. h2.push_back(9);
  270. }
  271. if (t[0][1] == '6') {
  272. h2.push_back(6);
  273. h2.push_back(8);
  274. }
  275. if (t[0][1] == '7') {
  276. h2.push_back(0);
  277. h2.push_back(7);
  278. h2.push_back(3);
  279. h2.push_back(8);
  280. h2.push_back(9);
  281. }
  282. if (t[0][1] == '8') {
  283. h2.push_back(8);
  284. }
  285. if (t[0][1] == '9') {
  286. h2.push_back(9);
  287. h2.push_back(8);
  288. }
  289. // m2
  290. if (t[0][4] == '1') {
  291. m2.push_back(0);
  292. m2.push_back(1);
  293. m2.push_back(3);
  294. m2.push_back(4);
  295. m2.push_back(7);
  296. m2.push_back(8);
  297. m2.push_back(9);
  298. }
  299. if (t[0][4] == '2') {
  300. m2.push_back(2);
  301. m2.push_back(8);
  302. }
  303. if (t[0][4] == '0') {
  304. m2.push_back(0);
  305. m2.push_back(8);
  306. }
  307. if (t[0][4] == '3') {
  308. m2.push_back(3);
  309. m2.push_back(8);
  310. m2.push_back(9);
  311.  
  312. }
  313. if (t[0][4] == '4') {
  314. m2.push_back(4);
  315. m2.push_back(8);
  316. m2.push_back(9);
  317. }
  318. if (t[0][4] == '5') {
  319. m2.push_back(5);
  320. m2.push_back(6);
  321. m2.push_back(8);
  322. m2.push_back(9);
  323. }
  324. if (t[0][4] == '6') {
  325. m2.push_back(6);
  326. m2.push_back(8);
  327. }
  328. if (t[0][4] == '7') {
  329. m2.push_back(0);
  330. m2.push_back(7);
  331. m2.push_back(3);
  332. m2.push_back(8);
  333. m2.push_back(9);
  334. }
  335. if (t[0][4] == '8') {
  336. m2.push_back(8);
  337. }
  338. if (t[0][4] == '9') {
  339. m2.push_back(9);
  340. m2.push_back(8);
  341. }
  342.  
  343. // m1
  344. if (t[0][3] == '1') {
  345. m1.push_back(0);
  346. m1.push_back(1);
  347. m1.push_back(3);
  348. m1.push_back(4);
  349. }
  350. if (t[0][3] == '2') {
  351. m1.push_back(2);
  352. }
  353. if (t[0][3] == '0') {
  354. m1.push_back(0);
  355. }
  356. if (t[0][3] == '3') {
  357. m1.push_back(3);
  358.  
  359. }
  360. if (t[0][3] == '4') {
  361. m1.push_back(4);
  362. }
  363. if (t[0][3] == '5') {
  364. m1.push_back(5);
  365. }
  366. if (t[0][3] == '7') {
  367. m1.push_back(0);
  368. m1.push_back(3);
  369. }
  370. vector < string > ret;
  371. ret.clear();
  372.  
  373. for (int i = 0; i < h1.size(); i++)
  374. for (int j = 0; j < h2.size(); j++)
  375. for (int k = 0; k < m1.size(); k++)
  376. for (int z = 0; z < m2.size(); z++) {
  377. int c = 1;
  378. c &= dfs(h1[i], h2[j], m1[k], m2[z], 0);
  379. if (c) {
  380. string r = "";
  381. r += h1[i] + '0';
  382. r += h2[j] + '0';
  383. r += ":";
  384. r += m1[k] + '0';
  385. r += m2[z] + '0';
  386. ret.push_back(r);
  387. }
  388. }
  389. if (ret.size() == 0)
  390. cout << "none" << endl;
  391. else {
  392. sort(ret.begin(), ret.end());
  393. vector < string > is;
  394. for (int i = 0; i < ret.size(); i++) {
  395. vector < string > cc;
  396. cc.clear();
  397. string ccur = ret[i];
  398. for (int j = 0; j < N; j++) {
  399. cc.push_back(ccur);
  400. ccur = update(ccur);
  401. }
  402.  
  403. int count = 0;
  404. for (int j = 0; j < 5; j++) {
  405. if (j == 2)
  406. continue;
  407. int R[7], a[7], b[7];
  408. memset(R, 0, sizeof(R));
  409. for (int k = 0; k < cc.size(); k++) {
  410. memset(a, 0, sizeof(a));
  411. memset(b, 0, sizeof(b));
  412. if (cc[k][j] == '0') {
  413. b[0] = 1;
  414. b[1] = 1;
  415. b[2] = 1;
  416. b[3] = 1;
  417. b[4] = 1;
  418. b[5] = 1;
  419.  
  420. }
  421. if (cc[k][j] == '1') {
  422.  
  423. b[1] = 1;
  424. b[2] = 1;
  425.  
  426. }
  427. if (cc[k][j] == '2') {
  428. b[0] = 1;
  429. b[1] = 1;
  430. b[6] = 1;
  431. b[3] = 1;
  432. b[4] = 1;
  433.  
  434. }
  435. if (cc[k][j] == '3') {
  436. b[0] = 1;
  437. b[1] = 1;
  438. b[6] = 1;
  439. b[3] = 1;
  440. b[2] = 1;
  441. }
  442. if (cc[k][j] == '4') {
  443. b[1] = 1;
  444. b[2] = 1;
  445. b[6] = 1;
  446. b[5] = 1;
  447. }
  448. if (cc[k][j] == '5') {
  449. b[0] = 1;
  450. b[5] = 1;
  451. b[6] = 1;
  452. b[2] = 1;
  453. b[3] = 1;
  454. }
  455. if (cc[k][j] == '6') {
  456. b[0] = 1;
  457. b[5] = 1;
  458. b[6] = 1;
  459. b[2] = 1;
  460. b[3] = 1;
  461. b[4] = 1;
  462. }
  463. if (cc[k][j] == '7') {
  464. b[0] = 1;
  465. b[1] = 1;
  466. b[2] = 1;
  467.  
  468. }
  469. if (cc[k][j] == '8') {
  470. b[0] = 1;
  471. b[1] = 1;
  472. b[2] = 1;
  473. b[3] = 1;
  474. b[4] = 1;
  475. b[5] = 1;
  476. b[6] = 1;
  477. }
  478. if (cc[k][j] == '9') {
  479. b[0] = 1;
  480. b[1] = 1;
  481. b[2] = 1;
  482. b[3] = 1;
  483. b[5] = 1;
  484. b[6] = 1;
  485. }
  486. //t
  487. if (t[k][j] == '0') {
  488. a[0] = 1;
  489. a[1] = 1;
  490. a[2] = 1;
  491. a[3] = 1;
  492. a[4] = 1;
  493. a[5] = 1;
  494.  
  495. }
  496. if (t[k][j] == '1') {
  497.  
  498. a[1] = 1;
  499. a[2] = 1;
  500.  
  501. }
  502. if (t[k][j] == '2') {
  503. a[0] = 1;
  504. a[1] = 1;
  505. a[6] = 1;
  506. a[3] = 1;
  507. a[4] = 1;
  508.  
  509. }
  510. if (t[k][j] == '3') {
  511. a[0] = 1;
  512. a[1] = 1;
  513. a[6] = 1;
  514. a[3] = 1;
  515. a[2] = 1;
  516. }
  517. if (t[k][j] == '4') {
  518. a[1] = 1;
  519. a[2] = 1;
  520. a[6] = 1;
  521. a[5] = 1;
  522. }
  523. if (t[k][j] == '5') {
  524. a[0] = 1;
  525. a[5] = 1;
  526. a[6] = 1;
  527. a[2] = 1;
  528. a[3] = 1;
  529. }
  530. if (t[k][j] == '6') {
  531. a[0] = 1;
  532. a[5] = 1;
  533. a[6] = 1;
  534. a[2] = 1;
  535. a[3] = 1;
  536. a[4] = 1;
  537. }
  538. if (t[k][j] == '7') {
  539. a[0] = 1;
  540. a[1] = 1;
  541. a[2] = 1;
  542.  
  543. }
  544. if (t[k][j] == '8') {
  545. a[0] = 1;
  546. a[1] = 1;
  547. a[2] = 1;
  548. a[3] = 1;
  549. a[4] = 1;
  550. a[5] = 1;
  551. a[6] = 1;
  552. }
  553. if (t[k][j] == '9') {
  554. a[0] = 1;
  555. a[1] = 1;
  556. a[2] = 1;
  557. a[3] = 1;
  558. a[5] = 1;
  559. a[6] = 1;
  560. }
  561. for (int z = 0; z < 7; z++)
  562. if (!R[z])
  563. R[z] = a[z] ^ b[z];
  564. }
  565. int ok = 1;
  566. for (int k = 0; k < N; k++) {
  567. memset(a, 0, sizeof(a));
  568. //t
  569. if (t[k][j] == '0') {
  570. a[0] = 1;
  571. a[1] = 1;
  572. a[2] = 1;
  573. a[3] = 1;
  574. a[4] = 1;
  575. a[5] = 1;
  576.  
  577. }
  578. if (t[k][j] == '1') {
  579.  
  580. a[1] = 1;
  581. a[2] = 1;
  582.  
  583. }
  584. if (t[k][j] == '2') {
  585. a[0] = 1;
  586. a[1] = 1;
  587. a[6] = 1;
  588. a[3] = 1;
  589. a[4] = 1;
  590.  
  591. }
  592. if (t[k][j] == '3') {
  593. a[0] = 1;
  594. a[1] = 1;
  595. a[6] = 1;
  596. a[3] = 1;
  597. a[2] = 1;
  598. }
  599. if (t[k][j] == '4') {
  600. a[1] = 1;
  601. a[2] = 1;
  602. a[6] = 1;
  603. a[5] = 1;
  604. }
  605. if (t[k][j] == '5') {
  606. a[0] = 1;
  607. a[5] = 1;
  608. a[6] = 1;
  609. a[2] = 1;
  610. a[3] = 1;
  611. }
  612. if (t[k][j] == '6') {
  613. a[0] = 1;
  614. a[5] = 1;
  615. a[6] = 1;
  616. a[2] = 1;
  617. a[3] = 1;
  618. a[4] = 1;
  619. }
  620. if (t[k][j] == '7') {
  621. a[0] = 1;
  622. a[1] = 1;
  623. a[2] = 1;
  624.  
  625. }
  626. if (t[k][j] == '8') {
  627. a[0] = 1;
  628. a[1] = 1;
  629. a[2] = 1;
  630. a[3] = 1;
  631. a[4] = 1;
  632. a[5] = 1;
  633. a[6] = 1;
  634. }
  635. if (t[k][j] == '9') {
  636. a[0] = 1;
  637. a[1] = 1;
  638. a[2] = 1;
  639. a[3] = 1;
  640. a[5] = 1;
  641. a[6] = 1;
  642. }
  643. for (int z = 0; z < 7; z++)
  644. if (R[z] && a[z])
  645. ok = 0;
  646. }
  647.  
  648. if (ok)
  649. count++;
  650. }
  651. if (count == 4)
  652. is.push_back(ret[i]);
  653. }
  654. if (is.size() == 0)
  655. cout << "none" << endl;
  656. else {
  657. for (int i = 0; i < is.size() - 1; i++)
  658. cout << is[i] << " ";
  659. cout << is[is.size() - 1] << endl;
  660.  
  661. }
  662. is.clear();
  663.  
  664. }
  665.  
  666. }
  667. return 0;
  668.  
  669. }
Success #stdin #stdout 0.02s 2744KB
stdin
Standard input is empty
stdout
Standard output is empty