s_id stringlengths 10 10 | p_id stringlengths 6 6 | u_id stringlengths 10 10 | date stringlengths 10 10 | language stringclasses 1
value | original_language stringclasses 11
values | filename_ext stringclasses 1
value | status stringclasses 1
value | cpu_time stringlengths 1 5 | memory stringlengths 1 7 | code_size stringlengths 1 6 | code stringlengths 1 539k |
|---|---|---|---|---|---|---|---|---|---|---|---|
s568204099 | p02262 | u839008951 | 1516432515 | Python | Python3 | py | Runtime Error | 5970 | 10616 | 608 | import copy
cnt = 0
def insSort(A, n, g):
global cnt
for i in range(g, n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j = j - g
cnt += 1
A[j+g] = v
def shellSort(A, n):
G = []
i = 1
while True:
G.append(i)
i *= 4
if i > n - 1:
break
G.reverse()
print(len(G))
print(*G)
for i in G:
insSort(A, n, i)
n = int(input())
arr = []
for i in range(n):
arr.append(int(input()))
shellSort(arr, n)
print(cnt)
for s in arr:
print(s)
|
s678479000 | p02262 | u839008951 | 1516432734 | Python | Python3 | py | Runtime Error | 6140 | 10616 | 608 | import copy
cnt = 0
def insSort(A, n, g):
global cnt
for i in range(g, n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j = j - g
cnt += 1
A[j+g] = v
def shellSort(A, n):
G = []
i = 1
while True:
G.append(i)
i *= 4
if i > n - 1:
break
G.reverse()
print(len(G))
print(*G)
for i in G:
insSort(A, n, i)
n = int(input())
arr = []
for i in range(n):
arr.append(int(input()))
shellSort(arr, n)
print(cnt)
for s in arr:
print(s)
|
s225034507 | p02262 | u088372268 | 1517624891 | Python | Python3 | py | Runtime Error | 4020 | 16000 | 502 | n, gap = int(input()), []
data = list(map(int, [input() for i in range(n)]))
cnt, g = 0, n
while g >= 1:
g //= 2
gap.append(g)
if gap[0]:
gap.remove(0)
m = len(gap)
for i in range(m):
for idx in range(gap[i], n):
j = idx - gap[i]
while j >= 0 and data[j] > data[j+gap[i]]:
data[j+gap[i]], data[j] = data[j], data[j+gap[i]]
j -= gap[i]
cnt += 1
print(m)
print(" ".join(map(str, gap)))
print(cnt)
for i in range(n):
print(data[i])
|
s355233652 | p02262 | u088372268 | 1517625088 | Python | Python3 | py | Runtime Error | 3840 | 16000 | 502 | n, gap = int(input()), []
data = list(map(int, [input() for i in range(n)]))
cnt, g = 0, n
while g >= 1:
g //= 2
gap.append(g)
if gap[0]:
gap.remove(0)
m = len(gap)
for i in range(m):
for idx in range(gap[i], n):
j = idx - gap[i]
while j >= 0 and data[j] > data[j+gap[i]]:
data[j+gap[i]], data[j] = data[j], data[j+gap[i]]
j -= gap[i]
cnt += 1
print(m)
print(" ".join(map(str, gap)))
print(cnt)
for i in range(n):
print(data[i])
|
s299944848 | p02262 | u088372268 | 1517625255 | Python | Python3 | py | Runtime Error | 3900 | 16008 | 473 | n, gap = int(input()), []
data = list(map(int, [input() for i in range(n)]))
cnt, g = 0, n
while g >= 1:
g //= 2
gap.append(g)
m = len(gap)
for i in range(m):
for idx in range(gap[i], n):
j = idx - gap[i]
while j >= 0 and data[j] > data[j+gap[i]]:
data[j+gap[i]], data[j] = data[j], data[j+gap[i]]
j -= gap[i]
cnt += 1
print(m)
print(" ".join(map(str, gap)))
print(cnt)
for i in range(n):
print(data[i])
|
s780435990 | p02262 | u088372268 | 1517625674 | Python | Python3 | py | Runtime Error | 3260 | 16008 | 473 | n, gap = int(input()), []
data = list(map(int, [input() for i in range(n)]))
cnt, g = 0, n
while g >= 1:
g //= 2
gap.append(g)
m = len(gap)
for i in range(m):
gi = gap[i]
for idx in range(gap[i], n):
j = idx - gap[i]
while j >= 0 and data[j] > data[j+gi]:
data[j+gi], data[j] = data[j], data[j+gi]
j -= gi
cnt += 1
print(m)
print(" ".join(map(str, gap)))
print(cnt)
for i in range(n):
print(data[i])
|
s199021317 | p02262 | u088372268 | 1517629306 | Python | Python3 | py | Runtime Error | 3280 | 16004 | 438 | n, gap = int(input()), []
data = list(map(int, [input() for i in range(n)]))
cnt, g = 0, n
while g >= 1:
g //= 2
gap.append(g)
m = len(gap)
for i in gap:
for idx in range(i, n):
j = idx - i
while j >= 0 and data[j] > data[j+i]:
data[j+i], data[j] = data[j], data[j+i]
j -= i
cnt += 1
print(m)
print(" ".join(map(str, gap)))
print(cnt)
for i in range(n):
print(data[i])
|
s211904694 | p02262 | u088372268 | 1517633232 | Python | Python3 | py | Runtime Error | 2930 | 16004 | 490 | n, gap = int(input()), []
data = list(map(int, [input() for i in range(n)]))
cnt, g = 0, 0
while g <= n//9:
g = 3 * g + 1
gap.append(g)
m = len(gap)
gap = [gap[i] for i in range(m-1, -1, -1)]
for i in gap:
for idx in range(i, n):
j = idx - i
while j >= 0 and data[j] > data[j+i]:
data[j+i], data[j] = data[j], data[j+i]
j -= i
cnt += 1
print(m)
print(" ".join(map(str, gap)))
print(cnt)
for i in range(n):
print(data[i])
|
s903384464 | p02262 | u088372268 | 1517641520 | Python | Python3 | py | Runtime Error | 3100 | 16004 | 490 | n, gap = int(input()), []
data = list(map(int, [input() for i in range(n)]))
cnt, g = 0, 0
while g <= n//9:
g = 3 * g + 1
gap.append(g)
m = len(gap)
gap = [gap[i] for i in range(m-1, -1, -1)]
for i in gap:
for idx in range(i, n):
j = idx - i
while j >= 0 and data[j] > data[j+i]:
data[j+i], data[j] = data[j], data[j+i]
j -= i
cnt += 1
print(m)
print(" ".join(map(str, gap)))
print(cnt)
for i in range(n):
print(data[i])
|
s709072672 | p02262 | u547838013 | 1517667023 | Python | Python3 | py | Runtime Error | 3000 | 16008 | 489 | n, gap = int(input()), []
data = list(map(int, [input() for i in range(n)]))
cnt, g = 0, 0
while g <= n//9:
g = 3 * g + 1
gap.append(g)
m = len(gap)
gap = [gap[i] for i in range(m-1, -1, -1)]
for i in gap:
for idx in range(i, n):
j = idx - i
while j >= 0 and data[j] > data[j+i]:
data[j+i], data[j] = data[j], data[j+i]
j -= i
cnt += 1
print(m)
print(" ".join(map(str, gap)))
print(cnt)
for i in range(n):
print(data[i])
|
s949283832 | p02262 | u996463517 | 1518250198 | Python | Python3 | py | Runtime Error | 1350 | 9836 | 606 | def shellSort(A):
global cnt
cnt = 0
h = 1
g = []
while h <= len(A):
g.append(h)
h = 3*h+1
g.reverse()
m = len(g)
print(m)
print(' '.join(map(str,g)))
for i in range(m):
insertionSort(A,g[i])
def insertionSort(A,g):
global cnt
for i in range(g,len(A)):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j = j - g
cnt += 1
A[j+g] = v
n = int(input())
A = [int(input()) for i in range(n)]
shellSort(A)
print(cnt)
for i in A:
print(i)
|
s082095761 | p02262 | u996463517 | 1518250365 | Python | Python3 | py | Runtime Error | 1340 | 9836 | 618 | def insertionSort(A,g):
global cnt
for i in range(g,len(A)):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j = j - g
cnt += 1
A[j+g] = v
def shellSort(A):
global cnt
cnt = 0
h = 1
g = []
while h <= len(A):
g.append(h)
h = 3*h+1
g.reverse()
m = len(g)
print(m)
print(' '.join(map(str,g)))
for i in range(m):
insertionSort(A,g[i])
n = int(input())
A = [int(input()) for i in range(n)]
shellSort(A)
print(cnt)
for i in A:
print(i)
|
s345268681 | p02262 | u150984829 | 1518270678 | Python | Python3 | py | Runtime Error | 2320 | 10352 | 255 | n=int(input())
s=[1]
c=0
while s[-1]*3<n:s+=[s[-1]*3+1]
s=s[::-1]
a=[int(input())for _ in[0]*n]
for g in s:
for i in range(n):
k=a[i]
j=i-g
while j>=0 and a[j]>k:a[j+g]=a[j];j-=g;c+=1
a[j+g]=k
print(len(s))
print(*s)
print(c)
for x in a:print(x)
|
s093704838 | p02262 | u150984829 | 1518271178 | Python | Python3 | py | Runtime Error | 2300 | 10712 | 256 | n=int(input())
a=[int(input())for _ in[0]*n]
s=[1]
c=0
while s[-1]*3<n:s+=[s[-1]*3+1]
s=s[::-1]
for g in s:
for i in range(g,n):
v=a[i]
j=i-g
while j>=0 and a[j]>v:a[j+g]=a[j];j-=g;c+=1
a[j+g]=v
print(len(s))
print(*s)
print(c)
print(*a,sep='\n')
|
s841201715 | p02262 | u150984829 | 1518271388 | Python | Python3 | py | Runtime Error | 2350 | 10716 | 254 | n=int(input())
a=[int(input())for _ in[0]*n]
s=[1]
c=0
while s[-1]*3<n:s+=[s[-1]*3+1]
s=s[::-1]
for g in s:
for i in range(n):
v=a[i]
j=i-g
while j>=0 and a[j]>v:a[j+g]=a[j];j-=g;c+=1
a[j+g]=v
print(len(s))
print(*s)
print(c)
print(*a,sep='\n')
|
s901182524 | p02262 | u150984829 | 1518271615 | Python | Python3 | py | Runtime Error | 2360 | 10712 | 254 | n=int(input())
a=[int(input())for _ in[0]*n]
s=[1]
c=0
while s[-1]*3<n:s+=[s[-1]*3+1]
s=s[::-1]
for g in s:
for i in range(n):
v=a[i]
j=i-g
while j>=0 and a[j]>v:a[j+g]=a[j];j-=g;c+=1
a[j+g]=v
print(len(s))
print(*s)
print(c)
print(*a,sep='\n')
|
s310213962 | p02262 | u150984829 | 1518272071 | Python | Python3 | py | Runtime Error | 1840 | 10712 | 304 | n=int(input())
a=[int(input())for _ in[0]*n]
s=[int(pow(4, i) + 3*pow(2, i-1) + 1) for i in range(13)[::-1]] + [1]
s=[v for v in s if v <= n]
c=0
for g in s:
for i in range(n):
v=a[i]
j=i-g
while j>=0 and a[j]>v:a[j+g]=a[j];j-=g;c+=1
a[j+g]=v
print(len(s))
print(*s)
print(c)
print(*a,sep='\n')
|
s302053204 | p02262 | u150984829 | 1518272295 | Python | Python3 | py | Runtime Error | 2390 | 10716 | 313 | # Runtime Error
n=int(input())
a=[int(input())for _ in[0]*n]
s=[797161,265720,88573,29524,9841,3280,1093,364,121,40,13,4,1]
s=[v for v in s if v <= n]
c=0
for g in s:
for i in range(n):
v=a[i]
j=i-g
while j>=0 and a[j]>v:a[j+g]=a[j];j-=g;c+=1
a[j+g]=v
print(len(s))
print(*s)
print(c)
print(*a,sep='\n')
|
s789401657 | p02262 | u150984829 | 1518274043 | Python | Python3 | py | Runtime Error | 2330 | 10624 | 410 | n = int(input())
A = [int(input()) for _ in range(n)]
cnt = 0
G = [797161,265720,88573,29524,9841,3280,1093,364,121,40,13,4,1]
G = [v for v in G if v <= n]
m = len(G)
for g in G:
for i in range(n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j = j - g
cnt += 1
A[j+g] = v
print(m)
print(*G)
print(cnt)
print(*A, sep='\n')
|
s312397683 | p02262 | u150984829 | 1518274537 | Python | Python3 | py | Runtime Error | 0 | 0 | 480 | import sys
n = int(input())
A=[int(e)for e in sys.stdin]
cnt = 0
G = [797161,265720,88573,29524,9841,3280,1093,364,121,40,13,4,1]
G = [v for v in G if v <= n]
def insertionSort(A, n, g):
global cnt
for i in range(g, n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j = j - g
cnt += 1
A[j+g] = v
for g in G:
insertionSort(A, n, g)
print(len(G))
print(*G)
print(cnt)
print("\n".join(A))
|
s641597779 | p02262 | u150984829 | 1518274668 | Python | Python3 | py | Runtime Error | 0 | 0 | 424 | import sys
n = int(input())
A=[int(e)for e in sys.stdin]
cnt = 0
G = [797161,265720,88573,29524,9841,3280,1093,364,121,40,13,4,1]
G = [v for v in G if v <= n]
for g in G:
global cnt
for i in range(g, n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j = j - g
cnt += 1
A[j+g] = v
print(len(G))
print(*G)
print(cnt)
print(*A,sep='\n')
|
s274202420 | p02262 | u150984829 | 1518274679 | Python | Python3 | py | Runtime Error | 2330 | 10636 | 409 | import sys
n = int(input())
A=[int(e)for e in sys.stdin]
cnt = 0
G = [797161,265720,88573,29524,9841,3280,1093,364,121,40,13,4,1]
G = [v for v in G if v <= n]
for g in G:
for i in range(g, n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j = j - g
cnt += 1
A[j+g] = v
print(len(G))
print(*G)
print(cnt)
print(*A,sep='\n')
|
s079788836 | p02262 | u088372268 | 1518653983 | Python | Python3 | py | Runtime Error | 2940 | 15976 | 471 | import sys
n, gap = int(input()), []
data = [int(i) for i in sys.stdin.readlines()]
cnt, g = 0, 0
while g <= n//9:
g = 3 * g + 1
gap.append(g)
m = len(gap)
gap = gap[::-1]
for i in gap:
for idx in range(i, n):
j = idx - i
while j >= 0 and data[j] > data[j+i]:
data[j+i], data[j] = data[j], data[j+i]
j -= i
cnt += 1
print(m)
print(" ".join(map(str, gap)))
print(cnt)
for i in range(n):
print(data[i])
|
s116218040 | p02262 | u088372268 | 1518654312 | Python | Python3 | py | Runtime Error | 2920 | 16004 | 463 | n, gap = int(input()), []
data = list(map(int, [input() for i in range(n)]))
cnt, g = 0, 0
while g <= n//9:
g = 3 * g + 1
gap.append(g)
m = len(gap)
gap = gap[::-1]
for i in gap:
for idx in range(i, n):
j = idx - i
while j >= 0 and data[j] > data[j+i]:
data[j+i], data[j] = data[j], data[j+i]
j -= i
cnt += 1
print(m)
print(" ".join(map(str, gap)))
print(cnt)
for i in range(n):
print(data[i])
|
s878729437 | p02262 | u088372268 | 1518654446 | Python | Python3 | py | Runtime Error | 3040 | 15980 | 471 | import sys
n, gap = int(input()), []
data = [int(i) for i in sys.stdin.readlines()]
cnt, g = 0, 0
while g <= n//9:
g = 3 * g + 1
gap.append(g)
m = len(gap)
gap = gap[::-1]
for i in gap:
for idx in range(i, n):
j = idx - i
while j >= 0 and data[j] > data[j+i]:
data[j+i], data[j] = data[j], data[j+i]
j -= i
cnt += 1
print(m)
print(" ".join(map(str, gap)))
print(cnt)
for i in range(n):
print(data[i])
|
s933446982 | p02262 | u088372268 | 1518658342 | Python | Python3 | py | Runtime Error | 2190 | 15980 | 487 | import sys
n, gap = int(input()), []
data = [int(i) for i in sys.stdin.readlines()]
cnt, g = 0, 0
while g <= n//9:
g = 3 * g + 1
gap.append(g)
m = len(gap)
gap = gap[::-1]
for i in gap:
for idx in range(i, n):
j = idx - i
v = data[idx]
while j >= 0 and data[j] > v:
data[j+i] = data[j]
j -= i
cnt += 1
data[j+i] = v
print(m)
print(" ".join(map(str, gap)))
print(cnt)
for i in range(n):
print(data[i])
|
s438793484 | p02262 | u150984829 | 1519781958 | Python | Python3 | py | Runtime Error | 0 | 0 | 468 | import sys
n = int(input())
A = [int(e)for e in sys.stdin]
cnt = 0
G = [int((2.25**i-1)/1.25)for i in range(17,0,-1)]
G = [v for v in G if v <= n]
def insertionSort(A, n, g):
global cnt
for i in range(g, n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j = j - g
cnt += 1
A[j+g] = v
for g in G:
insertionSort(A, n, g)
print(len(G))
print(*G)
print(cnt)
print('\n'.join(A))
|
s694061025 | p02262 | u150984829 | 1519865757 | Python | Python3 | py | Runtime Error | 0 | 0 | 611 | import sys
def solve():
n = int(input())
A = list(map(int,sys.stdin))
cnt = 0
G = [int((2.25**i-1)/1.25)for i in range(17,0,-1)]
G = [v for v in G if v <= n]
def insertionSort(A, n, g):
global cnt
for i in range(g, n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j = j - g
cnt += 1
A[j+g] = v
for g in G:
insertionSort(A, n, g)
print(len(G))
print(*G)
print(cnt)
print('\n'.join(map(str,A)))
if __name__ == '__main__':
solve()
|
s787031607 | p02262 | u613534067 | 1520737734 | Python | Python3 | py | Runtime Error | 1220 | 9896 | 709 | import math
cnt = 0
m = 0
g = []
def insertion_sort(a, n, g):
# cnt+=1 のときにローカルスコープの外を見にいくようにするため
global cnt
for i in range(g, n):
v = a[i]
k = i - g
while k >= 0 and a[k] > v:
a[k+g] = a[k]
k -= g
cnt += 1
a[k+g] = v
def shell_sort(a, n):
global m, g
g = []
h = 1
while h <= n:
g.append(h)
h = h * 3 + 1
g.reverse()
m = len(g)
for i in g:
insertion_sort(a, n, i)
n = int(input())
a = []
for i in range(n):
a.append(int(input()))
shell_sort(a, n)
print(m)
print(" ".join(map(str, g)))
print(cnt)
for i in a:
print(i)
|
s383008551 | p02262 | u613534067 | 1520738078 | Python | Python3 | py | Runtime Error | 1320 | 9896 | 709 | import math
cnt = 0
m = 0
g = []
def insertion_sort(a, n, g):
# cnt+=1 のときにローカルスコープの外を見にいくようにするため
global cnt
for i in range(g, n):
v = a[i]
k = i - g
while k >= 0 and a[k] > v:
a[k+g] = a[k]
k -= g
cnt += 1
a[k+g] = v
def shell_sort(a, n):
global m, g
g = []
h = 1
while h <= n:
g.append(h)
h = h * 3 + 1
g.reverse()
m = len(g)
for i in g:
insertion_sort(a, n, i)
n = int(input())
a = []
for i in range(n):
a.append(int(input()))
shell_sort(a, n)
print(m)
print(" ".join(map(str, g)))
print(cnt)
for i in a:
print(i)
|
s975530428 | p02262 | u605879293 | 1522648611 | Python | Python3 | py | Runtime Error | 0 | 0 | 467 |
def shellSort(array, G):
cnt = 0
flag = False
for g in G:
if g != G[-1]:
insertionSort(array, g, cnt, flag)
else:
flag = True
insertionSort(array, g, cnt, flag)
n = int(input())
array = []
for i in range(n):
array.append(int(input()))
G = [4, 1]
print(len(G))
for g in G:
if g != G[-1]:
print(g, end=' ')
else:
print(g)
shellSort(array, G)
for a in array:
print(a)
|
s029295348 | p02262 | u605879293 | 1522650738 | Python | Python3 | py | Runtime Error | 1250 | 9832 | 644 | def insertionSort(array, g):
global cnt
n = len(array)
for i in range(g, n):
v = array[i]
j = i - g
while j >= 0 and array[j] > v:
array[j+g] = array[j]
j = j - g
cnt += 1
array[j+g] = v
def shellSort(array, G):
global cnt
cnt = 0
flag = False
for g in G:
insertionSort(array, g)
n = int(input())
array = []
for i in range(n):
array.append(int(input()))
G = []
h = 1
while h <= n:
G.append(h)
h = 3 * h + 1
G.reverse()
print(len(G))
print(' '.join(map(str, G)))
shellSort(array, G)
print(cnt)
for a in array:
print(a)
|
s689208094 | p02262 | u605879293 | 1522651563 | Python | Python3 | py | Runtime Error | 1340 | 9828 | 618 | def insertionSort(array, g):
global cnt
n = len(array)
for i in range(g, n):
v = array[i]
j = i - g
while j >= 0 and array[j] > v:
array[j+g] = array[j]
j = j - g
cnt += 1
array[j+g] = v
def shellSort(array, G):
global cnt
cnt = 0
for g in G:
insertionSort(array, g)
n = int(input())
array = []
for i in range(n):
array.append(int(input()))
G = []
h = 1
while h <= n:
G.insert(0, h)
h = 3 * h + 1
print(len(G))
print(' '.join(map(str, G)))
shellSort(array, G)
print(cnt)
for a in array:
print(a)
|
s282682400 | p02262 | u605879293 | 1522652043 | Python | Python3 | py | Runtime Error | 1340 | 10628 | 594 | def insertionSort(array, g):
global cnt
n = len(array)
for i in range(g, n):
v = array[i]
j = i - g
while j >= 0 and array[j] > v:
array[j+g] = array[j]
j = j - g
cnt += 1
array[j+g] = v
def shellSort(array, G):
global cnt
cnt = 0
for g in G:
insertionSort(array, g)
n = int(input())
array = []
for i in range(n):
array.append(int(input()))
G = []
h = 1
while h <= n:
G.insert(0, h)
h = 3 * h + 1
print(len(G))
print(*G)
shellSort(array, G)
print(cnt)
print(*array, sep='\n')
|
s173918456 | p02262 | u114315703 | 1523411650 | Python | Python3 | py | Runtime Error | 20 | 5616 | 617 | cnt = 0
def insertionSort(A, n, g):
global cnt
for i in range(g, n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j = j - g
cnt += 1
A[j+g] = v
def shellSort(A, n):
global cnt
G = [i for i in reversed(range(1, len(A), 3))]
m = len(G)
for i in range(0, m):
insertionSort(A, n, G[i])
print(m)
for e in G[:-1]:
print(e, end=' ')
print(G[-1])
print(cnt)
for e in A:
print(e)
n = int(input())
A = []
for i in range(n):
A.append(int(input()))
shellSort(A, n)
|
s395907936 | p02262 | u114315703 | 1523412226 | Python | Python3 | py | Runtime Error | 20 | 5616 | 634 | cnt = 0
def insertionSort(A, n, g):
global cnt
for i in range(g, n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j = j - g
cnt += 1
A[j+g] = v
def shellSort(A, n):
global cnt
G = [i for i in reversed(range(1, len(A), min(3, len(A) - 1)))]
m = len(G)
for i in range(0, m):
insertionSort(A, n, G[i])
print(m)
for e in G[:-1]:
print(e, end=' ')
print(G[-1])
print(cnt)
for e in A:
print(e)
n = int(input())
A = []
for i in range(n):
A.append(int(input()))
shellSort(A, n)
|
s160320813 | p02262 | u114315703 | 1523412663 | Python | Python3 | py | Runtime Error | 1320 | 9832 | 656 | cnt = 0
def insertionSort(A, n, g):
global cnt
for i in range(g, n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j = j - g
cnt += 1
A[j+g] = v
def shellSort(A, n):
global cnt
G = []
v = 1
while v <= len(A):
G.insert(0, v)
v = 3 * v + 1
m = len(G)
for i in range(0, m):
insertionSort(A, n, G[i])
print(m)
for e in G[:-1]:
print(e, end=' ')
print(G[-1])
print(cnt)
for e in A:
print(e)
n = int(input())
A = []
for i in range(n):
A.append(int(input()))
shellSort(A, n)
|
s754756854 | p02262 | u114315703 | 1523412738 | Python | Python3 | py | Runtime Error | 1270 | 9844 | 686 | cnt = 0
def insertionSort(A, n, g):
global cnt
for i in range(g, n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j = j - g
cnt += 1
A[j+g] = v
def shellSort(A, n):
global cnt
G = []
v = 1
while v <= len(A):
G.append(v)
v = 3 * v + 1
m = len(G)
G = [e for e in reversed(G)]
for i in range(0, m):
insertionSort(A, n, G[i])
print(m)
for e in G[:-1]:
print(e, end=' ')
print(G[-1])
print(cnt)
for e in A:
print(e)
n = int(input())
A = []
for i in range(n):
A.append(int(input()))
shellSort(A, n)
|
s182722236 | p02262 | u114315703 | 1523413382 | Python | Python3 | py | Runtime Error | 1260 | 9832 | 676 | cnt = 0
def insertionSort(A, n, g):
global cnt
for i in range(g, n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j = j - g
cnt += 1
A[j+g] = v
def shellSort(A, n):
global cnt
G = []
v = 1
while v <= len(A):
G.append(v)
v = 3 * v + 1
m = len(G)
for i in range(0, m):
insertionSort(A, n, G[m - i - 1])
print(m)
for e in range(m - 1, 0, -1):
print(G[e], end=' ')
print(G[0])
print(cnt)
for e in A:
print(e)
n = int(input())
A = []
for i in range(n):
A.append(int(input()))
shellSort(A, n)
|
s616731861 | p02262 | u114315703 | 1523413564 | Python | Python3 | py | Runtime Error | 1330 | 9832 | 739 | cnt = 0
def insertionSort(A, n, g):
global cnt
for i in range(g, n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j = j - g
cnt += 1
A[j+g] = v
def shellSort(A, n):
global cnt
G = []
v = 1
while v <= len(A):
G.append(v)
v = 3 * v + 1
m = len(G)
print(m)
for i in range(0, m):
insertionSort(A, n, G[m - i - 1])
print(G[m - i - 1], end=' ') if i != m - 1 else print(G[m - i - 1])
# for e in range(m - 1, 0, -1):
# print(G[e], end=' ')
print(cnt)
for e in A:
print(e)
n = int(input())
A = []
for i in range(n):
A.append(int(input()))
shellSort(A, n)
|
s751245437 | p02262 | u126478680 | 1524955808 | Python | Python3 | py | Runtime Error | 1290 | 11740 | 821 | #! python
# shell_sort.py
import copy
import math
count = 0
def insertion_sort(A, N, g):
global count
A_ = copy.copy(A)
for i in range(g, N):
v = A_[i]
j = i - g
while j >= 0 and A_[j] > v:
A_[j+g] = A_[j]
j = j - g
count += 1
A_[j + g] = v
return A_
# h_(i+1) = 3h_i + 1 が最良の間隔
def shell_sort(A, N):
A_ = copy.copy(A)
h = 1
G = []
while True:
G.append(h)
h = 3*h + 1
if h > N:
break
G = G[::-1]
m = len(G)
for i in range(m):
A_ = insertion_sort(A_, N, G[i])
return A_, m, G
n = int(input())
A = [int(input()) for i in range(n)]
A, m, G = shell_sort(A, n)
print(m)
print(' '.join([str(h) for h in G]))
print(count)
for x in A:
print(x)
|
s010972739 | p02262 | u126478680 | 1524956093 | Python | Python3 | py | Runtime Error | 1450 | 10676 | 744 | #! python
# shell_sort.py
import copy
import math
count = 0
def insertion_sort(A, N, g):
global count
for i in range(g, N):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j = j - g
count += 1
A[j + g] = v
# h_(i+1) = 3h_i + 1 が最良の間隔
def shell_sort(A, N):
h = 1
G = []
while True:
G.append(h)
h = 3*h + 1
if h > N:
break
G = G[::-1]
m = len(G)
for i in range(m):
insertion_sort(A, N, G[i])
return m, G
n = int(input())
A = [int(input()) for i in range(n)]
m, G = shell_sort(A, n)
print(m)
print(' '.join([str(h) for h in G]))
print(count)
for x in A:
print(x)
|
s402149631 | p02262 | u255317651 | 1524968569 | Python | Python3 | py | Runtime Error | 0 | 0 | 719 | # -*- coding: utf-8 -*-
"""
Created on Sun Apr 29 10:42:20 2018
ALDS1-2d
@author: maezawa
"""
import numpy as np
def insertion(a, n, g):
global cnt
for i in range(g, n):
v = a[i]
j = i-g
while j>=0 and a[j]>v:
a[j+g] = a[j]
j = j - g
cnt += 1
a[j+g] = v
def print_array(g):
ans = str(g[0])
for i in range(1,len(g)):
ans += ' '+str(g[i])
print(ans)
n = int(input())
a=[]
for i in range(n):
a.append(int(input()))
cnt = 0
m = int(np.floor(np.log2(n)))
g = [2**i for i in reversed(range(m))]
for i in range(m):
insertion(a, n, g[i])
print(m)
print_array(g)
print(cnt)
for i in range(n):
print(a[i])
|
s682264956 | p02262 | u255317651 | 1524968791 | Python | Python3 | py | Runtime Error | 30 | 5688 | 706 | # -*- coding: utf-8 -*-
"""
Created on Sun Apr 29 10:42:20 2018
ALDS1-2d
@author: maezawa
"""
import math
def insertion(a, n, g):
global cnt
for i in range(g, n):
v = a[i]
j = i-g
while j>=0 and a[j]>v:
a[j+g] = a[j]
j = j - g
cnt += 1
a[j+g] = v
def print_array(g):
ans = str(g[0])
for i in range(1,len(g)):
ans += ' '+str(g[i])
print(ans)
n = int(input())
a=[]
for i in range(n):
a.append(int(input()))
cnt = 0
m = int(math.log(n, 2))
g = [2**i for i in reversed(range(m))]
for i in range(m):
insertion(a, n, g[i])
print(m)
print_array(g)
print(cnt)
for i in range(n):
print(a[i])
|
s892368019 | p02262 | u255317651 | 1524969135 | Python | Python3 | py | Runtime Error | 20 | 5684 | 706 | # -*- coding: utf-8 -*-
"""
Created on Sun Apr 29 10:42:20 2018
ALDS1-2d
@author: maezawa
"""
import math
def insertion(a, n, g):
global cnt
for i in range(g, n):
v = a[i]
j = i-g
while j>=0 and a[j]>v:
a[j+g] = a[j]
j = j - g
cnt += 1
a[j+g] = v
def print_array(g):
ans = str(g[0])
for i in range(1,len(g)):
ans += ' '+str(g[i])
print(ans)
n = int(input())
a=[]
for i in range(n):
a.append(int(input()))
cnt = 0
m = int(math.log(n, 2))
g = [2**i for i in reversed(range(m))]
for i in range(m):
insertion(a, n, g[i])
print(m)
print_array(g)
print(cnt)
for i in range(n):
print(a[i])
|
s448862411 | p02262 | u255317651 | 1524969174 | Python | Python3 | py | Runtime Error | 20 | 5688 | 706 | # -*- coding: utf-8 -*-
"""
Created on Sun Apr 29 10:42:20 2018
ALDS1-2d
@author: maezawa
"""
import math
def insertion(a, n, g):
global cnt
for i in range(g, n):
v = a[i]
j = i-g
while j>=0 and a[j]>v:
a[j+g] = a[j]
j = j - g
cnt += 1
a[j+g] = v
def print_array(g):
ans = str(g[0])
for i in range(1,len(g)):
ans += ' '+str(g[i])
print(ans)
n = int(input())
a=[]
for i in range(n):
a.append(int(input()))
cnt = 0
m = int(math.log(n, 2))
g = [2**i for i in reversed(range(m))]
for i in range(m):
insertion(a, n, g[i])
print(m)
print_array(g)
print(cnt)
for i in range(n):
print(a[i])
|
s747519235 | p02262 | u255317651 | 1524969364 | Python | Python3 | py | Runtime Error | 4830 | 9916 | 754 | # -*- coding: utf-8 -*-
"""
Created on Sun Apr 29 10:42:20 2018
ALDS1-2d
@author: maezawa
"""
import math
def insertion(a, n, g):
global cnt
for i in range(g, n):
v = a[i]
j = i-g
while j>=0 and a[j]>v:
a[j+g] = a[j]
j = j - g
cnt += 1
a[j+g] = v
def print_array(g):
ans = str(g[0])
if len(g) > 1:
for i in range(1,len(g)):
ans += ' '+str(g[i])
print(ans)
n = int(input())
a=[]
for i in range(n):
a.append(int(input()))
cnt = 0
m = int(math.log(n, 2))
if m == 0:
m = 1
g = [2**i for i in reversed(range(m))]
for i in range(m):
insertion(a, n, g[i])
print(m)
print_array(g)
print(cnt)
for i in range(n):
print(a[i])
|
s747492201 | p02262 | u255317651 | 1524972954 | Python | Python3 | py | Runtime Error | 1320 | 9912 | 936 | # -*- coding: utf-8 -*-
"""
Created on Sun Apr 29 10:42:20 2018
ALDS1-2d
@author: maezawa
"""
import math
def insertion(a, n, g):
global cnt
for i in range(g, n):
v = a[i]
j = i-g
while j>=0 and a[j]>v:
a[j+g] = a[j]
j = j - g
cnt += 1
a[j+g] = v
def print_array(g):
ans = str(g[0])
if len(g) > 1:
for i in range(1,len(g)):
ans += ' '+str(g[i])
print(ans)
def gn(n):
g = []
h = 1
while True:
g.append(h)
h = 3*h + 1
if h>= n:
return g
n = int(input())
a=[]
for i in range(n):
a.append(int(input()))
cnt = 0
#m = int(math.log(n, 2))
#if m == 0:
# m = 1
#g = [2**i for i in reversed(range(m))]
g = list(reversed(gn(n)))
m = len(g)
for i in range(m):
insertion(a, n, g[i])
print(m)
print_array(g)
print(cnt)
for i in range(n):
print(a[i])
|
s575628898 | p02262 | u255317651 | 1524973269 | Python | Python3 | py | Runtime Error | 1330 | 9908 | 935 | # -*- coding: utf-8 -*-
"""
Created on Sun Apr 29 10:42:20 2018
ALDS1-2d
@author: maezawa
"""
import math
def insertion(a, n, g):
global cnt
for i in range(g, n):
v = a[i]
j = i-g
while j>=0 and a[j]>v:
a[j+g] = a[j]
j = j - g
cnt += 1
a[j+g] = v
def print_array(g):
ans = str(g[0])
if len(g) > 1:
for i in range(1,len(g)):
ans += ' '+str(g[i])
print(ans)
def gn(n):
g = []
h = 1
while True:
g.append(h)
h = 3*h + 1
if h> n:
return g
n = int(input())
a=[]
for i in range(n):
a.append(int(input()))
cnt = 0
#m = int(math.log(n, 2))
#if m == 0:
# m = 1
#g = [2**i for i in reversed(range(m))]
g = list(reversed(gn(n)))
m = len(g)
for i in range(m):
insertion(a, n, g[i])
print(m)
print_array(g)
print(cnt)
for i in range(n):
print(a[i])
|
s194509763 | p02262 | u255317651 | 1524973577 | Python | Python3 | py | Runtime Error | 1740 | 9912 | 935 | # -*- coding: utf-8 -*-
"""
Created on Sun Apr 29 10:42:20 2018
ALDS1-2d
@author: maezawa
"""
import math
def insertion(a, n, g):
global cnt
for i in range(g, n):
v = a[i]
j = i-g
while j>=0 and a[j]>v:
a[j+g] = a[j]
j = j - g
cnt += 1
a[j+g] = v
def print_array(g):
ans = str(g[0])
if len(g) > 1:
for i in range(1,len(g)):
ans += ' '+str(g[i])
print(ans)
def gn(n):
g = []
h = 1
while True:
g.append(h)
h = 3*h + 1
if h> n:
return g
n = int(input())
a=[]
for i in range(n):
a.append(int(input()))
cnt = 0
#m = int(math.log(n, 2))
#if m == 0:
# m = 1
#g = [2**i for i in reversed(range(m))]
g = list(reversed(gn(n)))
m = len(g)
for i in range(m):
insertion(a, n, g[i])
print(m)
print_array(g)
print(cnt)
for i in range(n):
print(a[i])
|
s282649337 | p02262 | u255317651 | 1524974173 | Python | Python3 | py | Runtime Error | 1330 | 9848 | 924 | # -*- coding: utf-8 -*-
"""
Created on Sun Apr 29 10:42:20 2018
ALDS1-2d
@author: maezawa
"""
def insertion(a, n, g):
global cnt
for i in range(g, n):
v = a[i]
j = i-g
while j>=0 and a[j]>v:
a[j+g] = a[j]
j = j - g
cnt += 1
a[j+g] = v
def print_array(g):
ans = str(g[0])
if len(g) > 1:
for i in range(1,len(g)):
ans += ' '+str(g[i])
print(ans)
def gn(n):
g = []
h = 1
while True:
g.append(h)
h = 3*h + 1
if h>= n:
return g
n = int(input())
a=[]
for i in range(n):
a.append(int(input()))
cnt = 0
#m = int(math.log(n, 2))
#if m == 0:
# m = 1
#g = [2**i for i in reversed(range(m))]
g = list(reversed(gn(n)))
m = len(g)
for i in range(m):
insertion(a, n, g[i])
print(m)
print_array(g)
print(cnt)
for i in range(n):
print(a[i])
|
s969010616 | p02262 | u255317651 | 1524976972 | Python | Python3 | py | Runtime Error | 1260 | 9848 | 925 | # -*- coding: utf-8 -*-
"""
Created on Sun Apr 29 10:42:20 2018
ALDS1-2d
@author: maezawa
"""
def insertion(a, n, g):
global cnt
for i in range(g, n):
v = a[i]
j = i-g
while j>=0 and a[j]>v:
a[j+g] = a[j]
j = j - g
cnt += 1
a[j+g] = v
def print_array(g):
ans = str(g[0])
if len(g) > 1:
for i in range(1,len(g)):
ans += ' '+str(g[i])
print(ans)
def gn(n):
g = []
h = 1
while True:
g.append(h)
h = 3*h + 1
if h>= n:
return g
n = int(input())
a=[]
for i in range(n):
a.append(int(input()))
cnt = 0
#m = int(math.log(n, 2))
#if m == 0:
# m = 1
#g = [2**i for i in reversed(range(m))]
g = list(reversed(gn(n)))
m = len(g)
for i in range(m):
insertion(a, n, g[i])
print(m)
print_array(g)
print(cnt)
for i in range(n):
print(a[i])
|
s245571074 | p02262 | u126478680 | 1525198411 | Python | Python3 | py | Runtime Error | 1210 | 9904 | 675 | import math
count = 0
m = 0
G = []
def insertion_sort(A, N, g):
global count
for i in range(g, N):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j = j - g
count += 1
A[j + g] = v
# h_(i+1) = 3h_i + 1 が最良の間隔 (らしい)
def shell_sort(A, N):
global m, G
m = math.floor(math.log(2*N+1, 3))
G = [int((pow(3, i)-1)/2) for i in range(m, 0, -1)]
for i in range(m):
insertion_sort(A, N, G[i])
n = int(input())
A = [int(input()) for i in range(n)]
shell_sort(A, n)
print(m)
print(' '.join([str(h) for h in G]))
print(count)
for x in A:
print(x)
|
s873617401 | p02262 | u311299757 | 1525441984 | Python | Python3 | py | Runtime Error | 7380 | 11584 | 687 | from typing import List
def insertion_sort(arr: List[int], n: int, g: int):
cnt = 0
for i in range(g, n):
v = arr[i]
j = i - g
while (j >= 0 and arr[j] > v):
arr[j + g] = arr[j]
j = j - g
cnt += 1
arr[j + g] = v
return cnt
def shell_sort(arr, n):
G = [(3 * i + 1) for i in range(100) if (3 * i + 1) <= n][::-1]
m = len(G)
cnt = sum([insertion_sort(arr, n, G[i]) for i in range(m)])
return m, ' '.join([str(x) for x in G]), cnt
n = int(input())
num_arr = [int(input()) for _ in range(n)]
m, G, cnt = shell_sort(num_arr, n)
print(m)
print(G)
print(cnt)
for x in num_arr:
print(x)
|
s024981415 | p02262 | u986478725 | 1527429941 | Python | Python3 | py | Runtime Error | 20 | 5608 | 1404 | # ALDS1_2_D.
# シェルソート。
# 理論上、h[i + 1] = h[i] + 1, h[0] = 1という数列が使えて、
# これによると計算量がO(n^1.25)くらいになるとか。
# 挿入ソートを間隔でメソッド化してcntを出力→加算、の流れ。
def show(a):
# 配列の中身を出力する。
_str = ""
for i in range(len(a) - 1):
_str += str(a[i]) + " "
_str += str(a[len(a) - 1])
print(_str)
def insertion_sort(a, g):
# 間隔gでの挿入ソート(g=1が通常の挿入ソート)。
# ALDS1_1_Aでcur - 1って、ここをcur - gにするだけ。
# 交換回数をreturnする。
count = 0
for i in range(g, len(a)):
cur = i
while cur >= g:
if a[cur - g] > a[cur]:
a[cur - g], a[cur] = a[cur], a[cur - g]
else: break
cur -= g; count += 1
return count
def shell_sort(a):
cnt = 0
h = 1
G = []
while h < len(a): # 数列を生成。
G.append(h)
h = 3 * h + 1
G.reverse() # 逆にしておく。というかそういう指示が出てる。
print(len(G))
show(G)
for i in range(len(G)):
cnt += insertion_sort(a, G[i])
print(cnt)
def main():
N = int(input())
A = [int(input()) for i in range(N)]
shell_sort(A)
for i in range(N): print(A[i])
if __name__ == "__main__":
main()
|
s268707309 | p02262 | u986478725 | 1527430182 | Python | Python3 | py | Runtime Error | 1700 | 9848 | 1553 | # ALDS1_2_D.
# シェルソート。
# 理論上、h[i + 1] = h[i] + 1, h[0] = 1という数列が使えて、
# これによると計算量がO(n^1.25)くらいになるとか。
# 挿入ソートを間隔でメソッド化してcntを出力→加算、の流れ。
def show(a):
# 配列の中身を出力する。
_str = ""
for i in range(len(a) - 1):
_str += str(a[i]) + " "
_str += str(a[len(a) - 1])
print(_str)
def insertion_sort(a, g):
# 間隔gでの挿入ソート(g=1が通常の挿入ソート)。
# ALDS1_1_Aでcur - 1って、ここをcur - gにするだけ。
# 交換回数をreturnする。
count = 0
# なお、gがlen(a)の場合は何もしないで0が返る。
for i in range(g, len(a)):
cur = i
while cur >= g:
if a[cur - g] > a[cur]:
a[cur - g], a[cur] = a[cur], a[cur - g]
else: break
cur -= g; count += 1
return count
def shell_sort(a):
cnt = 0
h = 1
G = []
# ↓≦にしないとコーナーケースの時に対応できない。
while h <= len(a): # 数列を生成。
G.append(h)
h = 3 * h + 1
G.reverse() # 逆にしておく。というかそういう指示が出てる。
print(len(G))
show(G)
for i in range(len(G)):
cnt += insertion_sort(a, G[i])
print(cnt)
def main():
N = int(input())
A = [int(input()) for i in range(N)]
shell_sort(A)
for i in range(N): print(A[i])
if __name__ == "__main__":
main()
|
s401090451 | p02262 | u986478725 | 1527431149 | Python | Python3 | py | Runtime Error | 1660 | 9844 | 1553 | # ALDS1_2_D.
# シェルソート。
# 理論上、h[i + 1] = h[i] + 1, h[0] = 1という数列が使えて、
# これによると計算量がO(n^1.25)くらいになるとか。
# 挿入ソートを間隔でメソッド化してcntを出力→加算、の流れ。
def show(a):
# 配列の中身を出力する。
_str = ""
for i in range(len(a) - 1):
_str += str(a[i]) + " "
_str += str(a[len(a) - 1])
print(_str)
def insertion_sort(a, g):
# 間隔gでの挿入ソート(g=1が通常の挿入ソート)。
# ALDS1_1_Aでcur - 1って、ここをcur - gにするだけ。
# 交換回数をreturnする。
count = 0
# なお、gがlen(a)の場合は何もしないで0が返る。
for i in range(g, len(a)):
cur = i
while cur >= g:
if a[cur - g] > a[cur]:
a[cur - g], a[cur] = a[cur], a[cur - g]
else: break
cur -= g; count += 1
return count
def shell_sort(a):
cnt = 0
h = 1
G = []
# ↓≦にしないとコーナーケースの時に対応できない。
while h <= len(a): # 数列を生成。
G.append(h)
h = 3 * h + 1
G.reverse() # 逆にしておく。というかそういう指示が出てる。
print(len(G))
show(G)
for i in range(len(G)):
cnt += insertion_sort(a, G[i])
print(cnt)
def main():
N = int(input())
A = [int(input()) for i in range(N)]
shell_sort(A)
for i in range(N): print(A[i])
if __name__ == "__main__":
main()
|
s866256537 | p02262 | u986478725 | 1527431712 | Python | Python3 | py | Runtime Error | 1340 | 9848 | 1583 | # ALDS1_2_D.
# シェルソート。
# 理論上、h[i + 1] = h[i] + 1, h[0] = 1という数列が使えて、
# これによると計算量がO(n^1.25)くらいになるとか。
# 挿入ソートを間隔でメソッド化してcntを出力→加算、の流れ。
def show(a):
# 配列の中身を出力する。
_str = ""
for i in range(len(a) - 1):
_str += str(a[i]) + " "
_str += str(a[len(a) - 1])
print(_str)
def insertion_sort(a, g):
# 間隔gでの挿入ソート(g=1が通常の挿入ソート)。
# ALDS1_1_Aでcur - 1って、ここをcur - gにするだけ。
# 交換回数をreturnする。
count = 0
# なお、gがlen(a)の場合は何もしないで0が返る。
for i in range(g, len(a)):
cur = i
v = a[cur]
while cur >= g:
if a[cur - g] > v:
a[cur] = a[cur - g]; count += 1
else:
break
cur -= g
a[cur] = v
return count
def shell_sort(a):
cnt = 0
h = 1
G = []
# ↓≦にしないとコーナーケースの時に対応できない。
while h <= len(a): # 数列を生成。
G.append(h)
h = 3 * h + 1
G.reverse() # 逆にしておく。というかそういう指示が出てる。
print(len(G))
show(G)
for i in range(len(G)):
cnt += insertion_sort(a, G[i])
print(cnt)
def main():
N = int(input())
A = [int(input()) for i in range(N)]
shell_sort(A)
for i in range(N): print(A[i])
if __name__ == "__main__":
main()
|
s309743382 | p02262 | u986478725 | 1527432086 | Python | Python3 | py | Runtime Error | 0 | 0 | 1674 | # ALDS1_2_D.
# シェルソート。
# 理論上、h[i + 1] = h[i] + 1, h[0] = 1という数列が使えて、
# これによると計算量がO(n^1.25)くらいになるとか。
# 挿入ソートを間隔でメソッド化してcntを出力→加算、の流れ。
def show(a):
# 配列の中身を出力する。
_str = ""
for i in range(len(a) - 1):
_str += str(a[i]) + " "
_str += str(a[len(a) - 1])
print(_str)
def insertion_sort(a, g):
# 間隔gでの挿入ソート(g=1が通常の挿入ソート)。
# ALDS1_1_Aでcur - 1って、ここをcur - gにするだけ。
# 交換回数をreturnする。
count = 0
# なお、gがlen(a)の場合は何もしないで0が返る。
for i in range(g, len(a)):
cur = i
v = a[cur]
while cur >= g:
if a[cur - g] > v: # vより大きい数をスルーしていく感じ。
a[cur] = a[cur - g]; count += 1
else:
break
cur -= g
a[cur] = v
return count
def shell_sort(a):
cnt = 0
h = 1
G = []
# ↓≦にしないとコーナーケースの時に対応できない。
while h <= len(a): # 数列を生成。
G.append(h)
h = 3 * h + 1
G.reverse() # 逆にしておく。というかそういう指示が出てる。
print(len(G))
show(G)
for i in range(len(G)):
cnt += insertion_sort(a, G[i])
print(cnt)
def main():
N = int(input())
A = [int(input()) for i in range(N)]
shell_sort(A)
for i in range(N):
print(A[i])
if i > 500000 break
if __name__ == "__main__":
main()
|
s574646912 | p02262 | u986478725 | 1527432124 | Python | Python3 | py | Runtime Error | 1330 | 9844 | 1675 | # ALDS1_2_D.
# シェルソート。
# 理論上、h[i + 1] = h[i] + 1, h[0] = 1という数列が使えて、
# これによると計算量がO(n^1.25)くらいになるとか。
# 挿入ソートを間隔でメソッド化してcntを出力→加算、の流れ。
def show(a):
# 配列の中身を出力する。
_str = ""
for i in range(len(a) - 1):
_str += str(a[i]) + " "
_str += str(a[len(a) - 1])
print(_str)
def insertion_sort(a, g):
# 間隔gでの挿入ソート(g=1が通常の挿入ソート)。
# ALDS1_1_Aでcur - 1って、ここをcur - gにするだけ。
# 交換回数をreturnする。
count = 0
# なお、gがlen(a)の場合は何もしないで0が返る。
for i in range(g, len(a)):
cur = i
v = a[cur]
while cur >= g:
if a[cur - g] > v: # vより大きい数をスルーしていく感じ。
a[cur] = a[cur - g]; count += 1
else:
break
cur -= g
a[cur] = v
return count
def shell_sort(a):
cnt = 0
h = 1
G = []
# ↓≦にしないとコーナーケースの時に対応できない。
while h <= len(a): # 数列を生成。
G.append(h)
h = 3 * h + 1
G.reverse() # 逆にしておく。というかそういう指示が出てる。
print(len(G))
show(G)
for i in range(len(G)):
cnt += insertion_sort(a, G[i])
print(cnt)
def main():
N = int(input())
A = [int(input()) for i in range(N)]
shell_sort(A)
for i in range(N):
print(A[i])
if i > 500000: break
if __name__ == "__main__":
main()
|
s277106508 | p02262 | u986478725 | 1527432745 | Python | Python3 | py | Runtime Error | 1260 | 9840 | 1691 | # ALDS1_2_D.
# シェルソート。
# 理論上、h[i + 1] = h[i] + 1, h[0] = 1という数列が使えて、
# これによると計算量がO(n^1.25)くらいになるとか。
# 挿入ソートを間隔でメソッド化してcntを出力→加算、の流れ。
def show(a):
# 配列の中身を出力する。
_str = ""
for i in range(len(a) - 1):
_str += str(a[i]) + " "
_str += str(a[len(a) - 1])
print(_str)
def insertion_sort(a, g):
# 間隔gでの挿入ソート(g=1が通常の挿入ソート)。
# ALDS1_1_Aでcur - 1って、ここをcur - gにするだけ。
# 交換回数をreturnする。
count = 0
# なお、gがlen(a)の場合は何もしないで0が返る。
for i in range(g, len(a)):
cur = i
v = a[cur]
while cur >= g:
if a[cur - g] > v: # vより大きい数をスルーしていく感じ。
a[cur] = a[cur - g]; count += 1
else:
break
cur -= g
a[cur] = v
return count
def shell_sort(a):
cnt = 0
h = 1
G = []
# ↓≦にしないとコーナーケースの時に対応できない。
while h <= len(a): # 数列を生成。
G.append(h)
h = 3 * h + 1
G.reverse() # 逆にしておく。というかそういう指示が出てる。
print(len(G))
show(G)
for i in range(len(G)):
cnt += insertion_sort(a, G[i])
print(cnt)
def main():
N = int(input())
A = [int(input()) for i in range(N)]
shell_sort(A)
for i in range(N):
print(A[i])
if i > 300000 and N > 500000: break
if __name__ == "__main__":
main()
|
s400786861 | p02262 | u684241248 | 1527432885 | Python | Python3 | py | Runtime Error | 0 | 0 | 655 | N = int(input())
ary = [int(input()) for _ in range(N)]
def insertion_sort(ary, g):
cnt = 0
for i in range(g, N):
v = ary[i]
j = i - g
while j >= 0 and ary[j] > v:
ary[j + g] = ary[j]
j -= g
cnt += 1
ary[j + g] = v
return cnt
def shell_sort(ary):
g = []
gn = 1
while True:
if gn + 3 < N:
gn += 3
g.append(gn)
m = len(gn)
cnt = 0
for i in range(0, m):
cnt += insertion_sort(ary, g[i])
print(m)
print(' '.join([str(_) for _ in g]))
print(cnt)
[print(_) for _ in ary]
shell_sort(ary)
|
s024684667 | p02262 | u684241248 | 1527432996 | Python | Python3 | py | Runtime Error | 0 | 0 | 687 | N = int(input())
ary = [int(input()) for _ in range(N)]
def insertion_sort(ary, g):
cnt = 0
for i in range(g, N):
v = ary[i]
j = i - g
while j >= 0 and ary[j] > v:
ary[j + g] = ary[j]
j -= g
cnt += 1
ary[j + g] = v
return cnt
def shell_sort(ary):
g = []
gn = 1
while True:
if gn + 3 < N:
gn += 3
g.append(gn)
else:
break
m = len(gn)
cnt = 0
for i in range(0, m):
cnt += insertion_sort(ary, g[i])
print(m)
print(' '.join([str(_) for _ in g]))
print(cnt)
[print(_) for _ in ary]
shell_sort(ary)
|
s103647827 | p02262 | u303842929 | 1527746771 | Python | Python3 | py | Runtime Error | 0 | 0 | 1413 | #include <iostream>
#include <cstdlib>
#include <vector>
//shellSort(A, n) は、一定の間隔 g だけ離れた要素のみを対象とした挿入ソートである insertionSort(A, n, g) を、最初は大きい値から g を狭めながら繰り返します。これをシェルソートと言います。
//上の疑似コードの ? を埋めてこのプログラムを完成させてください。n と数列 A が与えられるので、疑似コード中の m、m 個の整数 Gi(i=0,1,...,m-1)、入力 Aを昇順にした列を出力するプログラムを作成してください。ただし、出力は以下の条件を満 たす必要があります。
using namespace std;
int cnt = 0;
vector<int> G;
void insertionSort(int A[], int n, int g){
for(int i = g; i < n; i++){
int v = A[i];
int j = i - g;
while(j >= 0 && A[j] > v){
A[j + g] = A[j];
j -= g;
cnt++;
}
A[j + g] = v;
}
}
void shellSort(int A[], int n){
int p = (n > 1) ? n / 4 : n;
while(p > 0){
G.push_back(p);
p /= 4;
}
int m = n / 4;
for(int i = 0; i < m; i++) insertionSort(A, n, G[i]);
}
int main(){
int n;
cin >> n;
int A[n];
for(int i = 0; i < n; i++) cin >> A[i];
shellSort(A, n);
cout << G.size() << '\n';
for(int i = 0; i < G.size(); i++){
cout << G[i];
if(i != n - 1) cout << ' ';
}
cout << '\n';
cout << cnt << '\n';
for(int i = 0; i < n; i++) cout << A[i] << endl;
}
|
s063132333 | p02262 | u682153677 | 1528876894 | Python | Python3 | py | Runtime Error | 0 | 0 | 797 | # -*- coding: utf-8 -*-
def insertionSort(A, n, g):
cnt = 0
for i in range(g, n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j + g] = A[j]
j = j - g
cnt += 1
A[j + g] = v
print_line(A, cnt)
def shellSort(A, n):
m = 0
G = []
while n >= (3 ** m - 1) / 2:
m += 1
G.append((3 ** m - 1) / 2)
print(m)
for i in range(len(G)):
if i == len(G) - 1:
print(G[i])
else:
print("{0}".format(G[i]), end=' ')
for i in range(m):
insertionSort(A, n, G[i])
def print_line(A, cnt):
print(cnt)
for i in range(len(A)):
print(A[i])
A = []
n = int(input())
for i in range(n):
A.append(int(input()))
shellSort(A, n)
|
s057013120 | p02262 | u308033440 | 1528953849 | Python | Python3 | py | Runtime Error | 2560 | 13772 | 716 | def insertionSort(A,n,g):
for i in range(g,n,1):
v = int(A[i])
j = i - g
while j >= 0 and int(A[j]) > v:
global cnt
A[j + g] = A[j]
j = j - g
cnt = cnt + 1
A[j+g] = str(v)
def shellSort(A,n):
global cnt
global G
G = []
cnt = 0
h = 1
while h <= n:
G.append(h)
h = 3*h + 1
m = len(G)
print(m)
G.reverse()
print(' '.join(map(str, G)))
for i in range(0,m,1):
insertionSort(A,n,G[i])
print(cnt)
n = int(input())
#改行で標準入力を受け付ける場合
A = []
for i in range(n):
A.append(input())
shellSort(A,n)
print('\n'.join(A))
|
s114017979 | p02262 | u308033440 | 1528953881 | Python | Python3 | py | Runtime Error | 2610 | 13772 | 716 | def insertionSort(A,n,g):
for i in range(g,n,1):
v = int(A[i])
j = i - g
while j >= 0 and int(A[j]) > v:
global cnt
A[j + g] = A[j]
j = j - g
cnt = cnt + 1
A[j+g] = str(v)
def shellSort(A,n):
global cnt
global G
G = []
cnt = 0
h = 1
while h <= n:
G.append(h)
h = 3*h + 1
m = len(G)
print(m)
G.reverse()
print(' '.join(map(str, G)))
for i in range(0,m,1):
insertionSort(A,n,G[i])
print(cnt)
n = int(input())
#改行で標準入力を受け付ける場合
A = []
for i in range(n):
A.append(input())
shellSort(A,n)
print('\n'.join(A))
|
s843067894 | p02262 | u308033440 | 1528954834 | Python | Python3 | py | Runtime Error | 2520 | 13772 | 758 | def insertionSort(A,n,g):
for i in range(g,n,1):
v = int(A[i])
j = i - g
while j >= 0 and int(A[j]) > v:
global cnt
A[j + g] = A[j]
j = j - g
cnt = cnt + 1
A[j+g] = str(v)
def shellSort(A,n):
global cnt
global G
G = []
cnt = 0
h = 1
while h <= n:
G.append(h)
h = 3*h + 1
if(len(G)>100):
break
m = len(G)
print(m)
G.reverse()
print(' '.join(map(str, G)))
for i in range(0,m,1):
insertionSort(A,n,G[i])
print(cnt)
n = int(input())
#改行で標準入力を受け付ける場合
A = []
for i in range(n):
A.append(input())
shellSort(A,n)
print('\n'.join(A))
|
s211672708 | p02262 | u308033440 | 1528954860 | Python | Python3 | py | Runtime Error | 2620 | 13772 | 758 | def insertionSort(A,n,g):
for i in range(g,n,1):
v = int(A[i])
j = i - g
while j >= 0 and int(A[j]) > v:
global cnt
A[j + g] = A[j]
j = j - g
cnt = cnt + 1
A[j+g] = str(v)
def shellSort(A,n):
global cnt
global G
G = []
cnt = 0
h = 1
while h <= n:
G.append(h)
h = 3*h + 1
if(len(G)>100):
break
m = len(G)
print(m)
G.reverse()
print(' '.join(map(str, G)))
for i in range(0,m,1):
insertionSort(A,n,G[i])
print(cnt)
n = int(input())
#改行で標準入力を受け付ける場合
A = []
for i in range(n):
A.append(input())
shellSort(A,n)
print('\n'.join(A))
|
s505124495 | p02262 | u308033440 | 1528955177 | Python | Python3 | py | Runtime Error | 1260 | 10632 | 753 | def insertionSort(A,n,g):
for i in range(g,n,1):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
global cnt
A[j + g] = A[j]
j = j - g
cnt = cnt + 1
A[j+g] = v
def shellSort(A,n):
global cnt
global G
G = []
cnt = 0
h = 1
while h <= n:
G.append(h)
h = 3*h + 1
if(len(G)>100):
break
m = len(G)
print(m)
G.reverse()
print(' '.join(map(str, G)))
for i in range(0,m,1):
insertionSort(A,n,G[i])
print(cnt)
n = int(input())
#改行で標準入力を受け付ける場合
A = [int(input()) for i in range(n)]
shellSort(A,n)
# print('\n'.join(A))
print(*A,sep='\n')
|
s940886091 | p02262 | u308033440 | 1528955195 | Python | Python3 | py | Runtime Error | 1240 | 10632 | 753 | def insertionSort(A,n,g):
for i in range(g,n,1):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
global cnt
A[j + g] = A[j]
j = j - g
cnt = cnt + 1
A[j+g] = v
def shellSort(A,n):
global cnt
global G
G = []
cnt = 0
h = 1
while h <= n:
G.append(h)
h = 3*h + 1
if(len(G)>100):
break
m = len(G)
print(m)
G.reverse()
print(' '.join(map(str, G)))
for i in range(0,m,1):
insertionSort(A,n,G[i])
print(cnt)
n = int(input())
#改行で標準入力を受け付ける場合
A = [int(input()) for i in range(n)]
shellSort(A,n)
# print('\n'.join(A))
print(*A,sep='\n')
|
s305093587 | p02262 | u308033440 | 1528955230 | Python | Python3 | py | Runtime Error | 1300 | 10628 | 509 | def insertionSort(A, n, g):
global cnt
for i in range(g, n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j = j - g
cnt += 1
A[j+g] = v
n = int(input())
A = [int(input()) for i in range(n)]
cnt = 0
G = [1]
for i in range(99):
if n < 1 + 3*G[-1]:
break
G.append(1 + 3*G[-1])
m = len(G)
G.reverse()
for i in range(m):
insertionSort(A, n, G[i])
print(m)
print(*G)
print(cnt)
print(*A, sep='\n')
|
s485785305 | p02262 | u308033440 | 1528955410 | Python | Python3 | py | Runtime Error | 1330 | 9828 | 521 | n = int(input())
a = []
for i in range(n):
a.append(int(input()))
def insertionsort(a, n, g):
global c
for i in range(g, n):
v = a[i]
j = i - g
while j >= 0 and a[j] > v:
a[j + g] = a[j]
j = j - g
c += 1
a[j + g] = v
c = 0
g = [1]
while g[-1] * 3 + 1 < n:
g.append(g[-1] * 3 + 1)
g.reverse()
for i in range(len(g)):
insertionsort(a, n, g[i])
print(len(g))
print(" ".join(map(str, g)))
print(c)
for i in range(n):
print(a[i])
|
s474200227 | p02262 | u308033440 | 1528955677 | Python | Python3 | py | Runtime Error | 2510 | 13772 | 716 | def insertionSort(A,n,g):
for i in range(g,n,1):
v = int(A[i])
j = i - g
while j >= 0 and int(A[j]) > v:
global cnt
A[j + g] = A[j]
j = j - g
cnt = cnt + 1
A[j+g] = str(v)
def shellSort(A,n):
global cnt
G = []
cnt = 0
h = 1
while h <= n:
G.append(h)
h = 3*h + 1
m = len(G)
print(m)
G.reverse()
print(' '.join(map(str, G)))
for i in range(0,m,1):
insertionSort(A,n,G[i])
print(cnt)
n = int(input())
#改行で標準入力を受け付ける場合
A = []
for i in range(n):
A.append(input())
shellSort(A,n)
print('\n'.join(A))
|
s592275857 | p02262 | u308033440 | 1528955883 | Python | Python3 | py | Runtime Error | 0 | 0 | 772 | ef insert_sort(A, n, g, cnt):
for i in range(g, n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j -= g
cnt += 1
A[j+g] = v
return cnt
def shellSort(A, n):
cnt = 0
G = []; h = 0
while h <= n:
if 3 * h + 1 <= n:
h = 3 * h + 1
G.append(h)
else: break
G = sorted(G, reverse=True)
m = len(G)
for i in range(m):
cnt = insert_sort(A, n, G[i], cnt)
return m, cnt, G
A = []
n = int(input())
for i in range(n):
A.append(int(input()))
m, cnt, G = shellSort(A, n)
print(m)
for i in range(m):
if i == m - 1:
print(G[i])
else:
print(G[i], end=" ")
print(cnt)
for i in A:
print(i)
|
s450442407 | p02262 | u657361950 | 1529371266 | Python | Python3 | py | Runtime Error | 0 | 0 | 797 | import sys
def print_arr(arr):
for i in range(len(arr)):
sys.stdout.write(str(arr[i]))
if i != len(arr) - 1:
sys.stdout.write(' ')
print()
def insertion_sort(arr, n, g):
cnt = 0
for i in range(g, n):
v = arr[i]
j = i - g
while j >= 0 and arr[j] > v:
arr[j + g] = arr[j]
j = j - g
cnt += 1
arr[j + g] = v
return cnt
def shell_sort(arr, g):
cnt = 0
for i in range(len(g)):
cnt += insertion_sort(arr, len(arr), g[i])
return cnt
def get_gap(n):
lst = []
v = 1
while v <= n:
lst.append(v)
v += 3**cnt
if len(lst) == 0: lst.append(1)
return list(reversed(lst))
n = int(input())
arr = [0] * n
for i in range(n):
arr[i] = int(input())
g = get_gap(n)
m = len(g)
cnt = shell_sort(arr, g)
print(m)
print_arr(g)
print(cnt)
for i in range(n):
print(arr[i])
|
s498251412 | p02262 | u424720817 | 1529387688 | Python | Python3 | py | Runtime Error | 0 | 0 | 774 | def main():
n = int(input())
numbers = [int(input()) for i in range(n)]
count = shellSort(numbers, n)
print(count)
[print(i) for i in numbers]
def shellSort(numbers, n):
count = 0
m = 1
g = []
while m <= n :
g.append(m)
m = 3 * m + 1
for i in range(len(g), -1, -1):
count += insertionSort(numbers, n, g[i])
print(len(g))
print(' '.join(map(str, g)))
return count
def insertionSort(numbers, n, h):
count = 0
for i in range(h, n, 1):
v = numbers[i]
j = i - h
while (j >= 0) & (numbers[j] > v):
numbers[j + h] = numbers[j]
j -= h
count += 1
numbers[j + h] = v
return count
if __name__ == '__main__':
main()
|
s127440653 | p02262 | u298224238 | 1529471776 | Python | Python3 | py | Runtime Error | 0 | 0 | 645 | def insertionSort(arr, g):
cnt = 0
for i in range(g, len(arr)):
tmp = arr[i]
j = i - g
while(j >= 0 and arr[j] > tmp):
arr[j + g] = arr[j]
j -= g
cnt += 1
arr[j + 1] = tmp
return cnt
def shellSort(arr):
cnt = 0
g = []
h = 0
while h <= len(arr) / 9:
h = 3 * h + 1
g.append(h)
for i in range(0, m):
cnt += insertionSort(a, g[i]):
return (cnt, g)
N = int(input())
arr = [int(input()) for i in range(N)]
cnt, g = shellSort(arr)
print(len(g))
print(' '.join(map(str, g)))
print(cnt)
print('\n'.join(map(str, arr)))
|
s156411519 | p02262 | u298224238 | 1529471816 | Python | Python3 | py | Runtime Error | 0 | 0 | 647 | def insertionSort(arr, g):
cnt = 0
for i in range(g, len(arr)):
tmp = arr[i]
j = i - g
while(j >= 0 and arr[j] > tmp):
arr[j + g] = arr[j]
j -= g
cnt += 1
arr[j + 1] = tmp
return cnt
def shellSort(arr):
cnt = 0
g = []
h = 0
while h <= len(arr) / 9:
h = 3 * h + 1
g.append(h)
for i in range(0, m):
cnt += insertionSort(arr, g[i]):
return (cnt, g)
N = int(input())
arr = [int(input()) for i in range(N)]
cnt, g = shellSort(arr)
print(len(g))
print(' '.join(map(str, g)))
print(cnt)
print('\n'.join(map(str, arr)))
|
s232371759 | p02262 | u298224238 | 1529471901 | Python | Python3 | py | Runtime Error | 0 | 0 | 662 | def insertionSort(arr, g):
cnt = 0
for i in range(g, len(arr)):
tmp = arr[i]
j = i - g
while(j >= 0 and arr[j] > tmp):
arr[j + g] = arr[j]
j -= g
cnt += 1
arr[j + 1] = tmp
return cnt
def shellSort(arr):
cnt = 0
g = []
h = 0
while h <= len(arr) / 9:
h = 3 * h + 1
g.append(h)
g = g[::-1]
for i in range(0, m):
cnt += insertionSort(arr, g[i])
return (cnt, g)
N = int(input())
arr = [int(input()) for i in range(N)]
cnt, g = shellSort(arr)
print(len(g))
print(' '.join(map(str, g)))
print(cnt)
print('\n'.join(map(str, arr)))
|
s934196965 | p02262 | u298224238 | 1529471936 | Python | Python3 | py | Runtime Error | 0 | 0 | 664 | def insertionSort(arr, g):
cnt = 0
for i in range(g, len(arr)):
tmp = arr[i]
j = i - g
while(j >= 0 and arr[j] > tmp):
arr[j + g] = arr[j]
j -= g
cnt += 1
arr[j + 1] = tmp
return cnt
def shellSort(arr):
cnt = 0
g = []
h = 0
while h <= len(arr) / 9:
h = 3 * h + 1
g.append(h)
g = g[::-1]
for i in range(0, m):
cnt += insertionSort(arr, g[i])
return (cnt, g)
N = int(input())
arr = [int(input()) for i in range(N)]
(cnt, g) = shellSort(arr)
print(len(g))
print(' '.join(map(str, g)))
print(cnt)
print('\n'.join(map(str, arr)))
|
s869940665 | p02262 | u298224238 | 1529472627 | Python | Python3 | py | Runtime Error | 0 | 0 | 663 | def insertionSort(arr, N, g):
cnt = 0
for i in range(g, N):
tmp = arr[i]
j = i - g
while(j >= 0 and arr[j] > tmp):
arr[j + g] = arr[j]
j -= g
cnt += 1
arr[j + g] = tmp
return cnt
def shellSort(arr, N):
cnt = 0
G = []
h = 0
m = 0
while h <= N / 9:
h = 3 * h + 1
G.append(h)
m += 1
G = G[::-1]
cnt = sum([insertionSort(arr, N, g) for g in G])
return (cnt, g)
N = int(input())
arr = [int(input()) for i in range(N)]
(cnt, G) = shellSort(arr, N)
print(len(G), ' '.join(map(str, G)), cnt, '\n'.join(map(str, arr)), end='\n')
|
s676859517 | p02262 | u298224238 | 1529473395 | Python | Python3 | py | Runtime Error | 0 | 0 | 615 | cnt = 0
def insertionSort(arr, N, g):
for i in range(g, N):
tmp = arr[i]
j = i - g
while(j >= 0 and arr[j] > tmp):
arr[j + g] = arr[j]
j -= g
cnt += 1
arr[j + g] = tmp
def shellSort(arr, N):
G = []
h = 0
m = 0
while h <= N / 9:
h = 3 * h + 1
m += 1
G.append(h)
G = G[::-1]
for g in G:
insertionSort(arr, N, g)
return G
N = int(input())
arr = [int(input()) for i in range(N)]
G = shellSort(arr, N)
print(len(G), ' '.join(map(str, G)), cnt, '\n'.join(map(str, arr)), end='\n')
|
s273263706 | p02262 | u308033440 | 1529641655 | Python | Python3 | py | Runtime Error | 2540 | 13648 | 727 | def insertionSort(A,n,g):
for i in range(g,n,1):
v = int(A[i])
j = i - g
while j >= 0 and int(A[j]) > v:
global cnt
A[j + g] = A[j]
j = j - g
cnt = cnt + 1
A[j+g] = str(v)
def shellSort(A,n):
global cnt
global G
G = []
cnt = 0
h = 1
while h <= n:
G.append(h)
h = 3*h + 1
m = len(G)
print(m)
G.reverse()
print(' '.join(map(str, G)))
for i in range(0,m,1):
insertionSort(A,n,G[i])
print(cnt)
n = int(input())
#改行で標準入力を受け付ける場合
A = [0] * n
for i in range(n):
A[i] = input()
shellSort(A,n)
print('\n'.join(A))
|
s470441814 | p02262 | u308033440 | 1529641655 | Python | Python3 | py | Runtime Error | 2600 | 13648 | 727 | def insertionSort(A,n,g):
for i in range(g,n,1):
v = int(A[i])
j = i - g
while j >= 0 and int(A[j]) > v:
global cnt
A[j + g] = A[j]
j = j - g
cnt = cnt + 1
A[j+g] = str(v)
def shellSort(A,n):
global cnt
global G
G = []
cnt = 0
h = 1
while h <= n:
G.append(h)
h = 3*h + 1
m = len(G)
print(m)
G.reverse()
print(' '.join(map(str, G)))
for i in range(0,m,1):
insertionSort(A,n,G[i])
print(cnt)
n = int(input())
#改行で標準入力を受け付ける場合
A = [0] * n
for i in range(n):
A[i] = input()
shellSort(A,n)
print('\n'.join(A))
|
s071337637 | p02262 | u308033440 | 1529641697 | Python | Python3 | py | Runtime Error | 2590 | 13648 | 727 | def insertionSort(A,n,g):
for i in range(g,n,1):
v = int(A[i])
j = i - g
while j >= 0 and int(A[j]) > v:
global cnt
A[j + g] = A[j]
j = j - g
cnt = cnt + 1
A[j+g] = str(v)
def shellSort(A,n):
global cnt
global G
G = []
cnt = 0
h = 1
while h <= n:
G.append(h)
h = 3*h + 1
m = len(G)
print(m)
G.reverse()
print(' '.join(map(str, G)))
for i in range(0,m,1):
insertionSort(A,n,G[i])
print(cnt)
n = int(input())
#改行で標準入力を受け付ける場合
A = [0] * n
for i in range(n):
A[i] = input()
shellSort(A,n)
print('\n'.join(A))
|
s777127399 | p02262 | u285980122 | 1529642314 | Python | Python3 | py | Runtime Error | 20 | 5612 | 704 | def insertionSort(A, n, g):
global cnt
for i in range(g,n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j = j - g
cnt+=1
A[j+g] = v
def shellSort(A, n):
global cnt
cnt = 0
g = 2
m = n // g
print(m) # 1行目
G = list(range(g*m,g*(m-1),-g))
G.append(1)
G = G[-1*(m):]
print(" ".join(list(map(str,G)))) # 2行目
for i in range(0,m):
insertionSort(A, n, G[i])
print(cnt) # 3行目
for i in range(0,len(A)):
print(A[i]) # 4行目以降
cnt = 0
n = int(input())
A = []
for i in range(n):
A.append(int(input()))
#print("-"*10)
shellSort(A,n)
|
s564464872 | p02262 | u153665391 | 1529822074 | Python | Python3 | py | Runtime Error | 20 | 5604 | 784 | N = int(input())
A = [int(input()) for i in range(N)]
def insertion_sort(A, N, diff, cnt):
for i in range(diff, N):
tmp_num = A[i]
j = i - diff
while j >= 0 and A[j] > tmp_num:
A[j+diff] = A[j]
j = j - diff
cnt += 1
A[j+diff] = tmp_num
return cnt
if __name__ == "__main__":
cnt = 0
divide_cnt = 0
diffs = []
quotient = N
while True:
quotient = quotient // 2
if quotient == 1:
break
diffs.append(quotient)
divide_cnt += 1
diffs.append(1)
divide_cnt += 1
for diff in diffs:
cnt = insertion_sort(A, N, diff, cnt)
print(divide_cnt)
print(" ".join(map(str, diffs)))
print(cnt)
for num in A:
print(num)
|
s147559661 | p02262 | u316584871 | 1530182921 | Python | Python3 | py | Runtime Error | 8280 | 9836 | 919 | def insertionSort(A, n, g):
cnti = 0
for i in range(g, n):
v = A[i]
j = i-g
while (j >= 0 and A[j] > v):
A[j + g] = A[j]
j -= g
cnti += 1
A[j+g] = v
return cnti
def shellSort(A,n):
cnt = 0
G = []
for k in range(int((n/3)) +1):
h = 3*k + 1
if (h <= n and len(G) < 100):
G.append(h)
elif(len(G) == 100):
break
G.reverse()
m = len(G)
for i in range(m):
cnt += insertionSort(A, n, G[i])
print(m)
for i in range(m):
if (i == m-1):
print('{}'.format(G[i]), end = '')
else:
print('{}'.format(G[i]), end = ' ')
return cnt
n = int(input())
nlist = []
for i in range(n):
x = int(input())
nlist.append(x)
c = shellSort(nlist,n)
print()
print(c)
for i in nlist:
print(i)
|
s298878277 | p02262 | u285980122 | 1530246902 | Python | Python3 | py | Runtime Error | 20 | 5608 | 1067 | def insertionSort(A, n, g):
global cnt
for i in range(g,n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j = j - g
cnt+=1
A[j+g] = v
def shellSort(A, n):
global cnt
cnt = 0
#g = 3
#g = n // 2 * 2
g = 2
#m = max(n // g,1)
#m = min(m, 100)
#print(m) # 1行目
#G = list(range(g*m,g,-g))
G = [1]
for i in range(1,101):
# gの2乗分ずつGのリスト値を変えていく
# mは結果のリストから取得
#print("g**i:{} ,n:{}".format(g**i, n))
if g**i <= n:
m = i+1
G.append(g**i)
g += 1
else:
break
G.reverse()
print(m) # 1行目
print(" ".join(list(map(str,G)))) # 2行目
for i in range(0,m):
insertionSort(A, n, G[i])
print(cnt) # 3行目
for i in range(0,len(A)):
print(A[i]) # 4行目以降
cnt = 0
n = int(input())
A = []
for i in range(n):
A.append(int(input()))
shellSort(A,n)
|
s221766270 | p02262 | u285980122 | 1530247004 | Python | Python3 | py | Runtime Error | 1720 | 9832 | 1077 | def insertionSort(A, n, g):
global cnt
for i in range(g,n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j = j - g
cnt+=1
A[j+g] = v
def shellSort(A, n):
global cnt
cnt = 0
#g = 3
#g = n // 2 * 2
g = 2
#m = max(n // g,1)
#m = min(m, 100)
#print(m) # 1行目
#G = list(range(g*m,g,-g))
G = [1]
m = 1
for i in range(1,101):
# gの2乗分ずつGのリスト値を変えていく
# mは結果のリストから取得
#print("g**i:{} ,n:{}".format(g**i, n))
if g**i <= n:
m = i+1
G.append(g**i)
g += 1
else:
break
G.reverse()
print(m) # 1行目
print(" ".join(list(map(str,G)))) # 2行目
for i in range(0,m):
insertionSort(A, n, G[i])
print(cnt) # 3行目
for i in range(0,len(A)):
print(A[i]) # 4行目以降
cnt = 0
n = int(input())
A = []
for i in range(n):
A.append(int(input()))
shellSort(A,n)
|
s641962174 | p02262 | u285980122 | 1530247079 | Python | Python3 | py | Runtime Error | 1680 | 9832 | 1077 | def insertionSort(A, n, g):
global cnt
for i in range(g,n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j = j - g
cnt+=1
A[j+g] = v
def shellSort(A, n):
global cnt
cnt = 0
#g = 3
#g = n // 2 * 2
g = 2
#m = max(n // g,1)
#m = min(m, 100)
#print(m) # 1行目
#G = list(range(g*m,g,-g))
G = [1]
m = 1
for i in range(1,101):
# gの2乗分ずつGのリスト値を変えていく
# mは結果のリストから取得
#print("g**i:{} ,n:{}".format(g**i, n))
if g**i <= n:
m = i+1
G.append(g**i)
g += 1
else:
break
G.reverse()
print(m) # 1行目
print(" ".join(list(map(str,G)))) # 2行目
for i in range(0,m):
insertionSort(A, n, G[i])
print(cnt) # 3行目
for i in range(0,len(A)):
print(A[i]) # 4行目以降
cnt = 0
n = int(input())
A = []
for i in range(n):
A.append(int(input()))
shellSort(A,n)
|
s273711766 | p02262 | u285980122 | 1530247450 | Python | Python3 | py | Runtime Error | 1920 | 9836 | 790 | def insertionSort(A, n, g):
global cnt
for i in range(g,n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j = j - g
cnt+=1
A[j+g] = v
def shellSort(A, n):
global cnt
cnt = 0
g = 4
G = [1]
m = 1
for i in range(1,101):
if g**i <= n:
m = i+1
G.append(g**i)
g += 1
else:
break
G.reverse()
print(m) # 1行目
print(" ".join(list(map(str,G)))) # 2行目
for i in range(0,m):
insertionSort(A, n, G[i])
print(cnt) # 3行目
for i in range(0,len(A)):
print(A[i]) # 4行目以降
cnt = 0
n = int(input())
A = []
for i in range(n):
A.append(int(input()))
shellSort(A,n)
|
s678255532 | p02262 | u285980122 | 1530247936 | Python | Python3 | py | Runtime Error | 3340 | 9832 | 815 | def insertionSort(A, n, g):
global cnt
for i in range(g,n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j = j - g
cnt+=1
A[j+g] = v
def shellSort(A, n):
global cnt
cnt = 0
g = 1
G = [1]
m = 1
for i in range(1,101):
tmp = G[-1]**2+g**2
if tmp <= n:
m = i+1
G.append(tmp)
g += 1
else:
break
G.reverse()
print(m) # 1行目
print(" ".join(list(map(str,G)))) # 2行目
for i in range(0,m):
insertionSort(A, n, G[i])
print(cnt) # 3行目
for i in range(0,len(A)):
print(A[i]) # 4行目以降
cnt = 0
n = int(input())
A = []
for i in range(n):
A.append(int(input()))
shellSort(A,n)
|
s619368441 | p02262 | u285980122 | 1530248115 | Python | Python3 | py | Runtime Error | 4030 | 9836 | 833 | def insertionSort(A, n, g):
global cnt
for i in range(g,n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j = j - g
cnt+=1
A[j+g] = v
def shellSort(A, n):
global cnt
cnt = 0
g = 1
G = [0]
m = 1
for i in range(1,101):
tmp = G[-1]**2+(g+1)**2
if tmp <= n:
m = i+1
G.append(tmp)
g += 1
else:
break
G[0] = 1
G.reverse()
print(m) # 1行目
print(" ".join(list(map(str,G)))) # 2行目
for i in range(0,m):
insertionSort(A, n, G[i])
print(cnt) # 3行目
for i in range(0,len(A)):
print(A[i]) # 4行目以降
cnt = 0
n = int(input())
A = []
for i in range(n):
A.append(int(input()))
shellSort(A,n)
|
s486198095 | p02262 | u285980122 | 1530248253 | Python | Python3 | py | Runtime Error | 4340 | 9840 | 832 | def insertionSort(A, n, g):
global cnt
for i in range(g,n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j = j - g
cnt+=1
A[j+g] = v
def shellSort(A, n):
global cnt
cnt = 0
g = 1
G = [1]
m = 1
for i in range(1,101):
tmp = G[-1]**2+(3)**i
if tmp <= n:
m = i+1
G.append(tmp)
g += 1
else:
break
#G[0] = 1
G.reverse()
print(m) # 1行目
print(" ".join(list(map(str,G)))) # 2行目
for i in range(0,m):
insertionSort(A, n, G[i])
print(cnt) # 3行目
for i in range(0,len(A)):
print(A[i]) # 4行目以降
cnt = 0
n = int(input())
A = []
for i in range(n):
A.append(int(input()))
shellSort(A,n)
|
s095683071 | p02262 | u320121447 | 1530509461 | Python | Python3 | py | Runtime Error | 4840 | 9828 | 683 | def swap(A, i, j):
tmp = A[i]
A[i] = A[j]
A[j] = tmp
def insertionSort(A, n, g):
global cnt
for i in range(g, n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j = j - g
cnt += 1
A[j+g] = v
def shellSort(A, n):
global cnt
cnt = 0
m = 1
G = [1]
while 2 ** m < n:
G.append(2 ** m)
m += 1
G.reverse()
print(m)
print(' '.join(map(str, G)))
for i in range(m):
insertionSort(A, n, G[i])
n = int(input())
A = []
for i in range(n):
a = int(input())
A.append(a)
shellSort(A, n)
print(cnt)
for a in A:
print(a)
|
s050083403 | p02262 | u320121447 | 1530509591 | Python | Python3 | py | Runtime Error | 1270 | 9836 | 703 | def swap(A, i, j):
tmp = A[i]
A[i] = A[j]
A[j] = tmp
def insertionSort(A, n, g):
global cnt
for i in range(g, n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j = j - g
cnt += 1
A[j+g] = v
def shellSort(A, n):
global cnt
cnt = 0
g = 1
G = [g]
while 3 * g + 1 < n:
g = 3 * g + 1
G.append(g)
m = len(G)
G.reverse()
print(m)
print(' '.join(map(str, G)))
for i in range(m):
insertionSort(A, n, G[i])
n = int(input())
A = []
for i in range(n):
a = int(input())
A.append(a)
shellSort(A, n)
print(cnt)
for a in A:
print(a)
|
s093373899 | p02262 | u320121447 | 1530509815 | Python | Python3 | py | Runtime Error | 1330 | 9836 | 739 | def swap(A, i, j):
tmp = A[i]
A[i] = A[j]
A[j] = tmp
def insertionSort(A, n, g):
global cnt
for i in range(g, n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j = j - g
cnt += 1
A[j+g] = v
def shellSort(A, n):
global cnt
cnt = 0
g = 1
G = [g]
while 3 * g + 1 < n:
g = 3 * g + 1
G.append(g)
if G[-1] < n//2: G.append(n//2)
m = len(G)
G.reverse()
print(m)
print(' '.join(map(str, G)))
for i in range(m):
insertionSort(A, n, G[i])
n = int(input())
A = []
for i in range(n):
a = int(input())
A.append(a)
shellSort(A, n)
print(cnt)
for a in A:
print(a)
|
s074260882 | p02262 | u677291728 | 1530605968 | Python | Python3 | py | Runtime Error | 0 | 0 | 599 | #! /usr/bin/python
import sys
if sys.version_info[0] >= 3: raw_input = input
def insertion_sort(a,g):
global cnt
for i in range(g, len(a)):
v = a[i]
j = i - g
while j >= 0 and a[j] > v:
a[j+g] = a[j]
j = j - g
cnt += 1
a[j+g] = v
def shell_sort(a):
global cnt
cnt = 0
g = []
h = 1
while h <= len(a):
g.append(h)
h = 3*h + 1
g.reverse()
m = len(g)
print(m)
print(''.join(map(str, g)))
for i in range(m):
insertion_sort(a, g[i])
a = [int(raw_input()) for i in range(raw_input())]
shell_sort(a)
print(cnt)
for e in a: print(e)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.