結果
問題 | No.1840 Random Painting |
ユーザー | 👑 hos.lyric |
提出日時 | 2022-02-11 22:39:36 |
言語 | D (dmd 2.106.1) |
結果 |
AC
|
実行時間 | 61 ms / 2,000 ms |
コード長 | 3,440 bytes |
コンパイル時間 | 709 ms |
コンパイル使用メモリ | 122,948 KB |
実行使用メモリ | 20,820 KB |
最終ジャッジ日時 | 2024-06-22 14:15:07 |
合計ジャッジ時間 | 2,462 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,812 KB |
testcase_01 | AC | 1 ms
6,940 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,944 KB |
testcase_06 | AC | 1 ms
6,940 KB |
testcase_07 | AC | 1 ms
6,940 KB |
testcase_08 | AC | 1 ms
6,944 KB |
testcase_09 | AC | 4 ms
6,940 KB |
testcase_10 | AC | 28 ms
8,372 KB |
testcase_11 | AC | 47 ms
12,120 KB |
testcase_12 | AC | 31 ms
9,884 KB |
testcase_13 | AC | 12 ms
6,944 KB |
testcase_14 | AC | 57 ms
19,512 KB |
testcase_15 | AC | 45 ms
12,384 KB |
testcase_16 | AC | 48 ms
13,084 KB |
testcase_17 | AC | 24 ms
6,944 KB |
testcase_18 | AC | 56 ms
20,820 KB |
testcase_19 | AC | 56 ms
20,060 KB |
testcase_20 | AC | 56 ms
20,692 KB |
testcase_21 | AC | 56 ms
20,464 KB |
testcase_22 | AC | 57 ms
20,660 KB |
testcase_23 | AC | 61 ms
19,032 KB |
testcase_24 | AC | 12 ms
6,944 KB |
testcase_25 | AC | 11 ms
6,940 KB |
testcase_26 | AC | 12 ms
6,940 KB |
testcase_27 | AC | 13 ms
6,944 KB |
testcase_28 | AC | 10 ms
6,940 KB |
testcase_29 | AC | 10 ms
6,944 KB |
testcase_30 | AC | 1 ms
6,944 KB |
testcase_31 | AC | 1 ms
6,944 KB |
testcase_32 | AC | 1 ms
6,944 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; */ ans += (l + r - N) * (l * l - l * r + r * r - 2 * l * N - 2 * r * N); } assert(ans % (3 * N) == 0); ans /= (3 * N); writeln(ans); } } catch (EOFException e) { } }