Skip to content
This repository was archived by the owner on Feb 22, 2022. It is now read-only.

Commit bf512d2

Browse files
Merge pull request #404 from boostcamp-ai-tech-4/sally-220122
[์ƒ๋ฆฌ] 2022.01.22
2 parents fe549c2 + b6e85d3 commit bf512d2

File tree

3 files changed

+109
-0
lines changed

3 files changed

+109
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include <string>
2+
#include <vector>
3+
#include <iostream>
4+
#include <algorithm>
5+
using namespace std;
6+
7+
vector<int> solution(vector<string> grid) {
8+
vector<int> answer;
9+
int dir[4][2] = {{-1,0},{0,1},{1,0},{0,-1}};
10+
11+
// init
12+
int N = grid.size();
13+
int M = grid[0].size();
14+
15+
int visit[501][501][4] = {false,};
16+
int arr[501][501] = {0,};
17+
for(int i = 0; i < N; i++)
18+
for(int j = 0; j < M; j++){
19+
if(grid[i][j] == 'S') arr[i][j] = 0;
20+
else if(grid[i][j] == 'L') arr[i][j] = -1;
21+
else if(grid[i][j] == 'R') arr[i][j] = 1;
22+
}
23+
24+
// check all cases
25+
for(int i = 0; i < N; i++)
26+
for(int j = 0; j < M; j++)
27+
for(int k = 0; k < 4; k++){ // light direction
28+
int cur_dir = k, cur_x = i, cur_y = j;
29+
int cnt = 0;
30+
if(visit[cur_x][cur_y][cur_dir]) continue;
31+
while(1){
32+
if(visit[cur_x][cur_y][cur_dir]) break;
33+
visit[cur_x][cur_y][cur_dir] = true;
34+
cnt++;
35+
36+
cur_x = (cur_x + dir[cur_dir][0] + N) % N;
37+
cur_y = (cur_y + dir[cur_dir][1] + M) % M;
38+
39+
cur_dir = (cur_dir + arr[cur_x][cur_y] + 4) % 4;
40+
}
41+
answer.push_back(cnt);
42+
}
43+
44+
sort(answer.begin(), answer.end());
45+
return answer;
46+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <string>
2+
#include <vector>
3+
#include <algorithm>
4+
#include <iostream>
5+
using namespace std;
6+
7+
bool solution(vector<string> phone_book) {
8+
bool answer = true;
9+
10+
int size_ = phone_book.size();
11+
sort(phone_book.begin(), phone_book.end());
12+
13+
for (int i = 0; i < size_-1; i++) {
14+
int s = phone_book[i].size();
15+
if (phone_book[i].compare(phone_book[i+1].substr(0, s)) == 0)
16+
return false;
17+
}
18+
19+
return answer;
20+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include <iostream>
2+
#include <string>
3+
#include <vector>
4+
#include <queue>
5+
#include <math.h>
6+
#include <algorithm>
7+
8+
using namespace std;
9+
10+
int solution(vector<int> priorities, int location) {
11+
int answer = 0;
12+
int remain[10] = { 0, };
13+
pair<int, bool> target;
14+
queue<pair<int, bool>> q;
15+
16+
for (int i = 0; i < priorities.size(); i++) {
17+
remain[priorities[i]]++;
18+
19+
if (i == location) q.push({ priorities[i], true });
20+
else q.push({ priorities[i], false });
21+
}
22+
23+
while (1) {
24+
target = q.front();
25+
q.pop();
26+
27+
bool pushed = false;
28+
for (int i = 9; i > target.first; i--) { // ๋” ํฐ ์šฐ์„ ์ˆœ์œ„๊ฐ€ ์žˆ๋Š”์ง€ ํ™•์ธ
29+
if (remain[i] > 0) {
30+
q.push(target);
31+
pushed = true;
32+
break;
33+
}
34+
}
35+
if (pushed == false) {
36+
answer++;
37+
remain[target.first]--;
38+
if (target.second == true) return answer;
39+
}
40+
}
41+
42+
return answer;
43+
}

0 commit comments

Comments
ย (0)