[ 나의 코드 ]
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
vector<string> solution(int n, vector<int> arr1, vector<int> arr2) {
vector<string> answer;
vector<vector<int>> answer1,answer2;
answer1.resize(n);
for(int i=0;i<n;i++)
{
int j=0;
answer1[i].resize(n,0);
int num = arr1[i];
while(num != 0)
{
answer1[i][j++]=num%2;
num=num/2;
}
reverse(answer1[i].begin(), answer1[i].end());
}
answer2.resize(n);
for(int i=0;i<n;i++)
{
int j=0;
answer2[i].resize(n,0);
int num = arr2[i];
while(num != 0)
{
answer2[i][j++]=num%2;
num=num/2;
}
reverse(answer2[i].begin(), answer2[i].end());
}
answer.resize(n);
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(answer1[i][j] == 1 || answer2[i][j] == 1)
{
answer[i].push_back('#');
}else{
answer[i].push_back(' ');
}
}
}
return answer;
}
[ 최적 코드 ]
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
vector<string> solution(int n, vector<int> arr1, vector<int> arr2) {
vector<string> answer;
for(int i=0;i<n;i++)
{
arr1[i] = arr1[i] | arr2[i];
string ans = "";
for(int j=0;j<n;j++)
{
if(arr1[i]%2 == 0) ans = ' ' + ans;
else ans = '#' + ans;
arr1[i] = arr1[i] >> 1;
}
answer.push_back(ans);
}
return answer;
}