結果
問題 |
No.3229 Liar Game Comibination
|
ユーザー |
![]() |
提出日時 | 2025-07-12 17:07:42 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 286 ms / 2,000 ms |
コード長 | 1,610 bytes |
コンパイル時間 | 2,395 ms |
コンパイル使用メモリ | 90,440 KB |
実行使用メモリ | 8,320 KB |
最終ジャッジ日時 | 2025-08-08 20:50:08 |
合計ジャッジ時間 | 7,457 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 29 |
ソースコード
import std.stdio, std.algorithm, std.array, std.conv; void main() { auto NMK = readln.split.to!(ulong[]); auto N = NMK[0], M = NMK[1], K = NMK[2]; F_2Vector[] matrix; foreach (i; 0 .. M) { F_2Vector vec; auto str = readln[0 .. $-1]; foreach (j; 0 .. N) { set_entry(vec, j, str[j] == cast(immutable) '1'); } matrix ~= vec; } ulong ans = 1; auto r = get_rank(matrix); foreach (i; 0 .. N-r) ans = 2 * ans % K; writeln(ans); } // F_2 matrix alias F_2Vector = size_t[40]; immutable ulong_size = 64; void set_entry(ref F_2Vector vector, ulong n_th, bool val) { if (val) vector[n_th / ulong_size] |= 1UL << n_th % ulong_size; else vector[n_th / ulong_size] &= ~0UL - (1UL << (n_th % ulong_size)); } bool is_zero(F_2Vector vector) { foreach (e; vector) if (e != 0) return false; return true; } F_2Vector slide_vector(F_2Vector vector) { F_2Vector slided; foreach (i; 0 .. vector.length - 1) { slided[i] = vector[i+1]; } return slided; } // by sweep // vectors can change uint get_rank(F_2Vector[] vectors ...) { if (vectors.all!(v => is_zero(v))) return 0; // make the left-most vector nonzero while (vectors.all!(v => v[0] == 0)) vectors.each!((ref v) => v = slide_vector(v)); while (vectors.all!(v => v[0] % 2 == 0)) vectors.each!((ref v) => v[0] >>= 1); foreach (ref v; vectors) { if (v[0] % 2 != 0) { auto tmp = vectors[0]; vectors[0] = v; v = tmp; } } // sweeping foreach (ref v; vectors[1 .. $]) { if (v[0] % 2 != 0) v[] ^= vectors[0][]; } vectors[1 .. $].map!((ref v) => v[0] >>= 1); return 1 + get_rank(vectors[1 .. $]); }