結果
問題 | No.800 四平方定理 |
ユーザー |
|
提出日時 | 2019-03-17 21:37:52 |
言語 | D (dmd 2.099.1) |
結果 |
AC
|
実行時間 | 943 ms / 2,000 ms |
コード長 | 2,686 bytes |
コンパイル時間 | 902 ms |
使用メモリ | 67,400 KB |
最終ジャッジ日時 | 2023-02-11 04:59:33 |
合計ジャッジ時間 | 14,018 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge14 |
テストケース
テストケース表示入力 | 結果 | 実行時間 使用メモリ |
---|---|---|
testcase_00 | AC | 5 ms
6,948 KB |
testcase_01 | AC | 9 ms
6,948 KB |
testcase_02 | AC | 7 ms
6,948 KB |
testcase_03 | AC | 8 ms
6,952 KB |
testcase_04 | AC | 6 ms
4,904 KB |
testcase_05 | AC | 8 ms
4,904 KB |
testcase_06 | AC | 10 ms
6,392 KB |
testcase_07 | AC | 9 ms
4,904 KB |
testcase_08 | AC | 9 ms
6,348 KB |
testcase_09 | AC | 10 ms
6,952 KB |
testcase_10 | AC | 373 ms
56,376 KB |
testcase_11 | AC | 411 ms
58,020 KB |
testcase_12 | AC | 417 ms
58,548 KB |
testcase_13 | AC | 384 ms
58,240 KB |
testcase_14 | AC | 419 ms
58,756 KB |
testcase_15 | AC | 427 ms
59,468 KB |
testcase_16 | AC | 432 ms
59,696 KB |
testcase_17 | AC | 455 ms
59,016 KB |
testcase_18 | AC | 424 ms
58,368 KB |
testcase_19 | AC | 439 ms
58,740 KB |
testcase_20 | AC | 1 ms
6,948 KB |
testcase_21 | AC | 1 ms
4,904 KB |
testcase_22 | AC | 454 ms
58,832 KB |
testcase_23 | AC | 943 ms
66,944 KB |
testcase_24 | AC | 894 ms
66,956 KB |
testcase_25 | AC | 875 ms
67,252 KB |
testcase_26 | AC | 1 ms
4,900 KB |
testcase_27 | AC | 2 ms
4,900 KB |
testcase_28 | AC | 836 ms
66,496 KB |
testcase_29 | AC | 849 ms
66,508 KB |
testcase_30 | AC | 874 ms
67,400 KB |
testcase_31 | AC | 775 ms
65,884 KB |
testcase_32 | AC | 888 ms
67,232 KB |
ソースコード
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, core.bitop; enum inf3 = 1_001_001_001; enum inf6 = 1_001_001_001_001_001_001L; enum mod = 1_000_000_007L; void main() { int n, d; scan(n, d); auto sq = iota(n + 1).map!(i => i^^2).array.assumeSorted; int[int] cnt; foreach (x ; 1 .. n + 1) { foreach (y ; 1 .. n + 1) { cnt[sq[x] + sq[y]]++; } } long ans; foreach (w ; 1 .. n + 1) { foreach (z ; 1 .. n + 1) { int a = sq[w] + d - sq[z]; if (a in cnt) ans += cnt[a]; } } writeln(ans); } int[][] readGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) { auto adj = new int[][](n, 0); foreach (i; 0 .. m) { int u, v; scan(u, v); if (is1indexed) { u--, v--; } adj[u] ~= v; if (isUndirected) { adj[v] ~= u; } } return adj; } alias Edge = Tuple!(int, "to", int, "cost"); Edge[][] readWeightedGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) { auto adj = new Edge[][](n, 0); foreach (i; 0 .. m) { int u, v, c; scan(u, v, c); if (is1indexed) { u--, v--; } adj[u] ~= Edge(v, c); if (isUndirected) { adj[v] ~= Edge(u, c); } } return adj; } void yes(bool b) { writeln(b ? "Yes" : "No"); } void YES(bool b) { writeln(b ? "YES" : "NO"); } T[] readArr(T)() { return readln.split.to!(T[]); } T[] readArrByLines(T)(int n) { return iota(n).map!(i => readln.chomp.to!T).array; } void scan(T...)(ref T args) { import std.stdio : readln; import std.algorithm : splitter; import std.conv : to; import std.range.primitives; auto line = readln().splitter(); foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } } bool chmin(T, U...)(ref T x, U args) { bool isChanged; foreach (arg; args) { if (x > arg) { x = arg; isChanged = true; } } return isChanged; } bool chmax(T, U...)(ref T x, U args) { bool isChanged; foreach (arg; args) { if (x < arg) { x = arg; isChanged = true; } } return isChanged; }