๋ฌธ์
์ฝ๋
#include <string>
#include <vector>
using namespace std;
vector<int> solution(int rows, int columns, vector<vector<int>> queries) {
vector<int> answer;
vector<int>v[10001];
int num = 1;
for(int i=0; i<rows; i++){
for(int k=0; k<columns; k++){
v[i].push_back(num);
num++;
}
}
for(int i=0; i<queries.size(); i++){
int min_value = 1e9;
int x1 = queries[i][0]-1, y1 = queries[i][1]-1;
int x2 = queries[i][0]-1, y2 = queries[i][3]-1;
int x3 = queries[i][2]-1, y3 = queries[i][3]-1;
int x4 = queries[i][2]-1, y4 = queries[i][1]-1;
int temp = v[x1][y1];
for(int i=x1; i<x4; i++){
v[i][y1] = v[i+1][y1];
min_value = min(min_value, v[i][y1]);
}
for(int i=y4; i<y3; i++){
v[x3][i] = v[x3][i+1];
min_value = min(min_value, v[x3][i]);
}
for(int i=x3; i>x2; i--){
v[i][y3] = v[i-1][y3];
min_value = min(min_value, v[i][y3]);
}
for(int i=y2; i>y1; i--){
v[x2][i] = v[x2][i-1];
min_value = min(min_value, v[x2][i]);
}
v[x1][y1+1] = temp;
min_value = min(min_value, temp);
answer.push_back(min_value);
}
return answer;
}
ํ์ด
์ด์ ์ ํ์๋ ๋ฐฑ์ค์ ๋ฐฐ์ด ๋๋ฆฌ๊ธฐ1 ๋ฌธ์ ์์ ๋ฐฉํฅ๋ง ๊ฑฐ๊พธ๋ก ๋ ๋ฌธ์ ์์ต๋๋ค.
์ด๋ฐ ๋ฐฐ์ด ๋๋ฆฌ๊ธฐ ๋ฌธ์ ๋ ํญ์ ํ์ฌ ์์์ ๊ฐ์ ์ด์ ์์์ ๊ฐ์ผ๋ก ๊ฐฑ์ ์์ผ ์ฃผ๋ฉด์ ์งํํด์ผ ํฉ๋๋ค.
๋ฐ์๊ณ ๋ฐฉํฅ์ผ๋ก ๋์๊ฐ๋ ๊ฒฝ์ฐ๋ ์ ๊ฒ์๊ธ ๋งํฌ์์ ์์ธํ ์ ๋ฆฌํ ์ ์์ผ๋ ์ฐธ๊ณ ๋ฐ๋๋๋ค.
1 2 3
4 5 6
7 8 9
์ ๋ฐฐ์ด์ ์๊ณ๋ฐฉํฅ์ผ๋ก ํ์ ํ๋ ๊ฒฝ์ฐ๋ฅผ ์๋ก ๋ค์ด ํ๋ฒ ์ ๋ฆฌํด ๋ณด๊ฒ ์ต๋๋ค.
'Algorithm ๐ง๐ปโ๐ป > ํ๋ก๊ทธ๋๋จธ์ค(Programmers)' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[c++] ํ๋ก๊ทธ๋๋จธ์ค - ํฌ๋ ์ธ ์ธํ๋ฝ๊ธฐ ๊ฒ์(Level 1) (0) | 2022.04.10 |
---|---|
[c++] ํ๋ก๊ทธ๋๋จธ์ค - ํคํจ๋ ๋๋ฅด๊ธฐ(Level 1) (0) | 2022.04.10 |
[c++] ํ๋ก๊ทธ๋๋จธ์ค - ์ ๊ณ ๊ฒฐ๊ณผ ๋ฐ๊ธฐ(Level 1) (0) | 2022.04.08 |
[c++] ํ๋ก๊ทธ๋๋จธ์ค - [1์ฐจ] ์บ์(Level 2) (0) | 2022.04.07 |
[c++] ํ๋ก๊ทธ๋๋จธ์ค - ํ๋ฆฐํฐ(Level 2) (0) | 2022.03.23 |
[c++] ํ๋ก๊ทธ๋๋จธ์ค - ์ผ๊ฐ ๋ฌํฝ์ด(Level 2) (0) | 2022.03.14 |
๋๊ธ