Skip to content

10 kang #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions 10/kang/1253.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include <iostream>
#include <map>
#include <vector>

using namespace std;

int N;
int a[2003];
map<int, int> tSum;
int zeroCnt;
int answer;

int main() {

cin >> N;
for(int i = 0; i < N; i++) {
cin >> a[i];
if(a[i] == 0)
zeroCnt++;
}

for(int i = 0; i < N - 1; i++) {
for(int j = i + 1; j < N; j++) {
tSum[a[i] + a[j]]++;
}
}

for(int i = 0; i < N; i++) {
//합이 존재하는데, a[i] != 0 -> a[i] + 0 = a[i] 가 아닌 조합이 존재해야 하므로 zeroCnt != tSum[a[i]]이면 다른 조합이 존재 하는 것
//다만 a[i] == 0 이면 zeroCnt에서 나 자신 1개를 빼주고 비교
if(tSum.find(a[i]) != tSum.end() && ((a[i] != 0 && tSum[a[i]] != zeroCnt) || (a[i] == 0 && tSum[a[i]] != zeroCnt - 1)) ) {
answer++;
}
}

cout << answer;

return 0;
}
47 changes: 47 additions & 0 deletions 10/kang/12789.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include <iostream>
#include <stack>

using namespace std;

int N;
int order[1003];
stack<int> st;
int idx = 1;

int main() {
cin >> N;

for(int i = 0; i < N; i++) {
cin >> order[i];
}

for(int i = 0; i < N; i++) {
if(idx < order[i]) {
while(!st.empty()) {
if(idx != st.top()) {
break;
}else {
st.pop();
idx++;
}
}
st.push(order[i]);
}else if(idx == order[i]) {
idx++;
}
}

while(!st.empty()) {
if(idx != st.top()) {
break;
}else {
st.pop();
idx++;
}
}
if(idx != N + 1)
cout << "Sad\n";
else
cout << "Nice\n";
return 0;
}
48 changes: 48 additions & 0 deletions 10/kang/14267.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int n, m;
vector<int> adj[100003];
int score[100003];

void bfs() {
queue<int> q;
int x;

q.push(1);
while(!q.empty()) {
x = q.front();
q.pop();
for(int nx : adj[x]) {
score[nx] += score[x];
q.push(nx);
}
}
}

int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int idx, w;

cin >> n >> m;
cin >> idx;
for(int i = 2; i <= n; i++) {
cin >> idx;
adj[idx].push_back(i);
}
for(int i = 0; i < m; i++) {
cin >> idx >> w;
score[idx] += w;
}

bfs();
for(int i = 1; i <= n; i++) {
cout << score[i] << " ";
}
cout << "\n";
return 0;
}
30 changes: 30 additions & 0 deletions 10/kang/p12927.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <string>
#include <vector>
#include <queue>

using namespace std;

long long solution(int n, vector<int> works) {
long long answer = 0;
priority_queue<int> pq;
int wSize = works.size();
for(int i = 0; i < wSize; i++) {
pq.push(works[i]);
}

while(n--) {
if(pq.empty())
break;
int x = pq.top();
pq.pop();
if(x > 1)
pq.push(x - 1);
}

while(!pq.empty()) {
int x = pq.top();
answer += x * x;
pq.pop();
}
return answer;
}
90 changes: 90 additions & 0 deletions 10/kang/p388353.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#include <string>
#include <vector>
#include <queue>
#include <cstring>

using namespace std;

int n, m;
char st[55][55];
bool visit[55][55];
int d[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};

void bfs(char a) {
queue<pair<int, int>> q;
queue<pair<int, int>> delQ;
memset(visit, 0, sizeof(visit));
int x, y, nx, ny;

q.push({0, 0});
visit[0][0] = true;
while(!q.empty()) {
x = q.front().first;
y = q.front().second;
q.pop();
for(int i = 0; i < 4; i++) {
nx = x + d[i][0];
ny = y + d[i][1];
if(nx < 0 || nx >= n + 2 || ny < 0 || ny >= m + 2)
continue;
if(visit[nx][ny])
continue;
if(st[nx][ny] == a) { // ' ' 외부와 연결된 a이면 delQ에 넣기
visit[nx][ny] = true;
delQ.push({nx, ny});
continue;
}
if(st[nx][ny] == ' ') { //' ' 외부로부터 갈 수 있는 경로면 탐색
q.push({nx, ny});
visit[nx][ny] = true;
}
}
}

while(!delQ.empty()) { //꺼낼 a들을 꺼내줌
x = delQ.front().first;
y = delQ.front().second;
delQ.pop();
st[x][y] = ' ';
}
}

int solution(vector<string> storage, vector<string> requests) {
int answer = 0;
int rSize = requests.size();
n = storage.size();
m = storage[0].size();

//테두리를 ' '로 채운 char 배열
for(int i = 0; i < n + 2; i++) {
fill(st[i], st[i] + m + 2, ' ');
}
for(int r = 1; r <= n; r++) {
for(int c = 1; c <= m; c++) {
st[r][c] = storage[r - 1][c - 1];
}
}

for(int i = 0; i < rSize; i++) {
if(requests[i].size() == 1) {
bfs(requests[i][0]);
}else {
for(int r = 0; r < n + 2; r++) {
for(int c = 0; c < m + 2; c++) {
if(st[r][c] == requests[i][0]) {
st[r][c] = ' ';
}
}
}
}
}

for(int r = 0; r < n + 2; r++) {
for(int c = 0; c < m + 2; c++) {
if(st[r][c] != ' ') {
answer++;
}
}
}
return answer;
}