C - Bingo 2

lightsong發表於2024-05-25

C - Bingo 2

https://atcoder.jp/contests/abc355/tasks/abc355_c

思路

統計每行元素個數

統計每列元素個數

統計兩個對角線的元素個數

任意一個達到n,則滿足條件

Code

https://atcoder.jp/contests/abc355/submissions/53878562

#define int long long

int n, t;
vector<int> a;

map<int, int> rowcnt, colcnt;
int pdcnt = 0; // postive dignal cnt
int fdcnt = 0; // false dignal cnt


signed main()
{
    cin >> n >> t;

    for(int i=1; i<=t; i++){
        int temp;
        cin >> temp;
        
        a.push_back(temp);
        
        temp--;
        
        int x = temp / n + 1;
        int y = temp % n + 1;
        
//        cout << "x =" << x << endl;
//        cout << "y =" << y << endl;
        
        rowcnt[x]++;
        colcnt[y]++;
        
        if (rowcnt[x] == n){
            cout << i << endl;
            return 0;
        }

        if (colcnt[y] == n){
            cout << i << endl;
            return 0;
        }
    
        if (x == y){
            pdcnt++;
            
            if (pdcnt == n){
                cout << i << endl;
                return 0;
            }
        }
        
        if (x + y == n+1){
            fdcnt++;
            
            if (fdcnt == n){
                cout << i << endl;
                return 0;
            }
        }
    }

    cout << -1 << endl;

    return 0;
}

相關文章