2017-07-13から1日間の記事一覧

Codeforces Round #421B: Mister B and PR Shifts

http://codeforces.com/contest/819/problem/B傾きと切片を持って適当にやればいい…がvectorの形で保持したらTLEぎりぎりになってしまった。 累積和でやりましょう。 あとmodの条件もいろいろ勘違いして結構バグらせた。 modは1違うだけで値が劇的に変わった…

Codeforces Round #419C: Karen and Supermarket

http://codeforces.com/contest/815/problem/C3乗っぽいけど2乗な木dp。 5000*5000*2のlong longの配列持ったらMLEした。 さらに初期化を適当にやりすぎてO(N^3)になってしまった。 直してAC。 int N, B; vector<int> G[MAX_N]; int dp[MAX_N][MAX_N][2]; int dp2</int>…

Codeforces Round #423B: High Load

http://codeforces.com/contest/827/problem/B最初にrootを一つ決めて、あとはkコずつrootからまんべんなくつけていけば、木の高さが最小、かつその時の一番rootから離れているedgeの個数も最小になるのでこれが求めるグラフとなる。 int N, K; void solve()…

Codeforces Round #423C: DNA Evolution

http://codeforces.com/contest/827/problem/Ce int n; ll sum(ll *bit, int i) { ll s = 0; while(i > 0) { s += bit[i]; i -= i & -i; } return s; } void add(ll *bit, int i, ll x) { while(i <= n) { bit[i] += x; i += i & -i; } } struct query { int…