275A - Lights Out - CodeForces Solution


implementation *900

Please click on ads to support us..

Python Code:

mat=[[0,0,0,0,0]]
for i in range(3):
    mat.append([0]+list(map(int,input().split()))+[0])
mat.append([0,0,0,0,0])
eq=[]
for i in range(1,4):
    eq_row=[]
    for j in range(1,4):
        eq_row+=[mat[i][j]+mat[i+1][j]+mat[i-1][j]+mat[i][j+1]+mat[i][j-1]]
    eq.append(eq_row)
for i in range(3):
    for j in range(3):
        print((eq[i][j]+1)%2,end='')
    print('')

C++ Code:

#include<bits/stdc++.h>
using namespace std;

#define int long long

bool func(int i,int j){
    if((i>=0&&i<3)&&(j>=0&&j<3)){
   return true;
    }
    else 
    return  false;
}
int32_t main(){
int a[3][3];
for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
cin>>a[i][j];
    }
}
int ans[3][3];
for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
        ans[i][j] = 1;
    }
}

for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
        if(a[i][j]%2==1){
            ans[i][j]=ans[i][j]^1;
        if(func(i,j+1)){  // adjacent  possible or not
            ans[i][j+1]=ans[i][j+1]^1;
        }
        if(func(i+1,j)){
            ans[i+1][j]=ans[i+1][j]^1;
        }
        if(func(i-1,j)){
            ans[i-1][j]=ans[i-1][j]^1;
        }
        if(func(i,j-1)){
            ans[i][j-1]=ans[i][j-1]^1;
        }
        }
     
        }
}
for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
        cout<<ans[i][j];
    }
    cout<<endl;
}
return 0;
}


Comments

Submit
0 Comments
More Questions

1183A - Nearest Interesting Number
1009E - Intercity Travelling
1637B - MEX and Array
224A - Parallelepiped
964A - Splits
1615A - Closing The Gap
4C - Registration System
1321A - Contest for Robots
1451A - Subtract or Divide
1B - Spreadsheet
1177A - Digits Sequence (Easy Edition)
1579A - Casimir's String Solitaire
287B - Pipeline
510A - Fox And Snake
1520B - Ordinary Numbers
1624A - Plus One on the Subset
350A - TL
1487A - Arena
1520D - Same Differences
376A - Lever
1305A - Kuroni and the Gifts
1609A - Divide and Multiply
149B - Martian Clock
205A - Little Elephant and Rozdil
1609B - William the Vigilant
978B - File Name
1426B - Symmetric Matrix
732B - Cormen --- The Best Friend Of a Man
1369A - FashionabLee
1474B - Different Divisors