본문 바로가기

코드포스

(37)
[Codeforces Round 886 (Div. 4)] F. We Were Both Children https://codeforces.com/blog/entry/118466 Codeforces Round #886 (Div. 4) Editorial - Codeforces codeforces.com ※. ai 가 n을 넘어가면 잡을 수 없다. (트랩은 n까지만 설치할 수 있다.) ※.1부터 n까지 곱을 cnt에 저장해준다. (i의 개수가 1이라면 i * x 의 개수에도 1을 더해준다.) (이 연산의 시간복잡도는 nlogn이다.) import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main { static int Answer; public static void ..
[Educational Codeforces Round 149 (Rated for Div. 2)] C. Best Binary String https://codeforces.com/blog/entry/116752 Educational Codeforces Round 149 Editorial - Codeforces codeforces.com 011110010 0[1110010] -> 00[100]111 -> 00001111 ※ 문자열에 [10]을 최대한 없애야한다. (110, 010) ※. [10] 이 있다면 같은수끼리 뭉치게 만든다. (111000, 100000, 111110, 반전했을때 가장 적은수로 오름차순) ※. 문자열에 ? 가 있는곳은 전의 문자를 붙인다. import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.Arrays; import java..
[Educational Codeforces Round 149 (Rated for Div. 2)] B. Comparison String https://codeforces.com/blog/entry/116752 Educational Codeforces Round 149 Editorial - Codeforces codeforces.com ※ >>> : 3 (3 2 1 3 2 1) ※. , > 일 때 >>일 경우 3-2-1, >>{ 와 개수가 같기 때문에) (>>>,
[Codeforces Round 863 (Div. 3)] E. Living Sequence https://codeforces.com/blog/entry/114788 int main() { std::ios::sync_with_stdio(false); std::cin.tie(0); int32_t num_tests; std::cin >> num_tests; for(int32_t t = 0; t > k; std::vector digits; while(k > 0) { digits.push_back(k % 9); k /= 9; } std::reverse(digits.begin(), digits.end()); for(int32_t i = 0; i < digits.size(); i++) std::cout 0, k / 9 연산은 다음 자..
[Codeforces Round 849 (Div. 4)] D. Distinct Split https://codeforces.com/blog/entry/112282 Codeforces Round #849 (Div. 4) Editorial - Codeforces codeforces.com #include "bits/stdc++.h" using namespace std; #define ll long long #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(),v.rend() #define pb push_back #define sz(a) (int)a.size() void solve() { int n; string s; cin >> n >> s; vector cnt(26, 0), p(26, 0); for(auto x: s) cnt[x - 'a'..
[Hello 2023] D. Boris and His Amazing Haircut ※. a[i] 5 3 3 3 -> 5 3 1 1 -> 1,3 pop -> 5 3 1 5 [5,3,1]) ※. a[i]와 b[i]가 같으면 b[i]보다 작은 수만 빼주면 된다. ※. 스택 대신 TreeSet도 가능 (treeset.headSet(b[i]).clear() -> b[i]보다 작은수를 반환 후 전부 제거한다...
[Codeforces Round #842 (Div. 2)] D. Lucky Permutation https://www.acmicpc.net/problem/25577 25577번: 열 정렬정렬 정 첫 번째 줄에 배열의 크기 $N(4 ≤ N​ ≤ 100\,000)$이 주어진다. 그다음 줄에 배열의 원소 $A_1, A_2, \cdots, A_n (-10^9 ≤ A_i ≤ 10^9, i \neq j $ 이면 $ A_i \neq A_j )$ 이 주어진다. 배열의 원소는 모두 정수이다 www.acmicpc.net import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.St..
[Codeforces Round #842 (Div. 2)] B. Quick Sort ※. 올바른 자리에 없는 원소들은 전부 작업을 거쳐야 한다. (1, 5, 2, 3, 4) ※. 올바르지 않은 원소들 중 가장 작은것부터 넣어야 한다. (1,5,2,3,4 -> 1 - 2 3 - 4 5 작업이 끝나면 정렬 완료) ※. 배열을 탐색하며 순서대로 있는 원소는 작업하지 않는다. (x,1,y,2,z,3 -> 1,2,3 - x y z 1 2 3 은 원소를 뺄 때 정렬) ※. n개의 배열 중 순서대로 있는 원소(w)를 뺀 후 작업해야 하는 나머지 원소(n-w)를 k로 나누어 준다. (+k 는 정렬해야 할 배열이 k개 미만일 때도 최소 1번의 작업을 해야하기 때문에) import java.io.BufferedReader; import java.io.InputStreamReader; import java..