Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define x first
- #define y second
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- int n;
- string s;
- cin >> n >> s;
- int teclado[5][4];
- pair<int, int> vetor[10][10], pos[10];
- for (int i = 0; i < 5; i++)
- for (int j = 0; j < 4; j++)
- teclado[i][j] = -1;
- teclado[1][1] = 1;
- teclado[1][2] = 2;
- teclado[1][3] = 3;
- teclado[2][1] = 4;
- teclado[2][2] = 5;
- teclado[2][3] = 6;
- teclado[3][1] = 7;
- teclado[3][2] = 8;
- teclado[3][3] = 9;
- teclado[4][2] = 0;
- for (int i = 0; i <= 9; i++) {
- for (int j = 1; j < 5; j++) {
- for (int k = 1; k < 4; k++) {
- if (teclado[j][k] == i) pos[i] = {j, k};
- }
- }
- }
- for (int i = 0; i <= 9; i++) {
- for (int j = 0; j <= 9; j++) {
- vetor[i][j] = {pos[i].x - pos[j].x, pos[i].y - pos[j].y};
- }
- }
- for (int i = 0; i <= 9; i++) {
- if (i != s[0] - '0') {
- string c = "";
- c += i + '0';
- auto p = pos[i];
- bool valid = true;
- for (int j = 0; j < n - 1; j++) {
- p.x += vetor[s[j + 1] - '0'][s[j] - '0'].x;
- p.y += vetor[s[j + 1] - '0'][s[j] - '0'].y;
- if (1 <= p.x && p.x <= 4 && 1 <= p.y && p.y <= 3 && teclado[p.x][p.y] != -1) {
- c += teclado[p.x][p.y] + '0';
- } else {
- valid = false;
- break;
- }
- }
- if (valid && c.length() == n) {
- cout << "NO" << endl;
- return 0;
- }
- }
- }
- cout << "YES" << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement