結果
問題 | No.1840 Random Painting |
ユーザー | 👑 hos.lyric |
提出日時 | 2022-02-11 22:38:11 |
言語 | D (dmd 2.106.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,340 bytes |
コンパイル時間 | 698 ms |
コンパイル使用メモリ | 126,600 KB |
実行使用メモリ | 21,016 KB |
最終ジャッジ日時 | 2024-06-22 14:15:04 |
合計ジャッジ時間 | 3,146 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,812 KB |
testcase_01 | AC | 1 ms
6,944 KB |
testcase_02 | AC | 1 ms
6,940 KB |
testcase_03 | AC | 1 ms
6,940 KB |
testcase_04 | AC | 1 ms
6,940 KB |
testcase_05 | AC | 1 ms
6,940 KB |
testcase_06 | AC | 1 ms
6,940 KB |
testcase_07 | AC | 1 ms
6,940 KB |
testcase_08 | AC | 1 ms
6,940 KB |
testcase_09 | AC | 4 ms
6,940 KB |
testcase_10 | AC | 31 ms
8,012 KB |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | AC | 65 ms
20,492 KB |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | AC | 66 ms
19,152 KB |
testcase_19 | AC | 66 ms
19,760 KB |
testcase_20 | AC | 64 ms
19,760 KB |
testcase_21 | AC | 65 ms
20,960 KB |
testcase_22 | AC | 66 ms
21,016 KB |
testcase_23 | AC | 66 ms
18,780 KB |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | AC | 1 ms
6,940 KB |
testcase_31 | AC | 1 ms
6,944 KB |
testcase_32 | AC | 1 ms
6,940 KB |
testcase_33 | AC | 1 ms
6,940 KB |
testcase_34 | AC | 1 ms
6,940 KB |
ソースコード
import std.conv, std.functional, std.range, std.stdio, std.string; import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons; import core.bitop; class EOFException : Throwable { this() { super("EOF"); } } string[] tokens; string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; } int readInt() { return readToken.to!int; } long readLong() { return readToken.to!long; } real readReal() { return readToken.to!real; } bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } } bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } } int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; } int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); } int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); } // n * (n + 1) // modifies a real[] solveLinearEq(real[][] a) { const n = cast(int)(a.length); foreach (h; 0 .. n) { int im = h; foreach (i; h + 1 .. n) { if (abs(a[im][h]) < abs(a[i][h])) { im = i; } } swap(a[h], a[im]); a[h][] /= a[h][h]; foreach (i; h + 1 .. n) { foreach_reverse (j; h .. n + 1) { a[i][j] -= a[i][h] * a[h][j]; } } } auto x = new real[n]; foreach_reverse (i; 0 .. n) { x[i] = a[i][n]; foreach (j; i + 1 .. n) { x[i] -= a[i][j] * x[j]; } } return x; } // https://oeis.org/A225233 long f(long x, long y) { const n = x + y; return (2 * n - x) * x; } void main() { debug {{ // E[time | reach 0] foreach (n; 1 .. 10 + 1) { auto a = new real[][](n, n + 1); foreach (x; 0 .. n) { a[x][] = 0.0L; a[x][x] += 1.0L; if (x > 0) { a[x][n] = 1.0L * (n - x) / n; { a[x][x - 1] -= 0.5L; } if (x + 1 < n) { a[x][x + 1] -= 0.5L; } } } auto es = a.solveLinearEq; foreach (x; 0 .. n) { es[x] /= (1.0L * (n - x) / n); } es[] *= 3.0L; writeln(es); foreach (x; 0 .. n) { assert(abs(f(x, n - x) - es[x]) <= 1e-6L); } } }} try { for (; ; ) { const N = readInt; const S = readToken; int[] xs; foreach (i; 1 .. N) if (S[i] == '0') { xs ~= i; } const len = cast(int)(xs.length); xs = xs ~ [0] ~ xs; xs[0 .. len] -= N; debug { writeln("xs = ", xs); } long ans; foreach (j; 0 .. len + 1) { const long l = -xs[j]; const long r = xs[j + len]; // 0 -> -l -> +r // 0 -> +r -> -l long sum; sum += r * (N - l - r) * (f(l, r) + f(l + r, N - l - r)); sum += l * (N - l - r) * (f(r, l) + f(l + r, N - l - r)); assert(sum % (l + r) == 0); sum /= (l + r); ans += sum; } assert(ans % (3 * N) == 0); ans /= (3 * N); writeln(ans); } } catch (EOFException e) { } }