1151B - Dima and a Bad XOR - CodeForces Solution


bitmasks brute force constructive algorithms dp *1600

Please click on ads to support us..

Python Code:

n, m = list(map(int, input().split()))
T = [[] for i in range(n)]
x = 0
d = [1] * n
for i in range(n):
    a = list(map(int, input().split()))
    T[i] = a
    x ^= a[0]
 
for i in range(n):
    for j in range(m):
        if x ^ T[i][0] ^ T[i][j] != 0:
            print('TAK')
            d[i] = j + 1
            print(*d)
            exit()
 
print('NIE')
 	 	       	  	  			 			  		

C++ Code:

#include<bits/stdc++.h>
using namespace std;
long long n, m, i, j, a[507][507], res, row, col;
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    
    cin >> n >> m;
    
    for(i = 1; i <= n; i++)
    {
        for(j = 1; j <= m; j++)
        {
            cin >> a[i][j];
        }
        
        res ^= a[i][1];
    }
    
    if(res)
    {
        cout << "TAK\n";
        for(i = 1; i <= n; i++) cout << "1 ";
        
        return 0;
    }
    
    for(i = 1; i <= n; i++)
    {
        for(j = 2; j <= m; j++)
        {
            if(a[i][j] != a[i][1])
            {
                res = 1;
                row = i;
                col = j;
                break;
            }
        }
        
        if(res == 1) break;
    }
    
    if(res)
    {
        cout << "TAK\n";
        for(i = 1; i <= n; i++)
        {
            if(row != i) cout << "1 ";
            else cout << col << " ";
        }
        
        return 0;
    }
    
    cout << "NIE";
}


Comments

Submit
0 Comments
More Questions

1612A - Distance
520A - Pangram
124A - The number of positions
1041A - Heist
901A - Hashing Trees
1283A - Minutes Before the New Year
1654D - Potion Brewing Class
1107B - Digital root
25A - IQ test
785A - Anton and Polyhedrons
1542B - Plus and Multiply
306A - Candies
1651C - Fault-tolerant Network
870A - Search for Pretty Integers
1174A - Ehab Fails to Be Thanos
1169A - Circle Metro
780C - Andryusha and Colored Balloons
1153A - Serval and Bus
1487C - Minimum Ties
1136A - Nastya Is Reading a Book
1353B - Two Arrays And Swaps
1490E - Accidental Victory
1335A - Candies and Two Sisters
96B - Lucky Numbers (easy)
1151B - Dima and a Bad XOR
1435B - A New Technique
1633A - Div 7
268A - Games
1062B - Math
1294C - Product of Three Numbers