2018-04-04から1日間の記事一覧

E. Mahmoud and Ehab and the xor-MST | Codeforces Round #473 (Div. 2)

まず最上位ビットについて考えてみよう。最上位ビットが異なる頂点同士を結ぶと、ほかの全てのビットが異なる頂点同士を結ぶよりも高コストなので、できるだけ少なく済ませたい。そこで0b0???のグループと0b1???のグループに分けてそれぞれ木になっていると…

D. Mahmoud and Ehab and another array construction task | Codeforces Round #473 (Div. 2)

辞書順最小にしたいので先頭からbの値を決めていく。 とりあえず、aの要素を使える限り使っていく。 例えば、入力例2は a={10, 3, 7} b={10, 3, 7} b[i]をa[i]の要素として使えるかどうかを判定するには、あらかじめ十分大きな素数の集合を用意しておく。a[i…

B. Mahmoud and Ehab and the message | Codeforces Round #473 (Div. 2)

int N, K, M; int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20); cin >> N >> K >> M; // 各単語の番号 map<string, int> id; rep(i, N) { string s; cin >> s; id[s] = i; } // 各単語の送信コスト vi A(N); rep(i, N)cin >> A</string,>…

A. Mahmoud and Ehab and the even-odd game | Codeforces Round #473 (Div. 2)

Nのパリティを見る。 (1) Nが偶数のとき 最初のターンでMahmoudがN個取ってMahmoudの勝ち。 (2) N >= 3 かつNが奇数のとき 最初のターンでMahmoudは2<=a<N個の偶数しか取れない。よってEhabのターンでN-a個は奇数であり、EhabがN-a個取って勝つ。 (3) Nが1のとき 最初のターンでMahmoudは何もできないので、Ehabの勝ち。 int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20); int n; cin >> n; cou…</n個の偶数しか取れない。よってehabのターンでn-a個は奇数であり、ehabがn-a個取って勝つ。>