結果
問題 | No.171 スワップ文字列(Med) |
ユーザー | 👑 obakyan |
提出日時 | 2020-03-01 19:42:40 |
言語 | Lua (LuaJit 2.1.1696795921) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,882 bytes |
コンパイル時間 | 85 ms |
コンパイル使用メモリ | 6,692 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-13 20:47:46 |
合計ジャッジ時間 | 842 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,248 KB |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | AC | 2 ms
5,248 KB |
testcase_11 | AC | 1 ms
5,248 KB |
testcase_12 | AC | 2 ms
5,248 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, tbl, mul) 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 cnt = 1 x = x / dv while x % dv == 0 do x = x / dv cnt = cnt + 1 end if tbl[dv] then tbl[dv] = tbl[dv] + cnt * mul else tbl[dv] = cnt * mul end lim = mce(msq(x)) end if primepos == prime_num then break end primepos = primepos + 1 dv = primes[primepos] end if x ~= 1 then if tbl[x] then tbl[x] = tbl[x] + mul else tbl[x] = mul end end end local s = io.read() local n = #s local tmap = {} for i = 1, n do local ss = s:sub(i, i) if tmap[ss] then tmap[ss] = tmap[ss] + 1 else tmap[ss] = 1 end end local t = {} for w, cnt in pairs(tmap) do table.insert(t, cnt) end local mulcnt = {} for i = 1, n do mulcnt[i] = 0 end do local rem = n for i = 1, #t do local c = t[i] for i = 1, c do mulcnt[i] = mulcnt[i] - 1 mulcnt[rem + 1 - i] = mulcnt[rem + 1 - i] + 1 end rem = rem - c end end local dvp = {} local primes = getprimes(mce(msq(n))) for i = 2, n do if 0 < mulcnt[i] then getdivisorparts(i, primes, dvp, mulcnt[i]) end end local ret = 1 for src, pw in pairs(dvp) do for i = 1, pw do ret = (ret * src) % 573 end end print(ret - 1)