codeforces

codeforces #406 B. Not Afraid

方針 各グループについて、絶対値が等しい正負の値のペアが存在するか探索。 ペアが存在するグループは少なくとも全員がtraitorというわけではない。 ペアが存在しない場合は、グループ全員がtraitorの可能性がある。 一つのグループでも、グループ全員がtra…

codeforces #406 A. The Monster

方針 法則性とか考えないで総当りでいけるっぽい #include <iostream> #include <vector> #include <algorithm> using namespace std; typedef long long ll; int main() { int a, b, c, d; cin >> a >> b >> c >> d; int ans = -1; for(int i=0;i<1000;i++) { bool flag = false; for(int</algorithm></vector></iostream>…

Codeforces #405 C. Bear and Different Names

方針 まず、n個の異なる名前を用意。 i番目が"NO"なら、ans[i+k-1] = ans[i]とするとi番目以外のk個のグループには影響がない。 ここで、ans[i] = ans[i+k-1]とすると、ans[i+k-1]が後から更新された場合にこまる。 自分の回答 #include <iostream> #include <vector> #include <algorithm></algorithm></vector></iostream>…

Codeforces #405 B. Bear and Friendship Condition

方針 グラフ中の全ての部分グラフ?で (辺の数)= (頂点の数)*(頂点の数-1) / 2 を満たしていれば “YES"、そうでなければ "NO"と出力。 全探索するために配列 vis[頂点の数] を用意。 dfsでは一つの辺に対して二回ずつカウントしている。 つまり、cnt_e…

Codeforces #403 C. Andryusha and Colored Balloons

方針 解けなかったので他の人の解答をみた。 #include <iostream> #include <vector> #include <set> using namespace std; set<int> c[200010]; vector<int> g[200010], p(200010, 0), a(200010, 0); void dfs(int cur, int pre) { if(pre != -1) { while(c[pre].count(p[pre])) p[pre]++; a[</int></int></set></vector></iostream>…