0w1

GCJ 2016 R1A pB. Rank and File ( Adhoc )

Dashboard - Round 1A 2016 - Google Code Jam
The constraints were small ( T ≤ 50, N ≤ 50, H ≤ 2500 ) so I stuck and thought it could be solved by some brute force methods. However, if the point is reached, it will very easy. Thinking it clearly, initially for all elements in each cell, their count will be an even number ( one counted by column and another counted by row ), and if any row or column is removed, the count of each element in the removed array will be an odd number for sure. So if we take out all such odd numbers and sort, the answer will appear.

#include <bits/stdc++.h>
using namespace std;
const int MAXN = 50 + 2;
const int MAXH = 2500 + 5;

int n;
int occ[ MAXH ];

int main(){
    int T; scanf("%d", &T);
    for( int kase = 1; kase <= T; ++kase ){
        memset( occ, 0, sizeof( occ ) );
        printf("Case #%d: ", kase);
        scanf("%d", &n);
        for( int i = 0; i < 2 * n - 1; ++i )
            for( int j = 0; j < n; ++j ){
                int h; scanf("%d", &h);
                ++occ[ h ];
            }
        vector< int > ans;
        for( int i = 0; i <= 2500; ++i )
            if( occ[ i ] & 1 )
                ans.push_back( i );
        sort( ans.begin(), ans.end() );
        for( int i = 0; i < ans.size(); ++i )
            printf("%d%c", ans[ i ], i == ans.size() - 1 ? '\n' : ' ');
    }
    return 0;
}