結果
問題 | No.944 煎っぞ! |
ユーザー | 👑 obakyan |
提出日時 | 2019-12-14 00:45:14 |
言語 | Lua (LuaJit 2.1.1696795921) |
結果 |
AC
|
実行時間 | 24 ms / 3,000 ms |
コード長 | 2,215 bytes |
コンパイル時間 | 107 ms |
コンパイル使用メモリ | 5,376 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-27 23:48:00 |
合計ジャッジ時間 | 1,903 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 23 ms
5,248 KB |
testcase_01 | AC | 23 ms
5,376 KB |
testcase_02 | AC | 22 ms
5,376 KB |
testcase_03 | AC | 23 ms
5,376 KB |
testcase_04 | AC | 24 ms
5,376 KB |
testcase_05 | AC | 22 ms
5,376 KB |
testcase_06 | AC | 22 ms
5,376 KB |
testcase_07 | AC | 21 ms
5,376 KB |
testcase_08 | AC | 23 ms
5,376 KB |
testcase_09 | AC | 22 ms
5,376 KB |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 7 ms
5,376 KB |
testcase_12 | AC | 5 ms
5,376 KB |
testcase_13 | AC | 2 ms
5,376 KB |
testcase_14 | AC | 6 ms
5,376 KB |
testcase_15 | AC | 4 ms
5,376 KB |
testcase_16 | AC | 2 ms
5,376 KB |
testcase_17 | AC | 2 ms
5,376 KB |
testcase_18 | AC | 6 ms
5,376 KB |
testcase_19 | AC | 6 ms
5,376 KB |
testcase_20 | AC | 23 ms
5,376 KB |
testcase_21 | AC | 23 ms
5,376 KB |
testcase_22 | AC | 22 ms
5,376 KB |
testcase_23 | AC | 23 ms
5,376 KB |
testcase_24 | AC | 23 ms
5,376 KB |
testcase_25 | AC | 23 ms
5,376 KB |
testcase_26 | AC | 22 ms
5,376 KB |
testcase_27 | AC | 23 ms
5,376 KB |
testcase_28 | AC | 2 ms
5,376 KB |
testcase_29 | AC | 1 ms
5,376 KB |
testcase_30 | AC | 23 ms
5,376 KB |
testcase_31 | AC | 23 ms
5,376 KB |
testcase_32 | AC | 22 ms
5,376 KB |
testcase_33 | AC | 24 ms
5,376 KB |
testcase_34 | AC | 23 ms
5,376 KB |
ソースコード
local mce, mfl, msq, mmi, mma, mab = math.ceil, math.floor, math.sqrt, math.min, math.max, math.abs local function getprimes(x) local primes = {} local allnums = {} for i = 1, x do allnums[i] = true end for i = 2, x do if allnums[i] then table.insert(primes, i) local lim = mfl(x / i) for j = 2, lim do allnums[j * i] = false end end end return primes end local function getdivisorparts(x, primes) local prime_num = #primes local tmp = {} local lim = mce(msq(x)) local primepos = 1 local dv = primes[primepos] while(primepos <= prime_num and dv <= lim) do if(x % dv == 0) then local asdf = {} asdf.p = dv asdf.cnt = 1 x = x / dv while(x % dv == 0) do x = x / dv asdf.cnt = asdf.cnt + 1 end table.insert(tmp, asdf) lim = mce(msq(x)) end if(primepos == prime_num) then break end primepos = primepos + 1 dv = primes[primepos] end if(x ~= 1) then local asdf = {} asdf.p, asdf.cnt = x, 1 table.insert(tmp, asdf) end return tmp end local function getdivisor(divisorparts) local t = {} local pat = 1 local len = #divisorparts local allpat = 1 for i = 1, len do allpat = allpat * (1 + divisorparts[i].cnt) end for t_i_pat = 0, allpat - 1 do local div = allpat local i_pat = t_i_pat local ret = 1 for i = 1, len do div = mfl(div / (divisorparts[i].cnt + 1)) local mul = mfl(i_pat / div) i_pat = i_pat % div for j = 1, mul do ret = ret * divisorparts[i].p end end table.insert(t, ret) end table.sort(t) return t end local n = io.read("*n") local a = {} local sum = 0 for i = 1, n do a[i] = io.read("*n") sum = sum + a[i] end local function solve(x) local cnt = 0 local val = 0 for i = 1, n do val = val + a[i] if val == x then cnt = cnt + 1 val = 0 elseif x < val then return 0 end end return cnt end local primes = getprimes(mce(msq(sum))) local divps = getdivisorparts(sum, primes) local divs = getdivisor(divps) for i = 1, #divs do local cnt = solve(divs[i]) if 0 < cnt then print(cnt) break end end