목록Algorithm/Problem Solving (95)
블로그 옮겼습니다
문제 링크 N > y; ps[i] = {x, y}; vx[i] = x, vy[i] = y; } sort(all(vx)), sort(all(vy)); for(int i = 0 ; i
문제 링크 \(1 A[i]; while(!dq.empty() && dq.front() = A[i]) dq.pop_back(); dq.push_back(i); cout
문제 링크 N
문제 링크 \(1 L; pos.resize(N); for(int i = 0 ; i > pos[i]; auto s = upper_bound(all(pos), 0); auto m = upper_bound(all(pos), L / 2); vector ss = vector(s, m); vector ee = vector(m, pos.end()); reverse(all(ee)); for(int i = 0 ; i
https://community.topcoder.com/stat?c=problem_statement&pm=11817 A, B, X
http://codeforces.com/contest/831/problem/E N > N; for(int i = 1 ; i > a; idxs[a].push_back(i); st.insert(a); update(i, 1); } int pos = 0; ll ans = 0; nums.assign(all(st)); for(int i = 0 ; i
http://codeforces.com/contest/112/problem/D N x >> d; int cnt = 0; for(int j = 1; j * j
http://codeforces.com/contest/732/problem/E N
http://codeforces.com/contest/277/problem/E 2 src = src; this->sink = sink; } bool spfa(){ vector inQ = vector(size, false); queue q; q.push(src); inQ[src] = true; dist[src] = 0; while(!q.empty()){ int here = q.front(); q.pop(); inQ[here] = false; for(int i = 0 ; i 0 && dist[here] + e.cost b.y;}vector points;int N;int NODE(int x){return 2 + x;}int IN(int x){return 2 * x;}int OUT(int x){return 2 ..
https://www.hackerrank.com/contests/w6/challenges/best-spot/problem 우선 FFT 코드는 명우님의 블로그의 코드를 참고했음을 알립니다. http://blog.myungwoo.kr/54 이 문제는 FFT를 모르면 절대 풀 수 없어 보이고, 안다면 단순한 구현문제로 전락해 버린다.우선 naive 하게 생각해 보았을 때 모든 위치에서 답을 계산해 보면 O((RC)^2) 의 시간이 걸린다.R, C가 최대 500 이기 때문에 시간안에 절대 돌 수 없다.FFT를 사용하면 O(RClgRC) 의 시간이 걸리게 되어 시간안에 돌게 된다. 우선 squared difference (x-y)^2 의 식을 풀어보면 x^2 - 2xy + y^2 이라는 것을 알 수가 있다.어차피..