본문 바로가기

코드포스

[코드포스 Practice7] B. Fake NP 어.. 이거 딱봐도 2인데??? 해서 바로 2출력했다가 틀렸다. 홀수일 경우를 빼먹어서 홀수인 경우에는 자기자신을 출력하게 했다. #include using namespace std; int main() { int l, r; cin >> l >> r; if(l == r) cout 더보기
[코드포스 Practice7] A. A pile of stones #include #include #include #include #include #include using namespace std; using i64 = long long; int main() { int n; scanf("%d", &n); //printf("%d", n); string s; cin >> s; int count = 0; for(int i = 0; i < s.size(); i++){ if(s[i] == '-') count--; else count++; count = max(count, 0); } printf("%d", count); return 0; } 쉬워서 이제 쓴다. -이면 --하고 +이면 ++ 하는데 음수가 되면 안되니깐 음수이면 0으로 바꿔준다. 더보기
[코드포스 Practice7] E. Bear and Forgotten Tree 3 겁 먹고 패스한 문제 겁쟁이 풀어보니 그리 어려운 문제가 아니었다. 이해하는데 조금 시간이 걸리고 조건이 좀 있었을 뿐 일단 -1 조건부터 정의해줬다. 높이의 2배보다 d가 클 수 없으니 이 때는 -1을 출력하고 종료한다. 또 쉬운게 이게 이진트리처럼 자식의 개수가 정해져 있는게 아니다. 그래서 부모 노드에 따닥따닥 붙어있어도 된다. 그래서 기본적으로 1번 노드에 자식노드를 붙이고 h와 d조건만 따로 만족시켜준다. 하지만 두 부분에서 빠트린 조건이 있었음.. 만약 이걸 대회중에 풀었다면 조건 못 찾아서 틀렸을 것 같다. 하나는 d와 h가 같을 때 내가 푼 대로 풀면 기본적으로 1번 노드에 자식 노드가 붙어있어서 d가 4가 되고만다. 그래서 그 때는 2번 노드에 자식노드를 붙이면 d와 h가 같아질 수 있다.. 더보기
[코드포스 Practice7] D. Array Splitting You are given a sorted array a1,a2,…,ana1,a2,…,an (for each index i>1i>1 condition ai≥ai−1ai≥ai−1 holds) and an integer kk. You are asked to divide this array into kk non-empty consecutive subarrays. Every element in the array should be included in exactly one subarray. Let max(i)max(i) be equal to the maximum in the ii-th subarray, and min(i)min(i) be equal to the minimum in the ii-th subarray... 더보기
[코드포스 Practice7] C. Chewbaсca and Number Luke Skywalker gave Chewbacca an integer number x. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit t means replacing it with digit 9 - t. Help Chewbacca to transform the initial number x to the minimum possible positive number by inverting some (possibly, zero) digits. The decimal representation of the final number shouldn't start with a zero. Input The fir.. 더보기
[코드포스 Practice7] 후기 오랜만의 코포~~ 시험기간동안 못 풀고 끝나니 과제 생겨서 못 풀고 이제야 푼다. 보통 문제풀 때 긴장해서 파들파들 떨면서 푸는데 오늘은 떨리지는 않았다. 그래서 A랑 B번은 빠르게 넘겼음. 먼저 입출력 예시부터 적고 읽으면서 문제 이해하고.. 그 다음 C번 푸는데 C번 맞왜틀이었음ㅋㅋㅋ 아 이게 맞는데?? 왜 계속 틀리지?? 뭐가 문제지?? 그러다 한 한시간 반 쯤 남기고 D번 풀려고 했었다. D번 딱 보자마자 파라매트릭 서치 생각났다. 최솟값 구하는 거고 전에 푼 공유기 문제도 생각나고.. 그런데 푼 지 너무 오래돼서 어떻게 하지 고민하다가 다시 C번이나 풀자해서 다시 C번으로 돌아왔다. C번 0과 9만 있는 경우 빠트린거 발견해서 추가했는데 또 틀림.. 그래서 이제는 E번을 봤다. E번 읽다가 빠른.. 더보기
[코드포스 Practice6] E. Little Pony and Expected Maximum 하루 고민해봤지만 모르므로 패스.. 7번 코포 풀고 다시 봐야겠다 더보기
[코드포스 Practice6] D. Berstagram Polycarp recently signed up to a new social network Berstagram. He immediately published nn posts there. He assigned numbers from 11 to nn to all posts and published them one by one. So, just after publishing Polycarp's news feed contained posts from 11 to nn — the highest post had number 11, the next one had number 22, ..., the lowest post had number nn. After that he wrote down all likes from .. 더보기