diff options
author | Raphael McSinyx <vn.mcsinyx@gmail.com> | 2017-08-18 22:45:44 +0700 |
---|---|---|
committer | Raphael McSinyx <vn.mcsinyx@gmail.com> | 2017-08-18 22:47:53 +0700 |
commit | 414c38d8cb31866daac61071bccf2e34a8d14d80 (patch) | |
tree | 3177119e5eea38ba26445e2f955b8e281b296da8 /THT/C/TP-2017/squares_brute-force.pas | |
parent | f7f3efd3f0c2634d741bcbf3b5639c1ba6b8c40f (diff) | |
download | cp-414c38d8cb31866daac61071bccf2e34a8d14d80.tar.gz |
Add THT/C/TP-2017
Diffstat (limited to 'THT/C/TP-2017/squares_brute-force.pas')
-rw-r--r-- | THT/C/TP-2017/squares_brute-force.pas | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/THT/C/TP-2017/squares_brute-force.pas b/THT/C/TP-2017/squares_brute-force.pas new file mode 100644 index 0000000..0b389d9 --- /dev/null +++ b/THT/C/TP-2017/squares_brute-force.pas @@ -0,0 +1,39 @@ +(* The method I actually used at the contest, approx 15% time-out. *) +uses math; + +var + f: text; + m, n, i, j, x, y: int16; + k: int8; + net: array[1..1000, 1..1000] of boolean; + count: int64 = 0; + +begin + assign(f, 'squares.inp'); + reset(f); + readln(f, m, n, k); + for x := 1 to m do + for y := 1 to n do + net[x][y] := true; + repeat + dec(k); + readln(f, x, y); + net[x][y] := false + until k = 0; + close(f); + + for x := 1 to m - 1 do + for y := 1 to n - 1 do + if net[x, y] then + for i := 0 to x - 1 do + for j := 1 to min(m - x, n - y - i) do + if net[x - i, y + j] and + net[x + j, y + i] and + net[x - i + j, y + i + j] then + count := count + 1; + + assign(f, 'squares.out'); + rewrite(f); + writeln(f, count); + close(f) +end. |