top of page

2021 CCC S2/J5: Modern Art

Updated: Oct 24, 2021


Data structure:

bool grid[m+1][n+1] , B is false, G is true

bool rowCommand[m+1], false is not change, true is change for ith row

bool colCommand[n+1], false is not change, true is change for ith column.


input R and C command, only do once change for ith row or column.

for loop the rowCommand[m+1], if ith is true, change grid[i][x] to !grid[i][x]

for loop thecolCommand[n+1], if ith is true, change grid[x][i] to !grid[x][i]


count grid[m+1][n+1] "true", this is the result.


#include <iostream>

#include <string.h>

using namespace std;


int main() {

int m = 0;

int n = 0;

cin >> m;

cin >> n;

bool rcmds[m+1];

bool ccmds[n+1];

memset(rcmds, false, m+1);

memset(ccmds, false, n+1);

int k;

cin >> k;

char letter;

int num;

for(int i = 0; i < k; i++){

cin >> letter;

cin >> num;

if(letter == 'R'){

rcmds[num] = !rcmds[num];

}

else{

ccmds[num] = !ccmds[num];

}

}


bool grid[m+1][n+1];

for(int i = 1; i <= m; i++){

for(int j = 1; j <= n; j++){

grid[i][j] = false;

}

}

for(int i = 1; i <= m; i++){

if(rcmds[i]){

for(int j = 1; j <= n; j++){

grid[i][j] = !grid[i][j];


}


}

}


for(int i = 1; i <= n; i++){

if(ccmds[i]){

for(int j = 1; j <= m; j++){

grid[j][i] = !grid[j][i];

}


}

}


int result = 0;

for(int i = 1; i <=m; i++){

for(int j = 1; j <= n; j++){

if(grid[i][j]){

result += 1;

}


}


}

cout<<result<<endl;

return 0;

}



Recent Posts

See All

CCC '24 J5 - Harvest Waterloo

#include<iostream> #include <vector> #include <algorithm> #include <cmath> #include <stack> using namespace std; int main() { int r, c,...

CCC '24 J4 - Troublesome Keys

s1 = input() s2 = input() silly = '' silly_o = '' quiete = '-' i = 0 j = 0 while i < len(s1) and j < len(s2): if s1[i] != s2[j]: if...

CCC '22 J5 - Square Pool

#include<iostream> #include <vector> #include <algorithm> #include <cmath> using namespace std; bool rowcom(pair<int, int> a, pair<int,...

Comments


One-time Donations
I hope I can solve all CCC problems!,
Please e-transfer cccottawa862008@gmail.com

Subscribe to AIOICode newsletter

I'm a title. ​Click here to edit me.

Thanks for submitting!

  • Twitter
  • Facebook
  • Linkedin

© 2023 by AIOICode.

bottom of page