Stay Hungry,Stay Foolish!

C - Bingo 2

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;
}

 

posted @ 2024-05-25 22:55  lightsong  阅读(24)  评论(0编辑  收藏  举报
Life Is Short, We Need Ship To Travel