Created
March 13, 2023 12:57
-
-
Save hanjae-jea/3ce94f8f6d60087f67e37c08f0b776cd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require("fs"); | |
const input = fs.readFileSync("dev/stdin").toString(); | |
const lines = input.trim().split("\n"); | |
const N = Number(lines[0]); | |
const SWITCH = [undefined].concat(lines[1].trim().split(" ").map(Number)); | |
const M = Number(lines[2]); | |
for (let l = 3; l < 3 + M; l++) { | |
let [gender, num] = lines[l].trim().split(" "); | |
gender = Number(gender); | |
num = Number(num); | |
// 남자 | |
if (gender == 1) { | |
for (let i = num; i <= N; i = i + num) { | |
if (SWITCH[i] === 0) SWITCH[i] = 1; | |
else SWITCH[i] = 0; | |
} | |
} | |
// 여자 | |
else { | |
if (SWITCH[num] === 0) SWITCH[num] = 1; | |
else SWITCH[num] = 0; | |
for (let i = 1; ; i++) { | |
if (1 <= num - i && num + i <= N && SWITCH[num - i] === SWITCH[num + i]) { | |
if (SWITCH[num - i] === 0) { | |
SWITCH[num - i] = 1; | |
SWITCH[num + i] = 1; | |
} else { | |
SWITCH[num - i] = 0; | |
SWITCH[num + i] = 0; | |
} | |
} else { | |
// 둘이 다르면 더이상 진행 X | |
break; | |
} | |
} | |
} | |
} | |
let result = ""; | |
for (let i = 1; i <= N; i++) { | |
result += `${SWITCH[i]} `; | |
if (i % 20 == 0) result += "\n"; | |
} | |
console.log(result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment