0w1

CFR 689 A. Mike and Cellphone ( Ad hoc )

Problem - A - Codeforces
Trickiest problem in division 2 ever.
There were many different solutions, mine is a little easier than most of them.
Consider with 0 and without 0.
If there is no 0, it is essentially asking whether there are at least one number on each side of the 3 * 3 matrix or not.
If there is 0, and 1, 2, or 3 exists, it works as well.

void solve(){
    int N; cin >> N;
    string s; cin >> s;
    vi has( 10 );
    for( int i = 0; i < s.size(); ++i )
        has[ s[ i ] - '0' ] = 1;
    int a = has[ 1 ] or has[ 2 ] or has[ 3 ];
    int b = has[ 1 ] or has[ 4 ] or has[ 7 ];
    int c = has[ 3 ] or has[ 6 ] or has[ 9 ];
    int d = has[ 7 ] or has[ 9 ];
    if( a and b and c and d ) cout << "YES\n";
    else if( has[ 0 ] and a ) cout << "YES\n";
    else cout << "NO\n";
}