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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
s311306409 | p02262 | u567380442 | 1421320249 | Python | Python3 | py | Runtime Error | 19920 | 47312 | 604 | import sys
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 += [h]
h = 1 + 3 * h
G = G[::-1]
m = len(G)
print(m)
print(*G)
for g in G:
insertionSort(A, g)
N = int(input())
A = [int(line) for line in sys.stdin]
shellSort(A)
print(cnt)
for a in A:
print(a) |
s469556105 | p02262 | u567380442 | 1421323371 | Python | Python3 | py | Runtime Error | 19930 | 47312 | 645 | import sys
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 += [h]
h = 1 + 3 * h
G = G[::-1]
m = len(G)
print(m)
print(*G)
for g in G:
insertionSort(A, g)
n = int(sys.stdin.readline())
A = []
for i in range(n):
A.append(int(sys.stdin.readline()))
shellSort(A)
print(cnt)
for a in A:
print(a) |
s649028204 | p02262 | u567380442 | 1421323541 | Python | Python3 | py | Runtime Error | 19920 | 47312 | 684 | import sys
def isort(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 -= g
cnt += 1
a[j + g] = v
# input data
n = int(sys.stdin.readline())
a = []
for i in range(n):
a.append(int(sys.stdin.readline()))
# determine m, g
g = [1]
m = 1
while True:
x = 3 * g[m - 1] + 1
if x >= n: break
g.append(x)
m += 1
g = g[::-1]
# 1 output m
print(m)
# 2 output g
print(' '.join(map(str, g)))
# sort it
cnt = 0
for i in range(m):
isort(a, n, g[i])
# 3 output cnt
print(cnt)
# 4 output sorted a
print('\n'.join(map(str, a))) |
s301062679 | p02262 | u567380442 | 1421323944 | Python | Python3 | py | Runtime Error | 19930 | 47312 | 661 | #!/usr/bin/python
import sys
if sys.version_info[0]>=3: raw_input=input
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
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):
insertionSort(a,g[i])
a=[int(raw_input()) for i in range(int(raw_input()))]
shellSort(a)
print(cnt)
for e in a: print(e) |
s382301594 | p02262 | u567380442 | 1426472267 | Python | Python3 | py | Runtime Error | 19930 | 159368 | 607 | import sys
def shell(a):
g = []
h = 1
while h <= len(a):
g.append(h)
h = 3*h+1
g.reverse()
print(len(g))
print(*g)
for i in g:
insertion(a, i)
def insertion(a, g):
global cnt
for i in range(g, len(a)):
v = a[i]
i -= g
while i >= 0 and a[i] > v:
a[i + g] = a[i]
i -= g
cnt += 1
a[i + g] = v
def main():
n = int(sys.stdin.readline())
a = list(map(int,sys.stdin.readlines()))
global cnt
cnt = 0
shell(a)
print(cnt)
print('\n'.join(map(str,a)))
main() |
s625882885 | p02262 | u567380442 | 1426473286 | Python | Python3 | py | Runtime Error | 19930 | 47080 | 441 | import sys
n = int(sys.stdin.readline())
a = list(map(int,sys.stdin))
g = []
h = 1
while h <= n:
g.append(h)
h = 3 * h + 1
g.reverse()
cnt = 0
for gi in g:
for i in range(gi, n):
v = a[i]
i -= gi
while i >= 0 and a[i] > v:
a[i + gi] = a[i]
i -= gi
cnt += 1
a[i + gi] = v
print(len(g))
print(' '.join(map(str, g)))
print(cnt)
print('\n'.join(map(str,a))) |
s180232281 | p02262 | u567380442 | 1426473549 | Python | Python3 | py | Runtime Error | 19920 | 47064 | 439 | import sys
n = int(sys.stdin.readline())
a = list(map(int,sys.stdin))
g = []
h = 1
while h <= n:
g.append(h)
h = 3 * h + 1
g.reverse()
cnt = 0
for gi in g:
for i in range(gi, n):
v = a[i]
i -= gi
while i >= 0 and a[i] > v:
a[i + gi] = a[i]
i -= gi
cnt += 1
a[i + gi] = v
print(len(g))
print(' '.join(map(str, g)))
print(cnt)
for ai in a:
print(ai) |
s830259494 | p02262 | u567380442 | 1428925820 | Python | Python3 | py | Runtime Error | 19930 | 47076 | 509 | from sys import stdin
def main():
n = int(stdin.readline())
a = list(map(int, stdin))
g = []
h = 1
while h <= n:
g.append(h)
h = 3 * h + 1
g.reverse()
cnt = 0
for gi in g:
for i in range(gi, n):
v = a[i]
i -= gi
while i >= 0 and a[i] > v: a[i + gi], i, cnt = a[i], i - gi, cnt + 1
a[i + gi] = v
print(len(g))
print(' '.join(map(str, g)))
print(cnt)
print('\n'.join(map(str, a)))
main() |
s933324342 | p02262 | u567380442 | 1428926841 | Python | Python3 | py | Runtime Error | 19930 | 159360 | 562 | from sys import stdin
def main():
n = int(stdin.readline())
a = list(map(int, stdin.readlines()))
g = []
h = 1
while h <= n:
g.append(h)
h = 3 * h + 1
g.reverse()
cnt = 0
for gi in g:
for i in range(gi, n):
v = a[i]
i -= gi
while i >= 0 and a[i] > v:
a[i + gi] = a[i]
i -= gi
cnt += 1
a[i + gi] = v
print(len(g))
print(' '.join(map(str, g)))
print(cnt)
print('\n'.join(map(str, a)))
main() |
s842454433 | p02262 | u604774382 | 1432852011 | Python | Python3 | py | Runtime Error | 19930 | 47312 | 671 | def insertionSort( nums, n, g ):
cnt = 0
for i in range( g, len( nums ) ):
v = nums[i]
j = i - g
while 0 <= j and v < nums[j]:
nums[ j+g ] = nums[j]
j -= g
cnt += 1
nums[ j+g ] = v
return cnt
def shellSort( nums, n ):
cnt = 0
g = []
val =0
for i in range( 0, n ):
val = 3*val+1
if n < val:
break
g.append( val )
g.reverse( )
m = len( g )
print( m )
print( " ".join( map( str, g ) ) )
for i in range( 0, m ):
cnt += insertionSort( nums, n, g[i] )
print( cnt )
n = int( input( ) )
nums = []
for i in range( 0, n ):
nums.append( int( input( ) ) )
shellSort( nums, n )
for i in nums:
print( i ) |
s865813296 | p02262 | u604774382 | 1432888469 | Python | Python3 | py | Runtime Error | 19920 | 47308 | 732 | def insertionSort( nums, n, g ):
cnt = 0
for i in range( g, len( nums ) ):
v = nums[i]
j = i - g
while 0 <= j and v < nums[j]:
nums[ j+g ] = nums[j]
j -= g
cnt += 1
nums[ j+g ] = v
return cnt
def shellSort( nums, n ):
cnt = 0
g = []
val =0
for i in range( 0, n ):
val = 3*val+1
if n < val:
break
g.append( val )
g.reverse( )
m = len( g )
print( m )
print( " ".join( map( str, g ) ) )
for i in range( 0, m ):
cnt += insertionSort( nums, n, g[i] )
print( cnt )
n = int( input( ) )
nums = []
for i in range( 0, n ):
nums.append( int( input( ) ) )
shellSort( nums, n )
output = []
for i in nums:
output.append( str( i ) )
output.append( "\n" )
output.pop( )
print( "".join( output ) ) |
s562278661 | p02262 | u604774382 | 1432888843 | Python | Python3 | py | Runtime Error | 19930 | 47308 | 658 | def insertionSort( nums, n, g ):
cnt = 0
i = g
n = len( nums )
while i < n:
v = nums[i]
j = i - g
while 0 <= j and v < nums[j]:
nums[ j+g ] = nums[j]
j -= g
cnt += 1
nums[ j+g ] = v
i += 1
return cnt
def shellSort( nums, n ):
cnt = 0
g = []
val =0
for i in range( 0, n ):
val = 3*val+1
if n < val:
break
g.append( val )
g.reverse( )
m = len( g )
print( m )
print( " ".join( map( str, g ) ) )
for i in range( 0, m ):
cnt += insertionSort( nums, n, g[i] )
print( cnt )
n = int( input( ) )
nums = []
for i in range( 0, n ):
nums.append( int( input( ) ) )
shellSort( nums, n )
for val in nums:
print( val ) |
s562863397 | p02262 | u604774382 | 1432889935 | Python | Python | py | Runtime Error | 19930 | 67900 | 678 | def insertionSort( nums, n, g ):
cnt = 0
i = g
n = len( nums )
while i < n:
v = nums[i]
j = i - g
while 0 <= j and v < nums[j] and j+g < n:
nums[ j+g ] = nums[j]
j -= g
cnt += 1
nums[ j+g ] = v
i += 1
return cnt
def shellSort( nums, n ):
cnt = 0
g = []
val =0
for i in range( 0, n ):
val = 3*val+1
if n < val:
break
g.append( val )
g.reverse( )
m = len( g )
print( m )
print( " ".join( map( str, g ) ) )
for i in range( 0, m ):
cnt += insertionSort( nums, n, g[i] )
print( cnt )
n = int( raw_input( ) )
nums = []
for i in range( 0, n ):
nums.append( int( raw_input( ) ) )
shellSort( nums, n )
for val in nums:
print( val ) |
s691818280 | p02262 | u604774382 | 1432890677 | Python | Python3 | py | Runtime Error | 19920 | 47316 | 651 | def insertionSort( nums, n, g ):
cnt = 0
i = g
while i < len( nums ):
v = nums[i]
j = i - g
while 0 <= j and v < nums[j]:
nums[ j+g ] = nums[j]
j -= g
cnt += 1
nums[ j+g ] = v
i += 1
return cnt
def shellSort( nums, n ):
cnt = 0
g = []
val =0
for i in range( 0, n ):
val = 3*val+1
if n < val:
break
g.append( val )
g.reverse( )
m = len( g )
print( m )
print( " ".join( map( str, g ) ) )
for i in range( 0, m ):
cnt += insertionSort( nums, n, g[i] )
print( cnt )
n = int( input( ) )
nums = []
for i in range( 0, n ):
nums.append( int( input( ) ) )
shellSort( nums, n )
for val in nums:
print( val ) |
s881056403 | p02262 | u604774382 | 1432892811 | Python | Python3 | py | Runtime Error | 19930 | 47308 | 645 | def insertionSort( nums, g ):
c = 0
i = g
n = len( nums )
while i < n:
v = nums[i]
j = i - g
while 0 <= j and v < nums[j]:
nums[ j+g ] = nums[j]
j -= g
c += 1
nums[ j+g ] = v
i += 1
return c
def shellSort( nums, n ):
cnt = 0
g = []
val =0
for i in range( 0, n ):
val = 3*val+1
if n < val:
break
g.append( val )
g.reverse( )
m = len( g )
print( m )
print( " ".join( map( str, g ) ) )
for i in range( 0, m ):
cnt += insertionSort( nums, g[i] )
print( cnt )
n = int( input( ) )
nums = []
for i in range( 0, n ):
nums.append( int( input( ) ) )
shellSort( nums, n )
for val in nums:
print( val ) |
s680264929 | p02262 | u604774382 | 1432899624 | Python | Python3 | py | Runtime Error | 19930 | 47308 | 648 | def insertionSort( nums, n, g ):
cnt = 0
i = g
while i < n:
v = nums[i]
j = i - g
while 0 <= j and v < nums[j]:
nums[ j+g ] = nums[j]
j -= g
cnt += 1
nums[ j+g ] = v
i += 1
return cnt
def shellSort( nums, n ):
cnt = 0
g = []
val =0
for i in range( n ):
val = 3*val+1
if n < val:
break
g.append( val )
g.reverse( )
m = len( g )
print( m )
print( " ".join( map( str, g ) ) )
for i in range( m ):
cnt += insertionSort( nums, n, g[i] )
print( cnt )
n = int( input( ) )
nums = []
for i in range( 0, n ):
nums.append( int( input( ) ) )
shellSort( nums, n )
print( "\n".join( map( str, nums ) ) ) |
s345866675 | p02262 | u604774382 | 1432899747 | Python | Python3 | py | Runtime Error | 0 | 0 | 599 | def insertionSort( nums, n, g ):
cnt = 0
i = g
while i < n:
v = nums[i]
j = i - g
while 0 <= j and v < nums[j]:
nums[ j+g ] = nums[j]
j -= g
cnt += 1
nums[ j+g ] = v
i += 1
return cnt
n = int( input( ) )
nums = []
for i in range( 0, n ):
nums.append( int( input( ) ) )
cnt = 0
g = []
val =0
for i in range( n ):
val = 3*val+1
if n < val:
break
g.append( val )
g.reverse( )
m = len( g )
print( m )
print( " ".join( map( str, g ) ) )
for i in range( m ):
cnt += insertionSort( nums, n, g[i] )
print( cnt )
shellSort( nums, n )
print( "\n".join( map( str, nums ) ) ) |
s266994714 | p02262 | u604774382 | 1432899828 | Python | Python3 | py | Runtime Error | 19930 | 47312 | 578 | def insertionSort( nums, n, g ):
cnt = 0
i = g
while i < n:
v = nums[i]
j = i - g
while 0 <= j and v < nums[j]:
nums[ j+g ] = nums[j]
j -= g
cnt += 1
nums[ j+g ] = v
i += 1
return cnt
n = int( input( ) )
nums = []
for i in range( 0, n ):
nums.append( int( input( ) ) )
cnt = 0
g = []
val =0
for i in range( n ):
val = 3*val+1
if n < val:
break
g.append( val )
g.reverse( )
m = len( g )
print( m )
print( " ".join( map( str, g ) ) )
for i in range( m ):
cnt += insertionSort( nums, n, g[i] )
print( cnt )
print( "\n".join( map( str, nums ) ) ) |
s976589776 | p02262 | u604774382 | 1432900033 | Python | Python3 | py | Runtime Error | 19930 | 47312 | 585 | def insertionSort( nums, n, g ):
cnt = 0
i = g
while i < n:
v = nums[i]
j = i - g
while 0 <= j and v < nums[j]:
nums[ j+g ] = nums[j]
j -= g
cnt += 1
nums[ j+g ] = v
i += 1
return cnt
n = int( input( ) )
nums = []
for i in range( 0, n ):
nums.append( int( input( ) ) )
cnt = 0
g = []
val = 0
for i in range( n ):
val = 3*val+1
if n < val:
break
g.append( val )
g.reverse( )
m = len( g )
print( m )
print( " ".join( map( str, g ) ) )
for i in range( m ):
cnt = cnt + insertionSort( nums, n, g[i] )
print( cnt )
print( "\n".join( map( str, nums ) ) ) |
s952109540 | p02262 | u604774382 | 1432900448 | Python | Python3 | py | Runtime Error | 19930 | 47308 | 646 | def insertionSort( nums, n, g ):
global cnt
i = g
while i < n:
v = nums[i]
j = i - g
while 0 <= j and v < nums[j]:
nums[ j+g ] = nums[j]
j -= g
cnt += 1
nums[ j+g ] = v
i += 1
def shellSort( nums, n ):
global cnt
g = []
val =0
for i in range( 0, n ):
val = 3*val+1
if n < val:
break
g.append( val )
g.reverse( )
m = len( g )
print( m )
print( " ".join( map( str, g ) ) )
for i in range( 0, m ):
insertionSort( nums, n, g[i] )
n = int( input( ) )
nums = []
for i in range( 0, n ):
nums.append( int( input( ) ) )
cnt = 0
shellSort( nums, n )
print( cnt )
print( "\n".join( map( str, nums ) ) ) |
s794502674 | p02262 | u604774382 | 1432900642 | Python | Python3 | py | Runtime Error | 19930 | 47312 | 625 | def insertionSort( nums, n, g ):
global cnt
i = g
while i < n:
v = nums[i]
j = i - g
while 0 <= j and v < nums[j]:
nums[ j+g ] = nums[j]
j -= g
cnt += 1
nums[ j+g ] = v
i += 1
def shellSort( nums, n ):
g = []
val =0
for i in range( n ):
val = 3*val+1
if n < val:
break
g.append( val )
g.reverse( )
m = len( g )
print( m )
print( " ".join( map( str, g ) ) )
for i in range( m ):
insertionSort( nums, n, g[i] )
n = int( input( ) )
nums = []
for i in range( n ):
nums.append( int( input( ) ) )
cnt = 0
shellSort( nums, n )
print( cnt )
print( "\n".join( map( str, nums ) ) ) |
s430191413 | p02262 | u604774382 | 1432900731 | Python | Python | py | Runtime Error | 19920 | 104012 | 663 | import sys
def insertionSort( nums, n, g ):
global cnt
i = g
while i < n:
v = nums[i]
j = i - g
while 0 <= j and v < nums[j]:
nums[ j+g ] = nums[j]
j -= g
cnt += 1
nums[ j+g ] = v
i += 1
def shellSort( nums, n ):
g = []
val =0
for i in range( n ):
val = 3*val+1
if n < val:
break
g.append( val )
g.reverse( )
m = len( g )
print( m )
print( " ".join( map( str, g ) ) )
for i in range( m ):
insertionSort( nums, n, g[i] )
n = int( sys.stdin.readline( ) )
nums = []
for i in range( n ):
nums.append( int( sys.stdin.readline( ) ) )
cnt = 0
shellSort( nums, n )
print( cnt )
print( "\n".join( map( str, nums ) ) ) |
s770338993 | p02262 | u604774382 | 1432900960 | Python | Python3 | py | Runtime Error | 19920 | 47308 | 681 | import sys
def insertionSort( nums, n, g ):
cnt = 0
i = g
while i < n:
v = nums[i]
j = i - g
while 0 <= j and v < nums[j]:
nums[ j+g ] = nums[j]
j -= g
cnt += 1
nums[ j+g ] = v
i += 1
return cnt
def shellSort( nums, n ):
g = []
val =0
for i in range( n ):
val = 3*val+1
if n < val:
break
g.append( val )
g.reverse( )
m = len( g )
print( m )
print( " ".join( map( str, g ) ) )
cnt = 0
for i in range( m ):
cnt += insertionSort( nums, n, g[i] )
print( cnt )
n = int( sys.stdin.readline( ) )
nums = []
for i in range( n ):
nums.append( int( sys.stdin.readline( ) ) )
shellSort( nums, n )
print( "\n".join( map( str, nums ) ) ) |
s472069640 | p02262 | u604774382 | 1432901695 | Python | Python3 | py | Runtime Error | 19930 | 47308 | 653 | import sys
def insertionSort( nums, n, g ):
cnt = 0
i = g
while i < n:
v = nums[i]
j = i - g
while 0 <= j and v < nums[j]:
nums[ j+g ] = nums[j]
j -= g
cnt += 1
nums[ j+g ] = v
i += 1
return cnt
def shellSort( nums, n ):
g = []
val = 1
while val <= n:
g.append( val )
val = 3*val+1
g.reverse( )
m = len( g )
print( m )
print( " ".join( map( str, g ) ) )
cnt = 0
for i in range( m ):
cnt += insertionSort( nums, n, g[i] )
print( cnt )
n = int( sys.stdin.readline( ) )
nums = []
for i in range( n ):
nums.append( int( sys.stdin.readline( ) ) )
shellSort( nums, n )
print( "\n".join( map( str, nums ) ) ) |
s562124570 | p02262 | u604774382 | 1432902097 | Python | Python3 | py | Runtime Error | 19930 | 47308 | 635 | import sys
def insertionSort( nums, n, g ):
global cnt
i = g
while i < n:
v = nums[i]
j = i - g
while 0 <= j and v < nums[j]:
nums[ j+g ] = nums[j]
j -= g
cnt += 1
nums[ j+g ] = v
i += 1
def shellSort( nums, n ):
g = []
val = 1
while val <= n:
g.append( val )
val = 3*val+1
g.reverse( )
m = len( g )
print( m )
print( " ".join( map( str, g ) ) )
for i in range( m ):
insertionSort( nums, n, g[i] )
n = int( sys.stdin.readline( ) )
nums = []
for i in range( n ):
nums.append( int( sys.stdin.readline( ) ) )
cnt = 0
shellSort( nums, n )
print( cnt )
print( "\n".join( map( str, nums ) ) ) |
s963226480 | p02262 | u604774382 | 1432902366 | Python | Python3 | py | Runtime Error | 19930 | 47304 | 592 | def insertionSort( nums, n, g ):
global cnt
for i in range( g, n ):
v = nums[i]
j = i - g
while 0 <= j and v < nums[j]:
nums[ j+g ] = nums[j]
j -= g
cnt += 1
nums[ j+g ] = v
def shellSort( nums, n ):
g = []
val = 1
while val <= n:
g.append( val )
val = 3*val+1
g.reverse( )
m = len( g )
print( m )
print( " ".join( map( str, g ) ) )
for i in range( m ):
insertionSort( nums, n, g[i] )
n = int( input( ) )
nums = []
for i in range( n ):
nums.append( int( input( ) ) )
cnt = 0
shellSort( nums, n )
print( cnt )
print( "\n".join( map( str, nums ) ) ) |
s875646735 | p02262 | u604774382 | 1432903288 | Python | Python3 | py | Runtime Error | 19930 | 47308 | 527 | def insertionSort( nums, n, g ):
global cnt
for i in range( g, n ):
v = nums[i]
j = i - g
while 0 <= j and v < nums[j]:
nums[ j+g ] = nums[j]
j -= g
cnt += 1
nums[ j+g ] = v
n = int( input( ) )
nums = []
for i in range( n ):
nums.append( int( input( ) ) )
g = []
val = 1
while val <= n:
g.append( val )
val = 3*val+1
g.reverse( )
m = len( g )
print( m )
print( " ".join( map( str, g ) ) )
cnt = 0
for i in range( m ):
insertionSort( nums, n, g[i] )
print( cnt )
print( "\n".join( map( str, nums ) ) ) |
s116600536 | p02262 | u604774382 | 1432903566 | Python | Python3 | py | Runtime Error | 19930 | 47308 | 462 | n = int( input( ) )
nums = []
for i in range( n ):
nums.append( int( input( ) ) )
g = []
val = 1
while val <= n:
g.append( val )
val = 3*val+1
g.reverse( )
m = len( g )
print( m )
print( " ".join( map( str, g ) ) )
cnt = 0
for i in range( m ):
for k in range( g[i], n ):
v = nums[k]
j = k - g[i]
while 0 <= j and v < nums[j]:
nums[ j+g[i] ] = nums[j]
j -= g[i]
cnt += 1
nums[ j+g[i] ] = v
print( cnt )
print( "\n".join( map( str, nums ) ) ) |
s102693747 | p02262 | u604774382 | 1432904431 | Python | Python3 | py | Runtime Error | 19930 | 47308 | 463 | n = int( input( ) )
nums = []
for i in range( n ):
nums.append( int( input( ) ) )
g = []
val = 1
while val <= n:
g.append( val )
val = 3*val+1
g.reverse( )
m = len( g )
print( m )
print( " ".join( map( str, g ) ) )
cnt = 0
for i in range( m ):
for k in range( g[i], n ):
v = nums[k]
j = k - g[i]
while 0 <= j and v < nums[j]:
nums[ j+g[i] ] = nums[j]
j -= g[i]
cnt += 1
nums[ j+g[i] ] = v
print( cnt )
print( "\n".join( map( str, nums ) ) ) |
s886364943 | p02262 | u604774382 | 1432904812 | Python | Python3 | py | Runtime Error | 19930 | 47308 | 462 | n = int( input( ) )
nums = []
for i in range( n ):
nums.append( int( input( ) ) )
g = []
val = 1
while val <= n:
g.append( val )
val = 3*val+1
g.reverse( )
m = len( g )
print( m )
print( " ".join( map( str, g ) ) )
cnt = 0
for i in range( m ):
for k in range( g[i], n ):
v = nums[k]
j = k - g[i]
while 0 <= j and v < nums[j]:
nums[ j+g[i] ] = nums[j]
j = j - g[i]
cnt = cnt + 1
nums[ j+g[i] ] = v
print( cnt )
for val in nums:
print( val ) |
s275931454 | p02262 | u604774382 | 1432906431 | Python | Python3 | py | Runtime Error | 19930 | 47308 | 596 | def insertionSort( nums, n, g ):
cnt = 0
for i in range( g, n):
v = nums[i]
j = i - g
while ( 0 <= j ) and ( v < nums[j] ):
nums[ j+g ] = nums[j]
j -= g
cnt += 1
nums[ j+g ] = v
return cnt
def shellSort( nums, n ):
cnt = 0
g = []
v = 1
while v <= n:
g.append( v )
v = 3*v+1
g.reverse( )
m = len( g )
print( m )
print( " ".join( map( str, g ) ) )
for i in range( m ):
cnt += insertionSort( nums, n, g[i] )
print( cnt )
n = int( input( ) )
nums = []
for i in range( n ):
nums.append( int( input( ) ) )
shellSort( nums, n )
for v in nums:
print( v ) |
s303705193 | p02262 | u604774382 | 1432906534 | Python | Python3 | py | Runtime Error | 19920 | 47308 | 593 | def insertionSort( nums, n, g ):
global cnt
for i in range( g, n):
v = nums[i]
j = i - g
while ( 0 <= j ) and ( v < nums[j] ):
nums[ j+g ] = nums[j]
j -= g
cnt += 1
nums[ j+g ] = v
def shellSort( nums, n ):
global cnt
cnt = 0
g = []
v = 1
while v <= n:
g.append( v )
v = 3*v+1
g.reverse( )
m = len( g )
print( m )
print( " ".join( map( str, g ) ) )
for i in range( m ):
insertionSort( nums, n, g[i] )
print( cnt )
n = int( input( ) )
nums = []
for i in range( n ):
nums.append( int( input( ) ) )
shellSort( nums, n )
for v in nums:
print( v ) |
s069915323 | p02262 | u604774382 | 1432906630 | Python | Python3 | py | Runtime Error | 19920 | 47308 | 577 | def insertionSort( nums, n, g ):
global cnt
for i in range( g, n):
v = nums[i]
j = i - g
while ( 0 <= j ) and ( v < nums[j] ):
nums[ j+g ] = nums[j]
j -= g
cnt += 1
nums[ j+g ] = v
def shellSort( nums, n ):
g = []
v = 1
while v <= n:
g.append( v )
v = 3*v+1
g.reverse( )
m = len( g )
print( m )
print( " ".join( map( str, g ) ) )
for i in range( m ):
insertionSort( nums, n, g[i] )
n = int( input( ) )
nums = []
for i in range( n ):
nums.append( int( input( ) ) )
cnt = 0
shellSort( nums, n )
print( cnt )
for v in nums:
print( v ) |
s905599356 | p02262 | u604774382 | 1432907108 | Python | Python3 | py | Runtime Error | 19930 | 47308 | 560 | def insertionSort( nums, n, g ):
global cnt
for i in range( g, n):
v = nums[i]
j = i - g
while ( 0 <= j ) and ( v < nums[j] ):
nums[ j+g ] = nums[j]
j -= g
cnt += 1
nums[ j+g ] = v
def shellSort( nums, n ):
g = []
v = 1
while v <= n:
g.append( v )
v = 3*v+1
g.reverse( )
m = len( g )
print( m )
print( " ".join( map( str, g ) ) )
for i in range( m ):
insertionSort( nums, n, g[i] )
n = int( input( ) )
nums = [ int( input( ) ) for i in range( n ) ]
cnt = 0
shellSort( nums, n )
print( cnt )
for v in nums:
print( v ) |
s053727443 | p02262 | u604774382 | 1432907375 | Python | Python3 | py | Runtime Error | 19930 | 47308 | 572 | def insertionSort( nums, n, g ):
global cnt
for i in range( g, n ):
v = nums[i]
j = i - g
while ( 0 <= j ) and ( v < nums[j] ):
nums[ j+g ] = nums[j]
j -= g
cnt += 1
nums[ j+g ] = v
def shellSort( nums ):
g = []
v = 1
n = len( nums )
while v <= n:
g.append( v )
v = 3*v+1
g.reverse( )
m = len( g )
print( m )
print( " ".join( map( str, g ) ) )
for i in range( m ):
insertionSort( nums, n, g[i] )
n = int( input( ) )
nums = [ int( input( ) ) for i in range( n ) ]
cnt = 0
shellSort( nums )
print( cnt )
for v in nums:
print( v ) |
s175827468 | p02262 | u604774382 | 1432953157 | Python | Python3 | py | Runtime Error | 19920 | 47308 | 604 | def insertionSort( nums, n, g ):
cnt = 0
for i in range( g, n ):
v = nums[i]
j = i - g
while j >= 0 and nums[j] > v:
nums[ j+g ] = nums[j]
j -= g
cnt += 1
nums[ j+g ] = v
return cnt
def shellSort( nums, n ):
g = []
v = 1
while v <= n:
g.append( v )
v = 3*v+1
g.reverse( )
m = len( g )
print( m )
print( " ".join( map( str, g ) ) )
cnt = 0
for i in range( m ):
cnt += insertionSort( nums, n, g[i] )
print( cnt )
n = int( input( ) )
nums = [ int( input( ) ) for i in range( n ) ]
nums.append( 0 )
shellSort( nums, n )
nums.pop( )
for v in nums:
print( v ) |
s129170470 | p02262 | u604774382 | 1433166438 | Python | Python3 | py | Runtime Error | 0 | 0 | 706 | def insertionSort( nums, n, g ):
global cnt
for i in range( g, n ):
v = nums[i]
j = i - g
while ( 0 <= j ) and ( v < nums[j] ):
nums[ j+g ] = nums[j]
j -= g
cnt += 1
nums[ j+g ] = v
def shellSort( nums ):
global cnt
g = []
v = 1
n = len( nums )
while v <= n:
g.append( v )
v = 3*v+1
g.reverse( )
m = len( g )
print( m )
print( " ".join( map( str, g ) ) )
cnt = 0
for i in range( m ):
insertionSort( nums, n, g[i] )
print( cnt )
n = int( input( ) )
nums = [ int( input( ) ) for i in range( n ) ]
shellSort( nums )
for v in nums:
print( v ) |
s589646206 | p02262 | u604774382 | 1433166545 | Python | Python3 | py | Runtime Error | 0 | 0 | 593 | def insertionSort( nums, n, g ):
global cnt
for i in range( g, n ):
v = nums[i]
j = i - g
while ( 0 <= j ) and ( v < nums[j] ):
nums[ j+g ] = nums[j]
j -= g
cnt += 1
nums[ j+g ] = v
def shellSort( nums ):
global cnt
g = []
v = 1
n = len( nums )
while v <= n:
g.append( v )
v = 3*v+1
g.reverse( )
m = len( g )
print( m )
print( " ".join( map( str, g ) ) )
cnt = 0
for i in range( m ):
insertionSort( nums, n, g[i] )
print( cnt )
n = int( raw_input( ) )
nums = [ int( raw_input( ) ) for i in range( n ) ]
shellSort( nums )
for v in nums:
print( v ) |
s185398917 | p02262 | u604774382 | 1433166582 | Python | Python3 | py | Runtime Error | 19930 | 47308 | 585 | def insertionSort( nums, n, g ):
global cnt
for i in range( g, n ):
v = nums[i]
j = i - g
while ( 0 <= j ) and ( v < nums[j] ):
nums[ j+g ] = nums[j]
j -= g
cnt += 1
nums[ j+g ] = v
def shellSort( nums ):
global cnt
g = []
v = 1
n = len( nums )
while v <= n:
g.append( v )
v = 3*v+1
g.reverse( )
m = len( g )
print( m )
print( " ".join( map( str, g ) ) )
cnt = 0
for i in range( m ):
insertionSort( nums, n, g[i] )
print( cnt )
n = int( input( ) )
nums = [ int( input( ) ) for i in range( n ) ]
shellSort( nums )
for v in nums:
print( v ) |
s170738802 | p02262 | u604774382 | 1435153212 | Python | Python3 | py | Runtime Error | 19930 | 47308 | 714 | def insertionSort( nums, n, g ):
global cnt
for i in range( g, n ):
v = nums[i]
j = i - g
while ( 0 <= j ) and ( v < nums[j] ):
nums[ j+g ] = nums[j]
j -= g
cnt += 1
nums[ j+g ] = v
def shellSort( nums ):
global cnt
g = []
v = 1
n = len( nums )
while v <= n:
g.append( v )
v = 3*v+1
g.reverse( )
m = len( g )
print( m )
print( " ".join( map( str, g ) ) )
cnt = 0
for i in range( m ):
insertionSort( nums, n, g[i] )
print( cnt )
print( "\n".join( map( str, nums ) ) )
n = int( input( ) )
nums = [ int( input( ) ) for i in range( n ) ]
shellSort( nums ) |
s613362394 | p02262 | u604774382 | 1435154426 | Python | Python3 | py | Runtime Error | 19930 | 47316 | 677 | def insertionSort( s, n, g ):
global cnt
for i in range( g, n ):
v = s[i]
j = i - g
while ( 0 <= j ) and ( v < s[j] ):
s[ j+g ] = s[j]
j -= g
cnt += 1
s[ j+g ] = v
def shellSort( s ):
global cnt
g = []
v = 1
n = len( s )
while v <= n:
g.append( v )
v = 3*v+1
g.reverse( )
m = len( g )
print( m )
print( " ".join( map( str, g ) ) )
cnt = 0
for i in range( m ):
insertionSort( s, n, g[i] )
print( cnt )
n = int( input( ) )
s = [ int( input( ) ) for i in range( n ) ]
shellSort( s )
print( "\n".join( map( str, s ) ) ) |
s662116855 | p02262 | u609407244 | 1436244293 | Python | Python3 | py | Runtime Error | 30 | 6776 | 839 | def insertion_sort(array, g, result):
for i in range(g, len(array)):
v = array[i]
j = i - g
while j >= 0 and array[j] > v:
array[j + g] = array[j]
j -= g
result['count'] += 1
A[j + g] = v
def shell_sort(array, result):
result['count'] = 0
G = list(reversed([int((3 ** i - 1) / 2) for i in range(1, len(array)) if (3 ** i - 1) / 2 < len(array)]))
if not G:
G = [1]
m = len(G)
result['G'] = G
result['m'] = m
for i in range(m):
insertion_sort(array, G[i], result)
if __name__ == '__main__':
n = int(input())
A = [int(input()) for _ in range(n)]
result = {}
shell_sort(A, result)
print(result['m'])
print(' '.join(map(str, result['G'])))
print(result['count'])
print('\n'.join(map(str, A))) |
s645349975 | p02262 | u609407244 | 1436244625 | Python | Python3 | py | Runtime Error | 19930 | 47320 | 922 | def insertion_sort(array, g, result):
for i in range(g, len(array)):
v = array[i]
j = i - g
while j >= 0 and array[j] > v:
array[j + g] = array[j]
j -= g
result['count'] += 1
A[j + g] = v
def g_gene(n):
yield 1
for i in range(2, n):
x = int((3 ** i - 1) / 2)
if x < n:
yield x
else:
raise StopIteration()
def shell_sort(array, result):
result['count'] = 0
G = list(reversed(list(g_gene(len(array)))))
m = len(G)
result['G'] = G
result['m'] = m
for i in range(m):
insertion_sort(array, G[i], result)
if __name__ == '__main__':
n = int(input())
A = [int(input()) for _ in range(n)]
result = {}
shell_sort(A, result)
print(result['m'])
print(' '.join(map(str, result['G'])))
print(result['count'])
print('\n'.join(map(str, A))) |
s235567975 | p02262 | u609407244 | 1436245310 | Python | Python3 | py | Runtime Error | 19930 | 47324 | 934 | def insertion_sort(array, g, result):
for i in range(g, len(array)):
v = array[i]
j = i - g
while j >= 0 and array[j] > v:
array[j + g] = array[j]
j -= g
result['count'] += 1
A[j + g] = v
def g_gene(n):
yield 1
i = 2
while 1:
x = int((3 ** i - 1) / 2)
if x < n:
yield x
else:
raise StopIteration()
i += 1
def shell_sort(array, result):
result['count'] = 0
G = list(reversed(list(g_gene(len(array)))))
m = len(G)
result['G'] = G
result['m'] = m
for i in range(m):
insertion_sort(array, G[i], result)
if __name__ == '__main__':
n = int(input())
A = [int(input()) for _ in range(n)]
result = {}
shell_sort(A, result)
print(result['m'])
print(' '.join(map(str, result['G'])))
print(result['count'])
print('\n'.join(map(str, A))) |
s687748137 | p02262 | u609407244 | 1436245917 | Python | Python3 | py | Runtime Error | 19930 | 47316 | 921 | def insertion_sort(array, g, result):
for i in range(g, len(array)):
v = array[i]
j = i - g
while j >= 0 and array[j] > v:
array[j + g] = array[j]
j -= g
result['count'] += 1
A[j + g] = v
def g_gene(n):
yield 1
for i in range(2, n):
x = int((3 ** i - 1) / 2)
if x < n:
yield x
else:
raise StopIteration()
def shell_sort(array, result):
result['count'] = 0
G = list(reversed(list(g_gene(len(array)))))
m = len(G)
result['G'] = G
result['m'] = m
for i in range(m):
insertion_sort(array, G[i], result)
if __name__ == '__main__':
n = int(input())
A = [int(input()) for _ in range(n)]
result = {}
shell_sort(A, result)
print(result['m'])
print(' '.join(map(str, result['G'])))
print(result['count'])
for a in A:
print(a) |
s040837384 | p02262 | u609407244 | 1436258459 | Python | Python3 | py | Runtime Error | 19930 | 47316 | 945 | def insertion_sort(array, g, result):
for i in range(g, len(array)):
v = array[i]
j = i - g
while j >= 0 and array[j] > v:
array[j + g] = array[j]
j -= g
result['count'] += 1
A[j + g] = v
def g_gene(n):
yield 1
for i in range(2, n):
x = int((3 ** i - 1) / 2)
if x < n:
yield x
else:
raise StopIteration()
def shell_sort(array, result):
result['count'] = 0
G = list(reversed(list(g_gene(len(array)))))
m = len(G)
result['G'] = G
result['m'] = m
for i in range(m):
insertion_sort(array, G[i], result)
if __name__ == '__main__':
n = int(input())
A = []
for _ in range(n):
A.append(int(input()))
result = {}
shell_sort(A, result)
print(result['m'])
print(' '.join(map(str, result['G'])))
print(result['count'])
for a in A:
print(a) |
s600989786 | p02262 | u609407244 | 1436258595 | Python | Python3 | py | Runtime Error | 19920 | 47320 | 986 | def insertion_sort(array, g, result):
for i in range(g, len(array)):
v = array[i]
j = i - g
while j >= 0 and array[j] > v:
array[j + g] = array[j]
j -= g
result['count'] += 1
A[j + g] = v
def g_gene(n):
yield 1
for i in range(2, n):
x = int((3 ** i - 1) / 2)
if x < n:
yield x
else:
raise StopIteration()
def shell_sort(array, result):
result['count'] = 0
G = list(reversed(list(g_gene(len(array)))))
m = len(G)
result['G'] = G
result['m'] = m
for i in range(m):
insertion_sort(array, G[i], result)
if __name__ == '__main__':
import sys
n = int(sys.stdin.readline())
A = []
for _ in range(n):
A.append(int(sys.stdin.readline()))
result = {}
shell_sort(A, result)
print(result['m'])
print(' '.join(map(str, result['G'])))
print(result['count'])
for a in A:
print(a) |
s171963275 | p02262 | u609407244 | 1436258655 | Python | Python3 | py | Runtime Error | 19930 | 47328 | 805 |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import sys
def isort(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 -= g
cnt += 1
a[j + g] = v
# input data
n = int(sys.stdin.readline())
a = []
for i in range(n):
a.append(int(sys.stdin.readline()))
# determine m, g
g = [1]
m = 1
while True:
x = 3 * g[m - 1] + 1
if x >= n: break
g.append(x)
m += 1
g = g[::-1]
# 1 output m
print(m)
# 2 output g
print(' '.join(map(str, g)))
# sort it
cnt = 0
for i in range(m):
isort(a, n, g[i])
# 3 output cnt
print(cnt)
# 4 output sorted a
print('\n'.join(map(str, a))) |
s074009144 | p02262 | u609407244 | 1436258790 | Python | Python3 | py | Runtime Error | 19930 | 47308 | 690 | import sys
def isort(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 -= g
cnt += 1
a[j + g] = v
# input data
n = int(sys.stdin.readline())
a = []
for i in range(n):
a.append(int(sys.stdin.readline()))
# determine m, g
g = [1]
m = 1
while True:
x = 3 * g[m - 1] + 1
if x >= n: break
g.append(x)
m += 1
g = g[::-1]
# 1 output m
print(m)
# 2 output g
print(' '.join(map(str, g)))
# sort it
cnt = 0
for i in range(m):
isort(a, n, g[i])
# 3 output cnt
print(cnt)
# 4 output sorted a
print('\n'.join(map(str, a))) |
s342355935 | p02262 | u609407244 | 1436259320 | Python | Python3 | py | Runtime Error | 19920 | 47308 | 661 | #!/usr/bin/python
import sys
if sys.version_info[0]>=3: raw_input=input
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
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):
insertionSort(a,g[i])
a=[int(raw_input()) for i in range(int(raw_input()))]
shellSort(a)
print(cnt)
for e in a: print(e) |
s389857045 | p02262 | u197445199 | 1442297636 | Python | Python | py | Runtime Error | 0 | 0 | 536 | import math
N = int(raw_input())
A = []
for i in range(N):
a = raw_input()
A.append(int(a))
g_pre_list = [1093, 364, 121, 40, 13, 4, 1]
g_list = []
for g in g_pre_list:
if g < math.ceil((N**1.5):
g_list.append(g)
print len(g_list)
print " ".join(map(str, g_list))
count = 0
for g in g_list:
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
count += 1
A[j+g] = v
print count
print "\n".join(map(str, A)) |
s729311605 | p02262 | u072053884 | 1444715383 | Python | Python3 | py | Runtime Error | 0 | 0 | 392 | n = int(input())
A = [int(input()) for i in range(n)]
#shellSort
cnt = 0
m = 3
G = [n - 1,int((n - 1) / 2) 1]
for i in range(m):
g = G[i]
# insertionSort
for j in range(g, n):
k = j - g
while (k >= 0) and (A[k] > A[k + g]):
A[k + g], A[k] = A[k], A[k + g]
k -= g
cnt += 1
print(m)
print(*G)
print(cnt)
for i in A:
print(i) |
s381492220 | p02262 | u072053884 | 1444757778 | Python | Python3 | py | Runtime Error | 0 | 0 | 472 | import sys
A = list(map(int, sys.stdin.read().split("\n")))
n = A[0]
del A[0]
#shellSort
cnt = 0
G = []
tg = 1
while tg <= n:
G.append(tg)
tg = 3 * tg + 1
G.reverse()
m = len(G)
for i in range(m):
g = G[i]
# insertionSort
for j in range(g, n):
k = j - g
while (k >= 0) and (A[k] > A[k + g]):
A[k + g], A[k] = A[k], A[k + g]
k -= g
cnt += 1
print(m)
print(*G)
print(cnt)
for i in A:
print(i) |
s698680901 | p02262 | u963402991 | 1448344505 | Python | Python3 | py | Runtime Error | 0 | 0 | 719 | def insertionSort(A, n, g):
global count
for i in range(g,n):
v = A[i]
j = i - g
#間隔gずつ選択ソートを行っていく
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j -= g
count += 1
A[j+g] = v
def shellSort(A, n):
global count
G = [i for i in range(1,n) if i % 3 == 1] #シェルソートで用いる配列Gはmod3 == 1の倍数のを用いる
m = len(G)
G = G[::-1]
for i in G:
insertionSort(A, n, i)
return A, G, m
#input data
n = int(input())
A = [int(input()) for i in range(n)]
count = 0
A, G, m = shellSort(A, n)
print (m)
print (G)
print (cnt)
for i in range(len(A)):
print (A[i]) |
s900180595 | p02262 | u963402991 | 1448344672 | Python | Python3 | py | Runtime Error | 0 | 0 | 587 | n = int(input())
A = [int(input()) for i in range(n)]
count = 0
def insertionSort(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 -= g
count += 1
A[j+g] = v
def shellSort(A, n):
global count
G = [i for i in range(1,n) if i % 3 == 1]
m = len(G)
G = G[::-1]
for i in G:
insertionSort(A, n, i)
return A, G, m
A, G, m = shellSort(A, n)
print (m)
print (G)
print (cnt)
for i in range(len(A)):
print (A[i]) |
s234316657 | p02262 | u488601719 | 1448782155 | Python | Python3 | py | Runtime Error | 0 | 0 | 587 | 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
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):
insertionSort(a,g[i])
a=[int(raw_input()) for i in range(int(raw_input()))]
shellSort(a)
print(cnt)
for e in a: print(e) |
s161838952 | p02262 | u488601719 | 1448782942 | Python | Python3 | py | Runtime Error | 0 | 0 | 672 | import math
def insertion_sort(A, N, g):
for i in range(g, N):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
# v????????§???????????°???????????????
A[j+g] = A[j]
j -= g
A[j+g] = v
print(*A)
def shell_sort(a, n):
g = []
gap = 1
while gap <= math.ceil(n / 3):
g.append(gap)
gap = 3 * gap + 1
g = g[::-1]
m = len(g)
print(m)
print(*g)
cnt = 0
for i in range(m):
cnt += insertion_sort(a, n, g[i])
print(cnt)
n = int(input())
a = []
for i in range(n):
a.append(int(input()))
shell_sort(a, n)
print("\n".join(map(str, a))) |
s160383556 | p02262 | u341533698 | 1454397620 | Python | Python | py | Runtime Error | 0 | 0 | 823 | def insertionSort(A, n, g, cnt):
for i in xrange(1,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
return A, cnt
def shellSort(A, n):
cnt = 0
G = [1]
for i in range(1,len(A)):
if 3*G[i-1]+1 < len(A):
G.append(3*G[i-1]+1)
G = list(reversed(G[:]))
#print G
m = len(G)
print m
print ' '.join(map(str,G))
newA = A[:]
for i in range(0,m):
newA, cnt = insertionSort(newA[:],len(A),G[i],cnt)
return newA, cnt
def main():
n = int(input())
A = [int(input()) for i in xrange(n)]
newA, cnt = shellSort(A, n)
print cnt
for i in range(len(newA)):
print newA[i]
return 0
if __name__ == '__main__':
main() |
s390211766 | p02262 | u603356762 | 1464872680 | Python | Python3 | py | Runtime Error | 0 | 0 | 377 | N = int(input())
a = [int(x) for x in input().split()]
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
return A
def shellSort(A,n):
m = 3
G = [4,3,1]
for x in G:
A=insertionSort(A,n,x)
print(m)
print(*G)
print(cnt)
print(*A)
shellSort(a,N) |
s406578243 | p02262 | u603356762 | 1464873155 | Python | Python3 | py | Runtime Error | 0 | 0 | 390 | N = int(input())
a = [int(x) for x in input().split()]
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
return A
def shellSort(A,n):
m = 3
G = [4,3,1]
for x in G:
A=insertionSort(A,n,x)
print(m)
print(*G)
print(cnt)
for x in A:
print(x)
shellSort(a,N) |
s270295337 | p02262 | u603356762 | 1464873371 | Python | Python3 | py | Runtime Error | 0 | 0 | 388 | N = int(input())
a = [int(x) for x in input().split()]
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
return A
def shellSort(A,n):
m = 2
G = [4,1]
for x in G:
A=insertionSort(A,n,x)
print(m)
print(*G)
print(cnt)
for x in A:
print(x)
shellSort(a,N) |
s766841792 | p02262 | u496045719 | 1470301086 | Python | Python3 | py | Runtime Error | 0 | 0 | 935 | swap_count = 0
def main():
num = int(input())
elements = [int(x) for x in input().split()]
# Get max interval
intervals = []
for i in range(0, num):
interval = int_f(i)
if num <= interval:
break
intervals.append(interval)
for interval in intervals:
insertion_sort(elements, num, interval)
print(len(intervals))
print(' '.join([str(interval) for interval in intervals]))
print(swap_count)
print(' '.join([str(i) for i in elements]))
def int_f(x):
return 3 * x + 1
def insertion_sort(elements, num, interval=1):
global swap_count
i = interval
while i < num:
j = i
while interval <= j:
print("%s, i: %s, j: %s" % (elements, i, j))
if elements[j - interval] <= elements[j]:
break
elements[j - interval], elements[j] = elements[j], elements[j - interval]
swap_count += 1
j -= interval
i += 1
if __name__ == '__main__':
main() |
s542610658 | p02262 | u496045719 | 1470303785 | Python | Python3 | py | Runtime Error | 0 | 0 | 925 | swap_count = 0
def main():
num = int(input())
elements = []
for i in range(0, num):
elements.append(int(input()))
# Get intervals
interval = 1
intervals = [interval]
while True:
interval = int_f(interval)
if interval > num:
break
intervals.insert(0, interval)
for interval in intervals:
insertion_sort(elements, num, interval)
print(len(intervals))
print(' '.join([str(interval) for interval in intervals]))
print(swap_count)
for val in elements:
print(val)
def int_f(x):
return 2.25 * x + 1
def insertion_sort(elements, num, interval=1):
global swap_count
i = interval
while i < num:
j = i
while interval <= j:
if elements[j - interval] <= elements[j]:
break
elements[j - interval], elements[j] = elements[j], elements[j - interval]
swap_count += 1
j -= interval
i += 1
if __name__ == '__main__':
main() |
s716129733 | p02262 | u092047183 | 1471654376 | Python | Python3 | py | Runtime Error | 0 | 0 | 555 | # coding: utf-8
import math
import sys
def insertionSort(a, n, g):
ct = 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
ct += 1
a[j+g] = v
return ct
n = int(input())
a = list(map(int, sys.stdin.readlines()))
cnt = 0
m = 0
h = 0
g = []
while True:
h = 3*h + 1
if h > n:
break
g.insert(0, h)
for i in g:
cnt += insertionSort(a, n, i)
print(len(g))
print(*g, sep=" ")
print(cnt)
print(*a, sep="/n") |
s927291260 | p02262 | u390995924 | 1472577791 | Python | Python3 | py | Runtime Error | 0 | 0 | 600 | n = int(input())
A = [int(input()) for _ in range(n)]
def isort(n, g):
global A
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 -= g
cnt += 1
A[j + g] = v
def ssort(n):
global cnt
global A
cnt = 0
m = max(min(int(n / 3), 100), 1)
G = [m * 3 - 3 * (i + 1) + 1 for i in range(m - 1)]
G.append(1)
print(m)
print(" ".join([str(g) for g in G]))
for g in G:
isort(A, n, g)
ssort(n)
print(cnt)
print("\n".join([str(a) for a in A])) |
s099344903 | p02262 | u890722286 | 1474035320 | Python | Python3 | py | Runtime Error | 0 | 0 | 561 | import sys
n = int(input())
A = list(map(int, sys.stdin))
cnt = 0
def insertion_sort(L, n, g):
global cnt
for i in range(g, n):
v = L[i]
j = i - g
while 0 <= j and v < L[j]:
L[j+g] = L[j]
j -= g
cnt += 1
L[j+g] = v
def shell_sort(L, n):
global G
for i in G:
insertion_sort(L, n, i)
G = [i for i in [262913, 65921, 16577, 4193, 1073, 281, 77, 23, 8, 1] if i <= n]
shell_sort(A, n)
print(len(G))
print(' '.join(str(x) for x in G))
print(cnt)
for i in B:
print(i) |
s940024150 | p02262 | u890722286 | 1474035524 | Python | Python3 | py | Runtime Error | 0 | 0 | 683 | import sys
n = int(input())
A = list(map(int, sys.stdin))
cnt = 0
def insertion_sort(L, n, g):
global cnt
for i in range(g, n):
v = L[i]
j = i - g
while 0 <= j and v < L[j]:
L[j+g] = L[j]
j -= g
cnt += 1
L[j+g] = v
def shell_sort(L, n):
global G
for i in G:
insertion_sort(L, n, i)
#G = [i for i in [262913, 65921, 16577, 4193, 1073, 281, 77, 23, 8, 1] if i <= n]
g = []
for i in range(100):
x = pow(4, i)
if n < x:
break
else:
g.append(x)
G = reversed(g)
shell_sort(A, n)
print(len(G))
print(' '.join(str(x) for x in G))
print(cnt)
for i in A:
print(i) |
s552826873 | p02262 | u908984540 | 1474841100 | Python | Python3 | py | Runtime Error | 0 | 0 | 698 | # -*- coding:utf-8 -*-
cnt = 0
def insection_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 -= g
cnt += 1
a[j+g] = v
def shell_sort(a):
g = list(1)
temp = 4
while temp < len(a):
g.append(temp)
temp = 3 * temp + 1
print(len(g))
for youso in reversed(g):
if youso != 1:
print(youso, end=' ')
else:
print(youso)
insection_sort(a, youso)
inp_num = int(input())
a = list()
for i in range(inp_num):
a.append(int(input()))
shell_sort(a)
print(cnt)
for i in a:
print(i) |
s236822698 | p02262 | u500396695 | 1477009105 | Python | Python3 | py | Runtime Error | 0 | 0 | 791 | import math
def insertionsort(A, n, 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
return cnt
def shellsort(A, n):
G = [] ##??§????°???¨?????????????????°???(gap??????????????????)???????????????
gap = 1
while gap <= math.ceil(n / 3):
G.append(gap)
gap = gap * 3 + 1
G = G[::-1]
m = len(G)
print(m)
print(*G)
cnt = 0
for i in range(m):
insertionsort(A, n, G[i])
print(cnt)
n = int(input())
A = []
for i in range(n):
A.append(int(input()))
shellsort(A, n)
print("?\n".join(map(str, A))) ##a?????¨??????????´????str()????????§??????list?????????????????? |
s754001482 | p02262 | u922871577 | 1478938272 | Python | Python | py | Runtime Error | 10 | 6408 | 529 | cnt = 0
def insSort(A, n, g):
global cnt
for i in xrange(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 = range(n-1, 0, -3)
if G[-1] != 1:
G.append(1)
m = len(G)
print m
print ' '.join(map(str, G))
for i in xrange(m):
insSort(A, n, G[i])
N = input()
A = [int(raw_input()) for _ in xrange(N)]
shellSort(A, N)
print cnt
for a in A:
print a |
s677846266 | p02262 | u922871577 | 1478939940 | Python | Python | py | Runtime Error | 0 | 0 | 575 | cnt = 0
def insSort(A, n, g):
global cnt
for i in xrange(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 = reversed([i*i for i in xrange(1, n) if i*i < n])
if len(G) == 0 or G[-1] != 1:
G.append(1)
m = len(G)
print m
print ' '.join(map(str, G))
for i in xrange(m):
insSort(A, n, G[i])
N = input()
A = [int(raw_input()) for _ in xrange(N)]
shellSort(A, N)
print cnt
for a in A:
print a |
s226666477 | p02262 | u908984540 | 1482770429 | Python | Python3 | py | Runtime Error | 30 | 7824 | 1018 | # -*- coding:utf-8 -*-
import math
def insertion_sort(num_list, length, interval):
cnt = 0
for i in range(interval, length):
v = num_list[i]
j = i - interval
while j >= 0 and num_list[j] > v:
num_list[j+interval] = num_list[j]
j = j - interval
cnt = cnt + 1
num_list[j+interval] = v
return cnt
def shell_sort(num_list, length):
cnt = 0
h = 1
intervals = list()
while length > h:
intervals.append(h)
h = 3 * h + 1
for i in reversed(range(len(intervals))):
cnt = cnt + insertion_sort(num_list, length, intervals[i])
print(len(intervals))
show_list(intervals)
print(cnt)
def show_list(list):
i = len(list) - 1;
while i > 0:
print(list[i], end=" ")
i = i - 1
print(list[i])
input_num = int(input())
input_list = list()
for i in range(input_num):
input_list.append(int(input()))
shell_sort(input_list, input_num)
for num in input_list:
print(num) |
s326998040 | p02262 | u089830331 | 1483486068 | Python | Python3 | py | Runtime Error | 30 | 7708 | 514 | def insertion_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 = j - g
cnt += 1
A[j + g] = v
return cnt
def shell_sort(A, n):
cnt = 0
m = 5
G = [5,4,3,2,1]
for i in range(m):
cnt = insertion_sort(A, n, G[i], cnt)
return m, G, cnt
data = []
for i in range(int(input())):
data.append(int(input()))
m, G, cnt = shell_sort(data, 5)
print(m)
print(" ".join(map(str, G)))
print(cnt)
for i in data: print(i) |
s099675804 | p02262 | u918276501 | 1489058846 | Python | Python3 | py | Runtime Error | 0 | 0 | 795 | def insertion_sort(a, n, g):
ct = 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
ct += 1
a[j+g] = v
return ct
def interval_list(n):
m = 0
gi= 1
g = []
while b <= n:
m += 1
g.append(gi)
b = 4**m + 3 * 2**(m-1) + 1
# shell_sort ???????????¨????????????????????????????????\?????????URL
# http://www.programming-magic.com/20100507074241/
return g.reverse()
if __name__ == "__main__":
n = int(input())
A = list(int(input()) for _ in range(n))
G = interval_list(n)
print(len(G))
print(*G)
ct= 0
for i in G:
ct += insertion_sort(A, n, i)
print(ct)
print(*A, sep="\n") |
s164504441 | p02262 | u918276501 | 1489058878 | Python | Python3 | py | Runtime Error | 0 | 0 | 656 | def insertion_sort(a, n, g):
ct = 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
ct += 1
a[j+g] = v
return ct
def interval_list(n):
m = 0
gi= 1
g = []
while b <= n:
m += 1
g.append(gi)
b = 4**m + 3 * 2**(m-1) + 1
return g.reverse()
if __name__ == "__main__":
n = int(input())
A = list(int(input()) for _ in range(n))
G = interval_list(n)
print(len(G))
print(*G)
ct= 0
for i in G:
ct += insertion_sort(A, n, i)
print(ct)
print(*A, sep="\n") |
s077528309 | p02262 | u130834228 | 1490100412 | Python | Python3 | py | Runtime Error | 0 | 0 | 1290 | def InsertionSort(A, N, g):
global cnt
for i in range(g, N):
key = A[i]
j = i-g
while j >= 0 and A[j] > key:
A[j+g] = A[j]
j = j-gdef InsertionSort(A, N, g):
global cnt
for i in range(g, N):
key = A[i]
j = i-g
while j >= 0 and A[j] > key:
A[j+g] = A[j]
j = j-g
cnt += 1
A[j+g] = key
return A
def ShellSort(A, N):
G = [len(A)//2]
i = 0
while True:
G.append(G[i]//2)
i += 1
if G[i] == 1:
break
for i in range(len(G)):
InsertionSort(A, N, G[i])
return G
N = int(input())
A = []
cnt = 0
for i in range(N):
A.append(int(input()))
ShellSort(A,N)
print(len(ShellSort(A,N)))
print(*ShellSort(A,N))
print(cnt)
print(*A, sep='\n')
cnt += 1
A[j+g] = key
return A
def ShellSort(A, N):
G = [len(A)//3*3]
i = 0
while True:
G.append(G[i]//3)
i += 1
if G[i] == 1:
break
for i in range(len(G)):
InsertionSort(A, N, G[i])
return G
N = int(input())
A = []
cnt = 0
for i in range(N):
A.append(int(input()))
ShellSort(A,N)
print(len(ShellSort(A,N)))
print(*ShellSort(A,N))
print(cnt)
print(*A, sep='\n') |
s209064322 | p02262 | u796784914 | 1493448718 | Python | Python | py | Runtime Error | 0 | 0 | 699 | n = input()
A = [input() for i in range(n)]
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 -= g
cnt += 1
A[j+g] = v
return cnt
def shellSort(A,n):
cnt = 0
m = int((n-1)/3)
G = [1]
for i in range(1,n):
g = 3**i
if g > n:
break
G.append(G[i-1]+g)
m = len(G)
for i in range(m):
j = (m-1) - i
cnt = insertionSort(A,n,G[j])
return m, G, cnt
m, G, cnt = shellSort(A,n)
print m
for i in range(m-1):
j = m - i
print G[j],
print G[0]
for item in A:
print item |
s712969226 | p02262 | u091533407 | 1497751538 | Python | Python3 | py | Runtime Error | 30 | 7868 | 745 | # -*- coding: utf-8 -*-
"""
Created on Sun Jun 18 10:42:00 2017
@author: syaga
"""
import math
def insertionSort(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 = j - g
cnt += 1
A[j+g] = v
return cnt
def shellSort(A, n):
cnt = 0
m = int(math.log(n-1,4)) + 1
print(m)
G = [4**i for i in range(m-1, -1, -1)]
print(" ".join(map(str, G)))
for i in range(0, m):
cnt = insertionSort(A, n, G[i], cnt)
print(cnt)
if __name__ == "__main__":
n = int(input())
A = []
for i in range(n):
A.append(int(input()))
shellSort(A, n)
for i in A:
print(i) |
s892677012 | p02262 | u264972437 | 1500305389 | Python | Python3 | py | Runtime Error | 0 | 0 | 644 | import math
def insertionSort(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 = j - g
cnt += 1
A[j+g] = v
return A,cnt
def shellSort(A,n):
cnt = 0
#m = n//2 + 1
#G = [2*i + 1*(i==0) for i in range(m)[::-1]]
m = int(math.log(n,2)) + 1
G = [2**i for i in range(m)[::-1]]
for g in G:
A,cnt = insertionSort(A,n,g,cnt)
return A,m,G,cnt
if __name__ == '__main__':
n = int(input())
A = []
[A.append(int(input())) for i in range(n)]
A,m,G,cnt = shellSort(A,n)
print(m)
print(' '.join([str(i) for i in G]))
print(cnt)
[print(a) for a in A]
print(A == sorted(data)) |
s971999646 | p02262 | u914146430 | 1500789489 | Python | Python3 | py | Runtime Error | 0 | 0 | 486 | def insertionSort(a,n,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
global cnt
cnt+=1
a[j+g]=v
def shellsort(a,n):
# global cnt
cnt=0
g=[(3**i-1)//2 for i in range(n,0,-1) if (3**i-1)//2<n]
m=len(g)
#print(g,m)
for i in range(m):
insertionSort(a,n,g[i])
return a,m,g
a,m,g=shellsort(a,n)
print(m)
print(*g)
for i in a:
print(i) |
s139266627 | p02262 | u539803218 | 1501633736 | Python | Python3 | py | Runtime Error | 0 | 0 | 534 | import math
def insertionSort(a, n, g):
ct = 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
ct += 1
a[j+g] = v
return ct
n = int(input())
a = list(map(int, input().split()))
cnt = 0
m = 0
h = 0
g = []
while True:
h = 3*h + 1
if h > n:
break
g.insert(0, math.ceil(h))
for i in g:
cnt += insertionSort(a, n, i)
print(len(g))
print(*g, sep=" ")
print(cnt)
print(*a, sep="\n") |
s884283877 | p02262 | u539803218 | 1501633755 | Python | Python3 | py | Runtime Error | 0 | 0 | 534 | import math
def insertionSort(a, n, g):
ct = 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
ct += 1
a[j+g] = v
return ct
n = int(input())
a = list(map(int, input().split()))
cnt = 0
m = 0
h = 0
g = []
while True:
h = 3*h + 1
if h > n:
break
g.insert(0, math.ceil(h))
for i in g:
cnt += insertionSort(a, n, i)
print(len(g))
print(*g, sep=" ")
print(cnt)
print(*a, sep="\n") |
s602155059 | p02262 | u539803218 | 1501633766 | Python | Python3 | py | Runtime Error | 0 | 0 | 534 | import math
def insertionSort(a, n, g):
ct = 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
ct += 1
a[j+g] = v
return ct
n = int(input())
a = list(map(int, input().split()))
cnt = 0
m = 0
h = 0
g = []
while True:
h = 3*h + 1
if h > n:
break
g.insert(0, math.ceil(h))
for i in g:
cnt += insertionSort(a, n, i)
print(len(g))
print(*g, sep=" ")
print(cnt)
print(*a, sep="\n") |
s138912733 | p02262 | u539803218 | 1501633792 | Python | Python3 | py | Runtime Error | 0 | 0 | 548 | #coding:utf-8
import math
def insertionSort(a, n, g):
ct = 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
ct += 1
a[j+g] = v
return ct
n = int(input())
a = list(map(int, input().split()))
cnt = 0
m = 0
h = 0
g = []
while True:
h = 3*h + 1
if h > n:
break
g.insert(0, math.ceil(h))
for i in g:
cnt += insertionSort(a, n, i)
print(len(g))
print(*g, sep=" ")
print(cnt)
print(*a, sep="\n") |
s580835863 | p02262 | u491916705 | 1502095043 | Python | Python | py | Runtime Error | 0 | 0 | 579 | n = int(raw_input())
a = []
for i in range(n):
a.append(int(raw_input()))
cnt = 0
num = 1
G = [1]
while 1:
if num*3+1 > n:
break
G.insert(0, num*3+1)
num = num*3 + 1
m = num
def insertionSort(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 = j - g
cnt += 1
A[j+g] = v
return cnt
print m
for i in range(m):
if i == m-1:
print G[i]
else:
print G[i],
print cnt
for i in range(n):
print a[i] |
s002006265 | p02262 | u508732591 | 1502781361 | Python | Python3 | py | Runtime Error | 0 | 0 | 546 | import sys
import math
ct= 0
def insertion_sort(a, n, g):
for j in range(0,n-g):
v = a[j+g]
while j >= 0 and a[j] > v:
a[j+g] = a[j]
j = j-g
ct += 1
a[j+g] = v
n = int(input())
a = list(map(int, sys.stdin.readlines()))
b = 701
g = [x for x in [1,4,10,23,57,132,301,701] if x <= n]
while True:
b = math.floor(2.25*b)
if b > n:
break
g.append(b)
g = g[::-1]
for i in g:
insertion_sort(a, n, i)
print(len(g))
print(*g, sep=" ")
print(ct)
print(*a, sep="\n") |
s775880498 | p02262 | u659034691 | 1503264572 | Python | Python3 | py | Runtime Error | 150 | 8228 | 593 | #shellSort(A, n)
n=int(input())
A=[int(input()) for i in range(n)]
cnt = 0
G=[1]
S=str(G[0])
#if 5<n<13:
t=n//2
#elif n<3000:
# t=n//9
#else:
# t=n//17
Gt=[4, 9, 20, 46, 103, 233, 525, 1182,2660, 5985, 13467]
i=0
while Gt[i]<t:
G.insert(0,Gt[i])
# print (i)
S=str(G[0])+" "+S
i+=1
m=len(G)
print (m)
print(S)
for i in range(m):
g=G[i]
for j in range(g,n):
v = A[j]
k = j - g
while k >= 0 and A[k] > v:
A[k+g] = A[k]
k = k - g
cnt+=1
A[k+g] = v
print(cnt)
for i in range(n):
print(A[i]) |
s281115840 | p02262 | u024715419 | 1507624326 | Python | Python3 | py | Runtime Error | 0 | 0 | 449 | def insertionSort(a,n,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
n = int(input())
a = [int(input()) for i in range(n)]
cnt = 0
i = 0
g = [1]
while 3*g[i]+1 < n:
g.append(3*g[i]+1)
i += 1
m = len(g)
for i in range(m):
insertionSort(a,n,g)
print(m)
print(*g)
print(cnt)
print(*a, sep="\n") |
s980335946 | p02262 | u024715419 | 1507624579 | Python | Python3 | py | Runtime Error | 0 | 0 | 461 | def insertionSort(a,n,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
global cnt += 1
a[j + g] = v
cnt = 0
n = int(input())
a = [int(input()) for i in range(n)]
i = 0
g = [1]
while 3*g[i]+1 < n:
g.append(3*g[i]+1)
i += 1
m = len(g)
for i in range(m):
insertionSort(a,n,g[i])
print(m)
print(*g)
print(cnt)
print(*a, sep="\n") |
s236149012 | p02262 | u928329738 | 1511971443 | Python | Python3 | py | Runtime Error | 0 | 0 | 630 | g_m=0
g_G=[]
g_cnt=0
A=[]
n = int(input())
for i in range(n):
A.append(int(input()))
def insertionSort(A,n,g):
global 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 = j-g
g_cnt += 1
A[j+g]=v
def shellSort(A,n):
cnt = 0
m = int(n**0.5)
g_m=m
G=[]
for i in range(1,n,3*i):
G.append(i)
g_G=G
for i in range(0,m):
insertionSort(A,n,G[i])
return A,m,G
A,g_m,g_G=shellSort(A,n)
print(g_m)
print(" ".join(map(str,g_G)))
print(g_cnt)
print(" ".join(map(str,A))) |
s346040315 | p02262 | u928329738 | 1511971681 | Python | Python3 | py | Runtime Error | 0 | 0 | 660 | g_m=0
g_G=[]
g_cnt=0
A=[]
n = int(input())
for i in range(n):
A.append(int(input()))
def insertionSort(A,n,g):
global 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 = j-g
g_cnt += 1
A[j+g]=v
def shellSort(A,n):
cnt = 0
m = int(n**0.5)
g_m=m
G=[]
j=1
for i in range(1,n,3*j):
G.append(i)
j=3*j
G=G.reverse()
for i in range(0,m):
insertionSort(A,n,G[i])
return A,m,G
A,g_m,g_G=shellSort(A,n)
print(g_m)
print(" ".join(map(str,g_G)))
print(g_cnt)
print(" ".join(map(str,A))) |
s026267485 | p02262 | u928329738 | 1511973843 | Python | Python3 | py | Runtime Error | 100 | 6212 | 661 | g_m=0
g_G=[]
g_cnt=0
A=[]
n = int(input())
for i in range(n):
A.append(int(input()))
def insertionSort(A,n,g):
global 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 = j-g
g_cnt += 1
A[j+g]=v
def shellSort(A,n):
m=1
G=[]
j=1
for i in range(0,10):
G.append(j)
j=3*j+1
while G[m]<=n:
m+=1
G=G[:m]
G.reverse()
for i in range(0,m):
insertionSort(A,n,G[i])
return A,m,G
A,g_m,g_G=shellSort(A,n)
print(g_m)
print(" ".join(map(str,g_G)))
print(g_cnt)
print(*A,sep="\n") |
s086091686 | p02262 | u928329738 | 1511973975 | Python | Python3 | py | Runtime Error | 1290 | 10636 | 662 | g_m=0
g_G=[]
g_cnt=0
A=[]
n = int(input())
for i in range(n):
A.append(int(input()))
def insertionSort(A,n,g):
global 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 = j-g
g_cnt += 1
A[j+g]=v
def shellSort(A,n):
m=1
G=[]
j=1
for i in range(0,100):
G.append(j)
j=3*j+1
while G[m]<=n:
m+=1
G=G[:m]
G.reverse()
for i in range(0,m):
insertionSort(A,n,G[i])
return A,m,G
A,g_m,g_G=shellSort(A,n)
print(g_m)
print(" ".join(map(str,g_G)))
print(g_cnt)
print(*A,sep="\n") |
s792716712 | p02262 | u409571842 | 1514443760 | Python | Python3 | py | Runtime Error | 350 | 6896 | 835 | #coding: UTF-8
import copy
class Algo:
cnt = 0
@staticmethod
def insertionSort(a, n, 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 -= g
Algo.cnt += 1
a[j+g] = v
def shellSort(a, n):
if n > 40:
G = [40, 13, 4, 1]
elif n <= 40 and n > 13:
G = [13, 4, 1]
elif n <= 13 and n > 4:
G = [4, 1]
else:
G = [1]
m = len(G)
for i in range(0, m):
Algo.insertionSort(a, n, G[i])
print(m)
for i in range(0, len(G)):
if i == len(G)-1:
print(G[i])
else:
print(G[i], " ", sep="", end="")
print(Algo.cnt)
for i in range(0, n):
print(a[i])
n = int(input())
l = []
for i in range(0, n):
l.append(int(input()))
Algo.shellSort(copy.deepcopy(l), n) |
s109786133 | p02262 | u409571842 | 1514444333 | Python | Python3 | py | Runtime Error | 1720 | 11412 | 752 | #coding: UTF-8
import copy
class Algo:
cnt = 0
@staticmethod
def insertionSort(a, n, 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 -= g
Algo.cnt += 1
a[j+g] = v
def shellSort(a, n):
h = 1
G = []
while h <= n:
G.insert(0, h)
h = h*3+1
m = len(G)
for i in range(0, m):
Algo.insertionSort(a, n, G[i])
print(m)
for i in range(0, len(G)):
if i == len(G)-1:
print(G[i])
else:
print(G[i], " ", sep="", end="")
print(Algo.cnt)
for i in range(0, n):
print(a[i])
n = int(input())
l = []
for i in range(0, n):
l.append(int(input()))
Algo.shellSort(copy.deepcopy(l), n) |
s201695706 | p02262 | u662418022 | 1516274323 | Python | Python3 | py | Runtime Error | 1320 | 9852 | 885 | # -*- coding: utf-8 -*-
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 -= g
cnt += 1
A[j+g] = v
def shellSort(A, n):
def func(m):
if m == 0:
return 1
else:
return func(m-1)*3 + 1
G = []
i = 0
while True:
gi = func(i)
if gi <= n:
G.append(gi)
i += 1
else:
break
G = G[::-1]
for g in G:
insertionSort(A, n , g)
return A, G
if __name__ == '__main__':
n = int(input())
A = [int(input()) for i in range(n)]
cnt = 0
A, G = shellSort(A, n)
print(len(G))
print(" ".join(map(str, G)))
print(cnt)
for i in range(n):
print(A[i])
|
s954985992 | p02262 | u662418022 | 1516275262 | Python | Python3 | py | Runtime Error | 0 | 0 | 708 | # -*- coding: utf-8 -*-
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 -= g
cnt += 1
A[j+g] = v
def shellSort(A, n):
G = []
i = 0
g = 1
while g <= len(A):
G.append(g)
g = 3*g+1
G = G.reverse()
for g in G:
insertionSort(A, n , g)
return A, G
if __name__ == '__main__':
n = int(input())
A = [int(input()) for i in range(n)]
cnt = 0
A, G = shellSort(A, n)
print(len(G))
print(" ".join(map(str, G)))
print(cnt)
for i in range(n):
print(A[i])
|
s723370130 | p02262 | u426534722 | 1516290332 | Python | Python3 | py | Runtime Error | 0 | 0 | 583 | def insertionSort(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
h = 1
G = []
while h < n:
G += [h]
h = 3 * h + 1
m = len(G)
for i in range(m - 1, -1, -1):
cnt = insertionSort(A, n, G[i], cnt)
print(m)
print(*G[::-1])
print(cnt)
print(*A, sep="\n")
n = int(input())
A = [int(readline()) for _ in range(n)]
shellSort(A, n)
|
s801603518 | p02262 | u152639966 | 1516303670 | Python | Python3 | py | Runtime Error | 1900 | 12176 | 458 | n=int(input())
A=[]
G=[]
for i in range(n):
A.append(input())
cnt=0
flag=1
h=1
while flag:
G.append(str(h))
h=3*h+1
if h>n:
flag=0
m=len(G)
G.reverse()
def Insertion_Sort(A,n,g,cnt):
for i in range(g,n):
v=int(A[i])
j=i-g
while j>=0 and int(A[j])>v:
A[j+g]=A[j]
j=j-g
cnt+=1
A[j+g]=v
return(cnt)
for i in range(m):
cnt=Insertion_Sort(A,n,int(G[i]),cnt)
print(m)
print(' '.join(G))
print(cnt)
for i in range(n):
print(A[i])
|
s219155712 | p02262 | u839008951 | 1516432424 | Python | Python3 | py | Runtime Error | 4830 | 10620 | 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 *= 2
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)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.