Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c51138c

Browse files
committed
.
1 parent 3591a87 commit c51138c

11 files changed

+61
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from ctypes import *
2+
import mmap
3+
4+
buf=mmap.mmap(-1,mmap.PAGESIZE,prot=mmap.PROT_READ|mmap.PROT_WRITE|mmap.PROT_EXEC)
5+
ftype=CFUNCTYPE(c_int,POINTER(c_int),c_int,c_int)
6+
fpointer=c_void_p.from_buffer(buf)
7+
f=ftype(addressof(fpointer))
8+
buf.write(
9+
b'\x89\xd3' # mov ebx,edx
10+
b'\xb9\x00\x00\x00\x00' # mov ecx,0
11+
b'\x48\x8d\x34\xb7' # lea rsi,[rsi*4+rdi]
12+
# begin:
13+
b'\x8b\x07' # mov eax,DWORD PTR [rdi]
14+
b'\xba\x00\x00\x00\x00' # mov edx,0
15+
b'\xf7\xfb' # idiv ebx
16+
b'\x01\xc1' # add ecx,eax
17+
b'\x48\x8d\x7f\x04' # lea rdi,0x4[rdi]
18+
b'\x48\x39\xf7' # cmp rdi,rsi
19+
b'\x74\x02' # jz end
20+
b'\xeb\xea' # jmp begin
21+
# end:
22+
b'\x89\xc8' # mov eax,ecx
23+
b'\xc3' # ret
24+
)
25+
26+
#del fpointer
27+
#buf.close()
28+
29+
class Solution:
30+
def smallestDivisor(self, nums: List[int], threshold: int) -> int:
31+
n = len(nums)
32+
l, r = ceil(sum(nums) / threshold), ceil(max(nums) / floor(threshold / n))
33+
#nums = [x-1 for x in nums]
34+
a=(c_int*n)()
35+
for i in range(n): a[i]=nums[i]-1
36+
while l < r:
37+
mid = (l + r) >> 1
38+
#cur = sum(n // mid for n in nums) + n
39+
cur = f(a,n,mid) + n
40+
if cur > threshold:
41+
l = mid + 1
42+
else:
43+
r = mid
44+
return l
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
greedy. O(log n).
2+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2n^2-2n+1. O(1).
2+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
merge segments. O(sort(n)).
2+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dfs, update the count when we traverse an edge. O(n).
2+

‎2501-2600/2582. Pass the Pillow.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
O(1).
2+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dfs+nth_element. O(n).
2+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Maintain an interval for each prime factor. Preprocess the prime factors of each number in [U]. O(U+n*log U/log log U).
2+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
DP, knapsack. Use prefix sum. O(n*t).
2+

‎chk/chk.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22

33

4+
from builtins import *
45
copy=_copy; random=_random; time=_time; bisect=_bisect
56
sys.setrecursionlimit(10**6)
67
sys.set_int_max_str_digits(10**7)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /