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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
s692870752 | p02261 | u637322311 | 1531748937 | Python | Python3 | py | Runtime Error | 0 | 0 | 1406 | import copy
def print_list(A):
print(*A, sep=" ")
def swap(a, b):
return b, a
def val(str):
return int(str[1])
def is_stable(_in, _out, n):
for i in range(0, n):
for j in range(i+1, n):
for a in range(0, n):
for b in range(a+1, n):
if val(_in[i]) == val(_in[j]) and _in[i] == _out[b] and _in[j] == _out[a]:
return False
return True
def print_stable(_in, _out, n):
if is_stable(_in, _out, n):
print("Stable")
else:
print("Not Stable")
def find_minj(A, i, n):
minj = i
for j in range(i, n):
if val(A[j]) < val(A[minj]):
minj = j
return minj
def bubble_sort(A, n):
A0 = copy.copy(A)
flg = 1 #逆の隣接要素が存在する
i = 0
while flg:
flg = 0
for j in range(n-1, i, -1):
if val(A[j-1]) > val(A[j]):
A[j-1], A[j] = swap(A[j-1], A[j])
flg = 1
i += 1
print_list(A)
print_stable(A0, A, n)
def selection_sort(A, n):
A0 = copy.copy(A)
for i in range(0, n):
minj = find_minj(A, i, n)
if val(A[i]) > val(A[minj]):
A[i], A[minj] = swap(A[i], A[minj])
print_list(A)
print_stable(A0, A, n)
n = int(input())
A = list(map(int,input().split()))
B = copy.copy(A)
bubble_sort(A, n)
selection_sort(B, n)
|
s680479326 | p02261 | u637322311 | 1531749111 | Python | Python3 | py | Runtime Error | 0 | 0 | 1406 | import copy
def print_list(A):
print(*A, sep=" ")
def swap(a, b):
return b, a
def val(str):
return int(str[1])
def is_stable(_in, _out, n):
for i in range(0, n):
for j in range(i+1, n):
for a in range(0, n):
for b in range(a+1, n):
if val(_in[i]) == val(_in[j]) and _in[i] == _out[b] and _in[j] == _out[a]:
return False
return True
def print_stable(_in, _out, n):
if is_stable(_in, _out, n):
print("Stable")
else:
print("Not stable")
def find_minj(A, i, n):
minj = i
for j in range(i, n):
if val(A[j]) < val(A[minj]):
minj = j
return minj
def bubble_sort(A, n):
A0 = copy.copy(A)
flg = 1 #逆の隣接要素が存在する
i = 0
while flg:
flg = 0
for j in range(n-1, i, -1):
if val(A[j-1]) > val(A[j]):
A[j-1], A[j] = swap(A[j-1], A[j])
flg = 1
i += 1
print_list(A)
print_stable(A0, A, n)
def selection_sort(A, n):
A0 = copy.copy(A)
for i in range(0, n):
minj = find_minj(A, i, n)
if val(A[i]) > val(A[minj]):
A[i], A[minj] = swap(A[i], A[minj])
print_list(A)
print_stable(A0, A, n)
n = int(input())
A = list(map(int,input().split()))
B = copy.copy(A)
bubble_sort(A, n)
selection_sort(B, n)
|
s269496964 | p02261 | u313089641 | 1531758061 | Python | Python3 | py | Runtime Error | 0 | 0 | 1499 | _ = int(input())
l2 = list(map(int, input().split()))
class Card():
def __init__(self, card):
self.card = card
self.mark = card[0]
self.number = card[1]
def __lt__(self, other):
if not isinstance(other, Card):
return NotImplemented
return self.number < other.number
def __eq__(self, other):
if not isinstance(other, Card):
return NotImplemented
return self.mark == other.mark and self.number == other.number
def __repr__(self):
return '{}{}'.format(self.mark, self.number)
def ls_sort(self):
return
def BubbleSort(target):
ls = target.copy()
flag = 1
while flag:
flag = 0
for i in range(len(ls)-1, 0, -1):
if ls[i] < ls[i-1]:
ls[i], ls[i-1] = ls[i-1], ls[i]
flag = 1
print(' '.join(map(str, ls)))
return sorted(ls)
def SelectSort(target):
ls = target.copy()
for i in range(len(ls)):
minj = i
for j in range(i+1, len(ls)):
if ls[j] < ls[minj]:
minj = j
if ls[i] != ls[minj]:
ls[i], ls[minj] = ls[minj], ls[i]
print(' '.join(map(str, ls)))
return sorted(ls)
l2 = [Card(i) for i in l2]
l2_sort = sorted(l2)
print(l2_sort)
bubble = BubbleSort(l2)
if bubble == l2_sort:
print('a')
else:
print('b')
select = SelectSort(l2)
if select == l2_sort:
print('a')
else:
print('b')
|
s288480625 | p02261 | u635209856 | 1541160299 | Python | Python3 | py | Runtime Error | 0 | 0 | 709 | def bubble(A):
flag=True;
n=len(A)
i=0
while flag:
for j in range(n-1,i,-1):
if A[j][1]<A[j-1][1]:
A[j],A[j-1]=A[j-1],A[j]
flag=True
i+=1
def selection(A):
n=len(A)
for i in range(n):
minj=i
for j in range(i,n):
if A[j][1]<A[minj][1]:
if i!=minj:
A[i],A[minj]=A[minj],A[i]
n=int(input())
ss=[x for x in input().split()]
ss2=ss.copy()
bubble(ss)
for i in range(len(ss)-1):
print(ss[i],end=' ')
print(ss[-1])
print('Stable')
selection(ss2)
for i in range(len(ss2)-1):
print(ss2[i],end=' ')
print(ss2[-1])
if ss=ss2:
print('Stable')
else:
print('Not stable')
|
s071717059 | p02261 | u312681524 | 1546420457 | Python | Python | py | Runtime Error | 0 | 0 | 1203 | <?php
fscanf(STDIN, '%d', $N);
$line = trim(fgets(STDIN));
$arr = explode(' ', $line);
$bubbleArr = BubbleSort($arr,$N);
echo(implode(' ',$bubbleArr).PHP_EOL."Stable".PHP_EOL);
$selectionArr = SelectionSort($arr,$N);
echo implode(" ",$selectionArr) . PHP_EOL;
isStable($bubbleArr, $selectionArr);
function BubbleSort($arr,$N)
{
for ($i = 0; $i<$N; ++$i) {
for ($j = $N-1; $j>$i; --$j) {
if ($arr[$j][1] < $arr[$j-1][1]) {
$tmp = $arr[$j];
$arr[$j] = $arr[$j - 1];
$arr[$j - 1] = $tmp;
}
}
}
return $arr;
}
function SelectionSort($arr, $N){
for ($i=0; $i<$N; ++$i){
$mini = $i;
for ($j=$i; $j<$N; ++$j){
if ($arr[$j][1] < $arr[$mini][1]){
$mini = $j;
}
}
if($mini!=$i){
$tmp = $arr[$i];
$arr[$i] = $arr[$mini];
$arr[$mini] = $tmp;
}
}
return $arr;
}
function isStable($bubbleArr, $selectionArr){
$result = array_diff_assoc($bubbleArr, $selectionArr);
if(count($result)==0){
echo("Stable".PHP_EOL);
} else {
echo("Not stable".PHP_EOL);
}
}
|
s502861917 | p02261 | u412294315 | 1559288406 | Python | Python3 | py | Runtime Error | 20 | 5624 | 1568 | class Sort():
def __init__(self,n,cards):
self.cards = cards
self.n = n
def bubble_sort(self):
# bubble sort
flag = 1
while flag != 0:
flag = 0
rev = list(range(1,self.n))
rev.reverse()
for j in rev:
if int(self.cards[j][1]) < int(self.cards[j-1][1]):
self.cards[j],self.cards[j-1] = self.cards[j-1],self.cards[j]
flag = 1
def select_sort(self):
for i in range(self.n):
mini = i
for j in range(i,self.n):
if int(self.cards[j][1]) < int(self.cards[mini][1]):
mini = j
if i != mini:
self.cards[i],self.cards[mini] = self.cards[mini],self.cards[i]
def check_stable(self,origin):
check_org = [["" for i in range(self.n)] for k in range(9)]
check_sort = [["" for i in range(self.n)] for k in range(9)]
for i in range(self.n):
check_org[int(origin[i][1])-1][i] = origin[i][0]
check_sort[int(self.cards[i][1])-1][i] = self.cards[i][0]
flag = 0
for i in range(self.n):
if "".join(check_org[i]) != "".join(check_sort[i]):
flag = 1
break
if flag == 0:
print("Stable")
else:
print("Not stable")
def print_card(self):
for i in range(self.n):
if i != self.n-1:
print("%s" % (self.cards[i]),end=" ")
else:
print("%s" % (self.cards[i]))
if __name__ == '__main__':
n = int(input())
card = input().split()
card2 = card.copy()
card_origin = card.copy()
bubble = Sort(n,card)
bubble.bubble_sort()
bubble.print_card()
bubble.check_stable(card_origin)
select = Sort(n,card2)
select.select_sort()
select.print_card()
select.check_stable(card_origin)
|
s737804692 | p02261 | u567380442 | 1421308790 | Python | Python3 | py | Runtime Error | 0 | 0 | 928 | def compare_cards(a, b):
return a[1] < b[1]
def bubble(C):
for i in range(len(C)):
for j in range(len(C) - 1, i, -1):
if compare_cards(C[j], C[j - 1]):
C[j], C[j - 1] = C[j -1], C[j]
def selection(C):
for i in range(len(C)):
mini = i
for j in range(i, len(C)):
if compare_cards(C[j], C[mini]):
mini = j
C[i], C[mini] = C[mini], C[i]
def check_stable(originC, sortedC):
for i in range(len(originC) - 1):
if not compare_cards(sortedC[i], sortedC[i + 1]):
if originC.index(sortedC[i]) > originC.index(sortedC[i + 1]):
return 'Not stable'
return 'Stable'
N = int(input())
C = input().split()
bubbleC = C.copy()
selectionC = C.copy()
bubble(bubbleC)
selection(selectionC)
print(*bubbleC)
print(check_stable(C, bubbleC))
print(*selectionC)
print(check_stable(C, selectionC)) |
s287836713 | p02261 | u567380442 | 1421309382 | Python | Python3 | py | Runtime Error | 0 | 0 | 863 | def compare_cards(a, b):
return a[1] < b[1]
def bubble(C):
for i in range(len(C)):
for j in range(len(C) - 1, i, -1):
if compare_cards(C[j], C[j - 1]):
C[j], C[j - 1] = C[j -1], C[j]
def selection(C):
for i in range(len(C)):
mini = i
for j in range(i, len(C)):
if compare_cards(C[j], C[mini]):
mini = j
C[i], C[mini] = C[mini], C[i]
def check_stable(originC, sortedC):
for i in range(len(originC) - 1):
if not compare_cards(sortedC[i], sortedC[i + 1]):
if originC.index(sortedC[i]) > originC.index(sortedC[i + 1]):
return 'Not stable'
return 'Stable'
N = int(input())
C = input().split()
bubbleC = C.copy()
selectionC = C.copy()
bubble(bubbleC)
#selection(selectionC)
print(*C) |
s429676893 | p02261 | u567380442 | 1421309475 | Python | Python3 | py | Runtime Error | 0 | 0 | 312 | def compare_cards(a, b):
return a[1] < b[1]
def bubble(C):
for i in range(len(C)):
for j in range(len(C) - 1, i, -1):
if compare_cards(C[j], C[j - 1]):
C[j], C[j - 1] = C[j -1], C[j]
N = int(input())
C = input().split()
bubbleC = C.copy()
bubble(bubbleC)
print(*C) |
s045058781 | p02261 | u567380442 | 1421309628 | Python | Python3 | py | Runtime Error | 0 | 0 | 338 | def compare_cards(a, b):
return a[1] < b[1]
def bubble(C):
for i in range(len(C)):
for j in range(len(C) - 1, i, -1):
if compare_cards(C[j], C[j - 1]):
C[j], C[j - 1] = C[j -1], C[j]
N = int(input())
C = input().split()
bubbleC = C.copy()
#bubble(bubbleC)
compare_cards(C[0],C[1])
print(*C) |
s726938574 | p02261 | u567380442 | 1421309767 | Python | Python3 | py | Runtime Error | 0 | 0 | 152 | def compare_cards(a, b):
return int(a[1]) < int(b[1])
N = int(input())
C = input().split()
bubbleC = C.copy()
#compare_cards(C[0],C[1])
print(*C) |
s149223007 | p02261 | u313994256 | 1442293630 | Python | Python | py | Runtime Error | 0 | 0 | 749 | #??????????????????
N = int(raw_input())
num_list1 = raw_input().split()
num_list2 = num_list1
flag = 1
while flag==1:
flag =0
for j in range(N-1,0,-1):
if int(num_list1[j][1:]) < int(num_list1[j-1][1:]):
a = num_list1[j]
num_list1[j] = num_list1[j-1]
num_list1[j-1] = a
flag =1
print " ".join(num_list1)
print "Stable"
#???????????????
for i in range(0,N,1):
minj =i
for j in range(i,N,1):
if int(num_list2[j][1:]) < int(num_list2[minj][1:]):
minj = j
num_list2[i], num_list2[minj] = num_list2[minj], num_list2[i]
print " ".join(num_list2)
if num_list1 == num_list2:
print "Stable"
else:
print "Not Stable" |
s141648409 | p02261 | u885889402 | 1442293831 | Python | Python3 | py | Runtime Error | 0 | 0 | 1338 | def str_selection_sort(a,n):
m=0
for i in range(0,n):
minj=i
for j in range(i,n):
if(int(a[minj][1:]) > int(a[j][1:])):
minj=j
if(minj!=i):
m+=1
a[minj],a[i] = a[i],a[minj]
print(" ".join(a))
return a
def bubble_sort(a,n):
m=0
flag=True
while(flag):
flag=False
for i in range(n-1,0,-1):
if(a[i-1][1:] > a[i][1:]):
tmp=a[i-1]
a[i-1]=a[i]
m+=1
a[i]=tmp
flag=True
b=list(map(str,a))
print(" ".join(b))
def is_stable(a,b,n):
for i in range(1,n):
if(b[i-1][1:]!=b[i][1:]):
continue
flag=False
for j in a:
if(j[:1]==b[i-1][:1] and (not flag)):
flag=True
continue
if(j[:1]==b[i][:1]):
if(not flag):
return False
else:
return True
if(flag):
return False
a=[]
n=int(input())
s=input()
a=s.split()
b=str_bubble_sort(list(a),n)
if(is_stable(a,b,n)):
print("Stable")
else:
print("Not stable")
b=str_selection_sort(list(a),n)
if(is_stable(a,b,n)):
print("Stable")
else:
print("Not stable") |
s972219050 | p02261 | u885889402 | 1442293949 | Python | Python3 | py | Runtime Error | 0 | 0 | 1315 | def str_selection_sort(a,n):
m=0
for i in range(0,n):
minj=i
for j in range(i,n):
if(int(a[minj][1:]) > int(a[j][1:])):
minj=j
if(minj!=i):
m+=1
a[minj],a[i] = a[i],a[minj]
print(" ".join(a))
return a
def bubble_sort(a,n):
m=0
flag=True
while(flag):
flag=False
for i in range(n-1,0,-1):
if(a[i-1][1:] > a[i][1:]):
tmp=a[i-1]
a[i-1]=a[i]
m+=1
a[i]=tmp
flag=True
print(" ".join(a))
def is_stable(a,b,n):
for i in range(1,n):
if(b[i-1][1:]!=b[i][1:]):
continue
flag=False
for j in a:
if(j[:1]==b[i-1][:1] and (not flag)):
flag=True
continue
if(j[:1]==b[i][:1]):
if(not flag):
return False
else:
return True
if(flag):
return False
a=[]
n=int(input())
s=input()
a=s.split()
b=str_bubble_sort(list(a),n)
if(is_stable(a,b,n)):
print("Stable")
else:
print("Not stable")
b=str_selection_sort(list(a),n)
if(is_stable(a,b,n)):
print("Stable")
else:
print("Not stable") |
s827990699 | p02261 | u885889402 | 1442294019 | Python | Python3 | py | Runtime Error | 0 | 0 | 1331 | def str_selection_sort(a,n):
m=0
for i in range(0,n):
minj=i
for j in range(i,n):
if(int(a[minj][1:]) > int(a[j][1:])):
minj=j
if(minj!=i):
m+=1
a[minj],a[i] = a[i],a[minj]
print(" ".join(a))
return a
def bubble_sort(a,n):
m=0
flag=True
while(flag):
flag=False
for i in range(n-1,0,-1):
if(a[i-1][1:] > a[i][1:]):
tmp=a[i-1]
a[i-1]=a[i]
m+=1
a[i]=tmp
flag=True
print(" ".join(a))
def is_stable(a,b,n):
for i in range(1,n):
if(b[i-1][1:]!=b[i][1:]):
continue
flag=False
for j in a:
if(j[:1]==b[i-1][:1] and (not flag)):
flag=True
continue
if(j[:1]==b[i][:1]):
if(not flag):
return False
else:
return True
if(flag):
return False
return True
a=[]
n=int(input())
s=input()
a=s.split()
b=str_bubble_sort(list(a),n)
if(is_stable(a,b,n)):
print("Stable")
else:
print("Not stable")
b=str_selection_sort(list(a),n)
if(is_stable(a,b,n)):
print("Stable")
else:
print("Not stable") |
s080634886 | p02261 | u496045719 | 1469603631 | Python | Python3 | py | Runtime Error | 0 | 0 | 1305 | STABLE = 'Stable'
UNSTABLE = 'Not stable'
def main():
card_num = int(input())
cards = input().split()
bubble_sorted = bubble_sort(cards, card_num)
select_sorted = select_sort(cards, card_num)
stability = True
for i, c in enumerate(select_sorted):
if c != bubble_sorted[i]:
stability = False
break
stability = STABLE if stability else UNSTABLE
print(bubble_sorted)
print(STABLE)
print(select_sorted)
print(stability)
return 0
def order(card_sym):
return int(card_sym[1])
def select_sort(elements, element_num):
elements = list(elements)
for i in range(0, element_num - 1):
min_val = order(elements[i + 1])
min_index = i + 1
for j in range(i + 1, element_num):
if order(elements[j]) < order(min_val):
min_val = elements[j]
min_index = j
if order(elements[i]) > order(elements[min_index]):
elements[i], elements[min_index] = elements[min_index], elements[i]
return elements
def bubble_sort(elements, element_num):
elements = list(elements)
for i in range(1, element_num):
for j in reversed(range(i, element_num)):
if order(elements[j - 1]) > order(elements[j]):
elements[j - 1], elements[j] = elements[j], elements[j - 1]
return elements
if __name__ == '__main__':
main() |
s080043565 | p02261 | u390995924 | 1472572010 | Python | Python3 | py | Runtime Error | 0 | 0 | 622 | import copy
N = int(input())
bscs = [(int(c[-1]), c) for c in input().split(" ")]
sscs = copy.copy(bscs)
for i in range(N):
j = N - 1
while j > i:
if bscs[j][0] < bscs[j - 1][0]:
tmp = bscs[j]
bscs[j] = bscs[j - 1]
bscs[j - 1] = tmp
j -= 1
print(" ".join([c[1] for c in bscs])
print("Stable")
for i in range(N):
minj = i
for j in range(i, N):
if sscs[j][0] < sscs[minj][0]:
minj = j
tmp = sscs[i]
sscs[i] = sscs[minj]
sscs[minj] = tmp
print(" ".join([c[1] for c in sscs]))
print("Stable" if bscs == sscs else "Not Stable") |
s312461867 | p02261 | u756595712 | 1474855285 | Python | Python3 | py | Runtime Error | 0 | 0 | 603 | length = int(input())
eles = [int(l) for l in input().split()]
is_stable = 'Stable'
import copy
_copy = copy.deepcopy(eles)
for i in range(length):
for j in range(length-1, 0, -1):
if _copy[j][1] < _copy[j-1][1]:
_copy[j], _copy[j-1] = _copy[j-1], _copy[j]
print(*_copy)
print(is_stable)
__copy = copy.deepcopy(eles)
for i in range(length-1):
_min = i
for l in range(i, length):
if __copy[l][1] < __copy[_min][1]:
_min = l
is_stable = 'Not Stable'
__copy[i], __copy[_min] = __copy[_min], __copy[i]
print(*__copy)
print(is_stable) |
s762224099 | p02261 | u918276501 | 1484820510 | Python | Python3 | py | Runtime Error | 0 | 0 | 654 | n = int(input())
lst = input().split()
bub, sel = [lst]*2
sls = []
for i in range(n):
m = i
li = lst[i][0]
if not li in sls:
sls.append(li)
for j in range(n-1,i,-1):
if bub[j] < bub[j-1]:
bub[j-1:j+1] = bub[j], bub[j-1]
for k in range(i, n):
if sel[k][1] < sel[k][1]:
m = k
if m != i:
sel[i], sel[m] = sel[m], sel[i]
def stable(sort):
s = 0
for i in range(1,n):
if sort[i][1] == sort[i-1][1] & sls.index(sort[i][0]) < sls.index(sort[i-1][0]):
s += 1
print('Not stable' if s else 'Stable')
print(*bub)
stable(bub)
print(*sel)
stable(sel) |
s991322285 | p02261 | u935329231 | 1485000990 | Python | Python3 | py | Runtime Error | 0 | 0 | 1428 | # -*- coding: utf-8 -*-
def bubble_sort(cards, num):
for left in range(num-1):
for right in range(left+1, num):
if cards[right][1] < cards[left][1]:
cards[left], cards[right] = cards[right], cards[left]
print(list_to_str(cards))
def selection_sort(cards, num):
for head in range(num):
min_i = head
for target in range(head+1, num):
if cards[target][1] < cards[min_i][1]:
min_i = target
cards[head], cards[min_i] = cards[min_i], cards[head]
print(list_to_str(cards))
def is_stable(before, after, num):
for i in range(num):
for j in range(i+1, num):
for a in range(num):
for b in range(a+1, num):
if before[i][1] == before[j][1]\
and before[i] == after[b]\
and before[j] == after[a]:
return 'Not stable'
return 'Stable'
def list_to_str(l, delimiter=' '):
# The default delimiter is one space.
return delimiter.join([str(v) for v in l])
if __name__ == '__main__':
num = int(input())
cards = input().split()
cards_for_bubble = cards.copy()
cards_for_selection = cards.copy()
bubble_sort(cards_for_bubble, num)
print(is_stable(cards, cards_for_bubble, num))
selection_sort(cards_for_selection, num)
print(is_stable(cards, cards_for_selection, num)) |
s127968561 | p02261 | u895660619 | 1487543006 | Python | Python3 | py | Runtime Error | 0 | 0 | 792 | N = int(input())
C = input().split()
B = C[:]
S = C[:]
# bubble sort
flag = 1
while(flag):
flag = 0
for x in (1, N):
if C[x][1:] < C[x-1][1:]:
C[x], C[x-1] = C[x-1], C[x]
flag = 1
# sectionSot
for x in range(0,N):
minj = x
for j in (x,n):
if S[j][1:] < S[minj][1:]:
minj = j
if minj != x:
S[x], S[j] = S[j], S[x]
for i in range(1, N):
v = C[i]
j = i - 1
while(j >=0 and C[j] > v):
C[j+1] = C[j]
j -= 1
C[j+1] = v
if(C == B):
print(" ".join(b for b in B))
print("Stable")
else:
print(" ".join(b for b in B))
print("Not stable")
if(C == S):
print(" ".join(b for b in S))
print("Stable")
else:
print(" ".join(b for b in S))
print("Not stable") |
s265365504 | p02261 | u148628801 | 1488960279 | Python | Python3 | py | Runtime Error | 0 | 0 | 600 | import sys
def bubble_sort(C, N):
for i in range(N):
for j in range(N - 1, i, -1):
if C[j][1] < C[j - 1][1]:
C[j], C[j - 1] = C[j - 1], C[j]
return C
def selection_sort(C, N):
for i in range(N):
minj = i
for j in range(i, N):
if C[j][1] < C[minj][1]:
minj = j
C[i], C[minj] = C[minj], C[i]
return C
fin = open("test.txt", "r")
#fin = sys.stdin
N = int(fin.readline())
A = fin.readline().split()
B = A[:]
A = bubble_sort(A, N)
B = selection_sort(B, N)
print(" ".join(A))
print("Stable")
print(" ".join(B))
if A == B:
print("Stable")
else:
print("Not stable") |
s699248270 | p02261 | u548155360 | 1489035667 | Python | Python3 | py | Runtime Error | 0 | 0 | 920 | def isStable(inlist, outlist):
for i in range(0, N):
for j in range(i+1, N):
for a in range(0, N):
for b in range(a+1, N):
if int(inlist[i][1:]) == int(inlist[j][1:]) && inlist[i] == outlist[b] && inlist[j] == outlist[a]:
return FALSE
break
else:
return TRUE
N = int(input())
A = input().split()
B = A
C = A
flag = 1
counter = 0
while flag:
flag = 0
for i in reversed(range(1,N)):
if int(C[i][1:]) < int(C[i-1][1:]):
C[i], C[i-1] = C[i-1], C[i]
counter += 1
flag = 1
print(" ".join(map(str, C)))
if(isStable(A, C)):
print("Stable")
else:
print("Not Stable")
counter=0
for i in range(N):
Br = B[i:]
Brr = [int(Br[j][1:]) for j in range(N-i+1)]
num = Brr.index(min(Brr))
if num != 0:
B[i], B[(i+num)] = B[(i+num)], B[i]
counter += 1
print(" ".join(map(str,B)))
if(isStable(A, B)):
print("Stable")
else:
print("Not Stable") |
s753756268 | p02261 | u796784914 | 1492850806 | Python | Python | py | Runtime Error | 10 | 6452 | 1053 | N = input()
A = map(str,raw_input().split())
Ab = A[:]
As = A[:]
def BubbleSort(A,N):
for i in range(N):
flag = 0
for i in range(1,N):
j = N - i
if A[j][1] < A[j-1][1]:
v = A[j]
A[j] = A[j-1]
A[j-1] = v
flag = 1
def SelectionSort(A,N):
for i in range(N):
minj = i
for j in range(i,N):
if A[j][1] < A[minj][1]:
minj = j
v = A[i]
A[i] = A[minj]
A[minj] = v
def Output(A):
for i in range(N-1):
print A[i],
print A[-1]
def Stable(AA):
l = [AA[i] for i in range(N-1) if AA[i][1] == AA[i+1][1]]
for item in l:
for i in range(N-1):
if A[i][1] == item[1]:
if A[i] == item:
msg = "Stable"
break
else:
msg = "Not stable"
break
print msg
SelectionSort(As,N)
BubbleSort(Ab,N)
Output(Ab)
Stable(Ab)
Output(As)
Stable(As) |
s120107374 | p02261 | u782850499 | 1494744784 | Python | Python3 | py | Runtime Error | 0 | 0 | 1117 | def bubble_sort(num_list):
list_b = num_list[:]
for i in range(len(list_b)-1):
for j in range(len(list_b)-1,i,-1):
if list_b[j][1] < list_b[j-1][1]:
list_b[j],list_b[j-1] = list_b[j-1],list_b[j]
return list_b
def selection_sort(num_list):
list_s = num_list[:]
for i in range(len(list_s)):
minj = i
for j in range(i,len(list_s)):
if list_s[minj][1] > list_s[j][1]:
minj = j
list_s[i],list_s[minj] = list_s[minj],list_s[i]
return list_s
def isStable(list_x, list_y):
leng = int(len(list_x))
for i in range(leng-1):
for j in range(i+1, leng):
for x in range(leng-1):
for y in range(x+1, leng):
if list_x[i][1]==list_x[j][1] and list_x[i]==list_y[y] and list_x[j] == list_y[x]:
return "Not stable"
return "Stable"
qnt = int(input())
num_list = input().split()
bs = bubble_sort(num_list)
ss = selection_sort(num_list)
print(" ".join(bs))
print(isStable(num_list,bs))
print(" ".join(ss))
print(isStable(num_list,ss) |
s028960900 | p02261 | u782850499 | 1494744958 | Python | Python3 | py | Runtime Error | 0 | 0 | 1120 | def bubble_sort(num_list):
list_b = num_list[:]
for i in range(len(list_b)-1):
for j in range(len(list_b)-1,i,-1):
if list_b[j][1] < list_b[j-1][1]:
list_b[j],list_b[j-1] = list_b[j-1],list_b[j]
return list_b
def selection_sort(num_list):
list_s = num_list[:]
for i in range(len(list_s)):
minj = i
for j in range(i,len(list_s)):
if list_s[minj][1] > list_s[j][1]:
minj = j
list_s[i],list_s[minj] = list_s[minj],list_s[i]
return list_s
def isStable(list_x, list_y):
leng = int(len(list_x))
for i in range(leng-1):
for j in range(i+1, leng):
for x in range(leng-1):
for y in range(x+1, leng):
if list_x[i][1]==list_x[j][1] and list_x[i]==list_y[y] and list_x[j] == list_y[x]:
return "Not stable"
return "Stable"
qnt = int(input())
num_list = input().split()
bs = bubble_sort(num_list)
ss = selection_sort(num_list)
print(" ".join(bs))
print(isStable(num_list,bs))
print(" ".join(ss))
print(isStable(num_list,ss) |
s790305692 | p02261 | u813534019 | 1497487853 | Python | Python | py | Runtime Error | 0 | 0 | 1459 | def buble(lst):
src_list = list(lst)
flag=True
while flag:
flag = False
for idx in range(len(lst)-1, 0, -1):
if int(lst[idx][1]) < int(lst[idx-1][1]):
flag_stable = True
for num in range(0, 9):
tmp1 = []
tmp2 = []
for i in range(0, len(lst)):
if int(lst[i][1]) == num:
tmp1.append(lst[i])
if int(src_list[i][1]) == num:
tmp2.append(src_list[i])
if tmp1 != tmp2:
flag_stable = False
break
print " ".join(lst)
if flag_stable:
print "Stable"
else:
print "Not stable"
def selection(lst):
src_list = list(lst)
for i in range(len(lst)):
m = i
for j in range(i,len(lst)):
if int(lst[m][1]) > int(lst[j][1]):
m=j
tmp=lst[i]
lst[i]=lst[m]
lst[m]=tmp
flag_stable = True
for num in range(0, 9):
tmp1 = []
tmp2 = []
for i in range(0, len(lst)):
if int(lst[i][1]) == num:
tmp1.append(lst[i])
if int(src_list[i][1]) == num:
tmp2.append(src_list[i])
if tmp1 != tmp2:
flag_stable = False
break
print " ".join(lst)
if flag_stable:
print "stable"
else:
print "not stable"
n=raw_input()
lst1 = raw_input().split()
lst2 = list(lst1)
buble(lst1)
selection(lst2) |
s819986989 | p02261 | u747635679 | 1498536811 | Python | Python3 | py | Runtime Error | 0 | 0 | 559 | n = int(input())
a = input().split()
b = a
for i in range(n):
for j in range(i + 1, n):
if int(a[j - 1][1]) > int(a[j][1]):
tmp = a[j - 1]
a[j - 1] = a[j]
a[j] = tmp
ra = " ".join(a)
print(ra)
print("Stable")
for i in range(n - 1):
minj = i
for j in (i + 1, n):
if int(b[j][1]) < int(b[minj][1]):
minj = j
if minj != i:
tmp = b[i]
b[i] = b[minj]
b[minj] = tmp
rb = " ".join(b)
print(rb)
if ra == rb:
print("Stable")
else:
print("Not Stable") |
s371848031 | p02261 | u760630500 | 1498817156 | Python | Python3 | py | Runtime Error | 0 | 0 | 816 |
def BubbleSort(N, C):
C = [] + C
for i in range(N):
for j in range(N-1, i, -1):
if C[j][1] < C[j-1][1]:
C[j], C[j-1] = C[j-1], C[j]
return C
def SelectionSort(N, C):
C = [] + C
for i in range(N):
minj = i
for j in range(i, N):
if C[minj][1] > C[j][1]:
minj = j
C[i], C[minj] = C[minj], C[i]
return C
def CompareSuit(L1, L2):
suit1, suit2 = "", ""
for i in range(len(L1)):
suit1 = suit1 + L1[i]
suit2 = suit2 + L2[i]
if suit1 == suit2:
return "Stable"
else:
return "Unstable"
N = int(input())
C = input.split()
C1 = BubbleSort(N, C)
C2 = SelectionSort(N, C)
print(" ".join(C1))
print(CompareSuit(C1, C1))
print(" ".join(C2))
print(CompareSuit(C1, C2)) |
s175094731 | p02261 | u760630500 | 1498817220 | Python | Python3 | py | Runtime Error | 0 | 0 | 818 |
def BubbleSort(N, C):
C = [] + C
for i in range(N):
for j in range(N-1, i, -1):
if C[j][1] < C[j-1][1]:
C[j], C[j-1] = C[j-1], C[j]
return C
def SelectionSort(N, C):
C = [] + C
for i in range(N):
minj = i
for j in range(i, N):
if C[minj][1] > C[j][1]:
minj = j
C[i], C[minj] = C[minj], C[i]
return C
def CompareSuit(L1, L2):
suit1, suit2 = "", ""
for i in range(len(L1)):
suit1 = suit1 + L1[i]
suit2 = suit2 + L2[i]
if suit1 == suit2:
return "Stable"
else:
return "Not stable"
N = int(input())
C = input.split()
C1 = BubbleSort(N, C)
C2 = SelectionSort(N, C)
print(" ".join(C1))
print(CompareSuit(C1, C1))
print(" ".join(C2))
print(CompareSuit(C1, C2)) |
s972306423 | p02261 | u735204496 | 1498980536 | Python | Python | py | Runtime Error | 0 | 0 | 1274 | import sys
class Card:
def __init__(self, num, kind):
self.kind = kind
self.num = num
def list_to_string(array):
s = ""
for n in array:
s += str(n) + " "
return s.strip()
def swap(array, i, j):
tmp = array[i]
array[i] = array[j]
array[j] = tmp
def is_stable(array1, array2):
if reduce(lambda x, y: x and y, map(lambda x: x[0] == x[1], zip(array1, array2))):
return "Stable"
else:
return "Not stable"
def bubble_sort(array):
for i in range(0, len(array)):
for j in reversed(range(i+1, len(array))):
if array[j].num < array[j-1].num:
swap(array, j, j-1)
def selection_sort(array):
for i in range(0, len(array)):
min_index = i
for j in range(i, len(array)):
if array[min_index] > array[j]:
min_index = j
swap(array, i, min_index)
def main():
num = int(sys.stdin.readline().strip())
array = map(lambda x: int(x), sys.stdin.readline().strip().split(" "))
a = list(array)
b = list(array)
print list_to_string(bubble_sort(a))
print is_stable(a, array)
print list_to_string(selection_sort(b))
print is_stable(b, array)
if __name__ == "__main__":
main() |
s462779938 | p02261 | u735204496 | 1498980720 | Python | Python | py | Runtime Error | 0 | 0 | 1503 | import sys
class Card:
def __init__(self, kind, num):
self.kind = kind
self.num = num
def __eq__(self, other):
return (self.kind == other.kind) and (self.num == other.num)
def __ne__(self, other):
return not ((self.kind == other.kind) and (self.num == other.num))
def list_to_string(array):
s = ""
for n in array:
s += str(n) + " "
return s.strip()
def swap(array, i, j):
tmp = array[i]
array[i] = array[j]
array[j] = tmp
def is_stable(array1, array2):
if reduce(lambda x, y: x and y, map(lambda x: x[0] == x[1], zip(array1, array2))):
return "Stable"
else:
return "Not stable"
def bubble_sort(array):
for i in range(0, len(array)):
for j in reversed(range(i+1, len(array))):
if array[j].num < array[j-1].num:
swap(array, j, j-1)
def selection_sort(array):
for i in range(0, len(array)):
min_index = i
for j in range(i, len(array)):
if array[min_index].num > array[j].num:
min_index = j
swap(array, i, min_index)
def main():
num = int(sys.stdin.readline().strip())
array = map(lambda x: Card(x[0], x[1]), sys.stdin.readline().strip().split(" "))
a = list(array)
b = list(array)
print list_to_string(bubble_sort(a))
print is_stable(a, array)
print list_to_string(selection_sort(b))
print is_stable(b, array)
if __name__ == "__main__":
main() |
s865290910 | p02261 | u914146430 | 1500715883 | Python | Python3 | py | Runtime Error | 0 | 0 | 719 | # bable sort
def bubbleSort(o_nums, n):
nums=o_nums[:]
for i in range(len(nums)-1):
for j in range(len(nums)-1,i,-1):
if nums[j][1]<nums[j-1][1]:
nums[j],nums[j-1]=nums[j-1],nums[j]
return nums
# bable sort
def bubbleSort(o_nums, n):
nums=o_nums[:]
for i in range(len(nums)-1):
for j in range(len(nums)-1,i,-1):
if nums[j][1]<nums[j-1][1]:
nums[j],nums[j-1]=nums[j-1],nums[j]
return nums
n=int(input())
cards=list(input().split())
b=bubbleSort(cards, n)
s=selectionSort(cards,n)
print(*b)
print("Stable")
print(*s)
if bubbleSort(cards, n) == selectionSort(cards, n):
print("Stable")
else:
print("Not stable") |
s183721804 | p02261 | u914146430 | 1500716005 | Python | Python3 | py | Runtime Error | 0 | 0 | 719 | # bable sort
def bubbleSort(o_nums, n):
nums=o_nums[:]
for i in range(len(nums)-1):
for j in range(len(nums)-1,i,-1):
if nums[j][1]<nums[j-1][1]:
nums[j],nums[j-1]=nums[j-1],nums[j]
return nums
# bable sort
def bubbleSort(o_nums, n):
nums=o_nums[:]
for i in range(len(nums)-1):
for j in range(len(nums)-1,i,-1):
if nums[j][1]<nums[j-1][1]:
nums[j],nums[j-1]=nums[j-1],nums[j]
return nums
n=int(input())
cards=list(input().split())
b=bubbleSort(cards, n)
s=selectionSort(cards,n)
print(*b)
print("Stable")
print(*s)
if bubbleSort(cards, n) == selectionSort(cards, n):
print("Stable")
else:
print("Not stable") |
s472088074 | p02261 | u914146430 | 1500716513 | Python | Python3 | py | Runtime Error | 0 | 0 | 711 | def bubbleSort(o_nums, n):
nums=o_nums[:]
for i in range(len(nums)-1):
for j in range(len(nums)-1,i,-1):
if nums[j][1]<nums[j-1][1]:
nums[j],nums[j-1]=nums[j-1],nums[j]
return nums
def bubbleSort(o_nums, n):
nums=o_nums[:]
for i in range(len(nums)-1):
for j in range(len(nums)-1,i,-1):
if nums[j][1]<nums[j-1][1]:
nums[j],nums[j-1]=nums[j-1],nums[j]
return nums
n=int(input())
cards=list(input().split())
b=bubbleSort(cards, n)
s=selectionSort(cards,n)
print(" ".join(b))
print("Stable")
print(" ".join(s))
if bubbleSort(cards, n) == selectionSort(cards, n):
print("Stable")
else:
print("Not stable") |
s456642745 | p02261 | u153665391 | 1504878673 | Python | Python3 | py | Runtime Error | 0 | 0 | 1157 | n = int(input())
a = list(input().split())
A = []
A1 = []
A2 = []
for i in a:
A.append(list(i))
A1.append(list(i))
A2.append(list(i))
# check stable or not
def is_stable(A3):
for i in range( 1, n ):
if int(A3[i-1][1]) == int(A3[i][1]):
sm = i-1
bg = i
for j in range( n ):
if ( A[j][0] == A3[sm][0]) & ( A[j][1] == A3[sm][1]):
t1 = j
if ( A[j][0] == A3[bg][0]) & ( A[j][1] == A3[bg][1]):
t2 = j
print(t1)
print(t2)
if t1 > t2:
return "Not stable"
return "Stable"
# bubble
for i in range( n ):
for j in range( n-1, i, -1 ):
if int(A1[j][1]) < int(A1[j-1][1]):
t = A1[j-1]
A1[j-1] = A1[j]
A1[j] = t
s = is_stable(A1)
print(" ".join(A1))
print(s)
# selection
for i in range( n ):
minj = i
for j in range( i+1, n ):
if int(A2[j][1]) < int(A2[minj][1]):
minj = j
if minj != i:
t = A2[i]
A2[i] = A2[minj]
A2[minj] = t
s = is_stable(A2)
print(" ".join(A2))
print(s) |
s270222431 | p02261 | u024715419 | 1507276252 | Python | Python3 | py | Runtime Error | 0 | 0 | 463 | n = int(input())
a = input().split()
b = a[:]
while flag:
flag = 0
for i in range(n-1):
if a[i][1] > a[i+1][1]:
a[i][1], a[i+1][1] = a[i+1][1], a[i][1]
flag = 1
print(*a)
print("Stable")
for i in range(n-1):
min_j = i
for j in range(i,n):
if b[j][1] < b[min_j][1]:
min_j = j
b[i][1], b[min_j][1] = b[min_j][1], b[i][1]
print(*b)
if a == b:
print("Stable")
else:
print("Not stable") |
s890607117 | p02261 | u024715419 | 1507276328 | Python | Python3 | py | Runtime Error | 0 | 0 | 463 | n = int(input())
a = input().split()
b = a[:]
while flag:
flag = 0
for i in range(n-1):
if a[i][1] > a[i+1][1]:
a[i][1], a[i+1][1] = a[i+1][1], a[i][1]
flag = 1
print(*a)
print("Stable")
for i in range(n-1):
min_j = i
for j in range(i,n):
if b[j][1] < b[min_j][1]:
min_j = j
b[i][1], b[min_j][1] = b[min_j][1], b[i][1]
print(*b)
if a == b:
print("Stable")
else:
print("Not stable") |
s852320074 | p02261 | u626266743 | 1510058822 | Python | Python3 | py | Runtime Error | 0 | 0 | 441 | N = int(input())
C = input().split()
_C = C.copy()
for i in range(N):
for j in range(N-1, i, -1):
if (C[j][1] < C[j-1][1]):
C[j][1], C[j-1][1] = C[j-1][1], C[j][1]
print(*C)
print("Stable")
for j in range(N):
m = i
for j in range(i, N):
if (_C[j][1] < _C[j-1][1]):
m = j
_C[i][1], _C[m][1] = _C[m][1], _C[i][1]
print(*_C)
if(C ==_C):
print("Stable")
else:
print("Not stable") |
s711796543 | p02261 | u150984829 | 1516473360 | Python | Python3 | py | Runtime Error | 0 | 0 | 278 | n=int(input())
c=input().split();d=c[:]
for i in range(n-1):
for j in range(0,n-i-1):
if c[j][1]>c[j+1][1]:c[j],c[j+1]=c[j+1],c[j]
m=i
for j in range(i,n):
if b[m][1]>b[j][1]:m=j
d[i],d[m]=d[m],d[i]
print(*c);print("Stable")
print(*d)
print(['Not s','S'][b==s]+'table')
|
s503962094 | p02261 | u150984829 | 1516473393 | Python | Python3 | py | Runtime Error | 0 | 0 | 278 | n=int(input())
c=input().split();d=c[:]
for i in range(n-1):
for j in range(0,n-i-1):
if c[j][1]>c[j+1][1]:c[j],c[j+1]=c[j+1],c[j]
m=i
for j in range(i,n):
if d[m][1]>d[j][1]:m=j
d[i],d[m]=d[m],d[i]
print(*c);print("Stable")
print(*d)
print(['Not s','S'][b==s]+'table')
|
s039214989 | p02261 | u996463517 | 1518224244 | Python | Python3 | py | Runtime Error | 0 | 0 | 614 | a = int(input())
B = input().split()
print(bubble(a,B))
print("Stable")
print(selection(a,B))
if bubble(a,B) == selection(a,B):
print("Stable")
else:
print("Not stable")
def selection(n,A):
for i in range(n):
minj = i
for j in range(i,n):
if int(A[j][1]) < int(A[minj][1]):
minj = j
A[i],A[minj] = A[minj],A[i]
return " ".join(A)
def bubble(n,A):
for i in range(n):
for j in range(n-1,i,-1):
if int(A[j][1]) < int(A[j-1][1]):
A[j],A[j-1] = A[j-1],A[j]
return " ".join(A)
|
s233816414 | p02261 | u933096856 | 1518590426 | Python | Python3 | py | Runtime Error | 0 | 0 | 469 | n=int(input())
l=input().split()
def BubbleSort(c):
for i in range(len(c)-1):
for j in range(len(c)-1, i, -1):
if int(c[j][-1]) < int(c[j-1][-1]):
c[j], c[j-1]=c[j-1],c[j]
return c
def SelectionSort(C):
for i in range(len(c)-1):
m=i
for j in range(i, len(c)-1):
if int(c[j][-1]) < int(c[m][-1]):
c[j], c[m]=c[m],c[j]
return c
print(BubbleSort(l))
print(SelectionSort(l)
|
s815504800 | p02261 | u933096856 | 1518590451 | Python | Python3 | py | Runtime Error | 0 | 0 | 470 | n=int(input())
l=input().split()
def BubbleSort(c):
for i in range(len(c)-1):
for j in range(len(c)-1, i, -1):
if int(c[j][-1]) < int(c[j-1][-1]):
c[j], c[j-1]=c[j-1],c[j]
return c
def SelectionSort(C):
for i in range(len(c)-1):
m=i
for j in range(i, len(c)-1):
if int(c[j][-1]) < int(c[m][-1]):
c[j], c[m]=c[m],c[j]
return c
print(BubbleSort(l))
print(SelectionSort(l))
|
s369259326 | p02261 | u933096856 | 1518607376 | Python | Python | py | Runtime Error | 0 | 0 | 575 | n=raw_int(input())
r=raw_input().split()
def BubbleSort(c, n):
for i in range(n):
for j in range(n-1, i, -1):
if int(c[j][-1]) < int(c[j-1][-1]):
c[j], c[j-1]=c[j-1],c[j]
return c
def SelectionSort(c, n):
for i in range(n):
m=i
for j in range(i, n):
if int(c[j][-1]) < int(c[m][-1]):
m=j
c[i],c[m]=c[m],c[i]
return c
l=list(r)
a=BubbleSort(l, n)
print *a
print 'Stable'
l=list(r)
b=SelectionSort(l, n)
print *b
if a==b:
print 'Stable'
else:
print 'Not stable'
|
s575552612 | p02261 | u933096856 | 1518607395 | Python | Python | py | Runtime Error | 0 | 0 | 575 | n=int(raw_input())
r=raw_input().split()
def BubbleSort(c, n):
for i in range(n):
for j in range(n-1, i, -1):
if int(c[j][-1]) < int(c[j-1][-1]):
c[j], c[j-1]=c[j-1],c[j]
return c
def SelectionSort(c, n):
for i in range(n):
m=i
for j in range(i, n):
if int(c[j][-1]) < int(c[m][-1]):
m=j
c[i],c[m]=c[m],c[i]
return c
l=list(r)
a=BubbleSort(l, n)
print *a
print 'Stable'
l=list(r)
b=SelectionSort(l, n)
print *b
if a==b:
print 'Stable'
else:
print 'Not stable'
|
s782099167 | p02261 | u906360845 | 1520702778 | Python | Python3 | py | Runtime Error | 0 | 0 | 724 | n = input()
nums = input()
nums = nums.split()
print(' '.join(map(str, nums)))
def bubble_sort(c, n):
for i in range(n-1):
for j in range(n-1):
if c[j] > c[j+1]:
c[j], c[j+1] = c[j+1], c[j]
return c
def selection_sort(c, n):
for i in range((n):
mink = i
for v in range(i, n):
if c[v] <c[mink]:
mink = v
if mink != i:
c[i], c[mink] = c[mink], c[i]
return c
def is_stable(bs, ss):
if bs == ss:
return 'Stable'
else:
return 'Not stable'
bs = bubble_sort(nums, int(n))
print(' '.join(bs))
print('Stable')
ss = selection_sort(nums, int(n))
print(' '.join(ss))
print(is_stable(bs, ss))
|
s292603628 | p02261 | u613534067 | 1521354725 | Python | Python3 | py | Runtime Error | 0 | 0 | 1319 | # Quick Sort #
# 安定かどうかの判定の計算量を減らすことができなかったので,悪いことをした...
def partition(A, p, r):
x = A[r][1]
i = p-1
for k in range(p, r):
if A[k][1] <= x:
i += 1
A[i], A[k] = A[k], A[i]
A[i+1], A[r] = A[r], A[i+1]
return i+1
def quick_sort(A, p, r):
if p < r:
q = partition(A, p, r)
quick_sort(A, p, q-1)
quick_sort(A, q+1, r)
def bubble_sort(c, n):
x = c[:]
for i in range(n):
for k in range(n-1, i, -1):
if x[k][1] < x[k-1][1]:
x[k], x[k-1] = x[k-1], x[k]
return x
def is_stable(_in, out):
n = len(_in)
for i in range(n):
for k in range(i+1, n):
for a in range(n):
for b in range(a+1, n):
if _in[i][1] == _in[k][1] and _in[i] == out[b] and _in[k] == out[a]:
return False
return True
n = int(input())
a = []
for i in range(n):
mrk, num = input().split()
num = int(num)
a.append((mrk, num))
b = a[:]
quick_sort(b, 0, n-1)
if n > 10000:
print("Not stable")
else:
# BubbleSortは常に安定
c = bubble_sort(a[:], n)
if b == c:
print("Stable")
else:
print("Not stable")
for i in b:
print(*i)
|
s845960800 | p02261 | u464859367 | 1522463985 | Python | Python3 | py | Runtime Error | 0 | 0 | 1292 | import re
import copy
pattern = r'([0-9])'
repatter = re.compile(pattern)
n = str(input())
text = input()
*lists, = text.split(" ")
lists2 = copy.copy(lists)
lists3 = copy.copy(lists)
# バブルソート
def bubble_sort(a):
flag = 1
i = 0
while flag:
flag = 0
for j in range(n-1, i, -1):
x = repatter.findall(a[j])
y = repatter.findall(a[j-1])
if x < y:
a[j], a[j-1] = a[j-1], a[j]
flag = 1
i += 1
print(*a)
print("Stable")
# 選択ソート
def select_sort(a):
for i in range(n):
min_j = i
for j in range(i+1, n):
x = repatter.findall(a[j])
y = repatter.findall(a[min_j])
if x < y:
min_j = j
a[i], a[min_j] = a[min_j], a[i]
print(*a)
def isStable(before, after):
for i in range(n):
for j in range(i+1, n):
for a in range(n):
for b in range(a+1, n):
x = repatter.findall(before[i])
y = repatter.findall(before[j])
if x == y and before[i] == after[b] and before[j] == after[a]:
print("Not stable")
bubble_sort(lists)
select_sort(lists2)
isStable(lists3, lists2)
|
s499628205 | p02261 | u308033440 | 1526012545 | Python | Python3 | py | Runtime Error | 0 | 0 | 1606 | # #バブルソート
# def BubbleSort(C,N):
# for i in range (0,N,1):
# for j in range(N-1,i-1,-1):
# if int(C[j][1:2]) < int(C[j-1][1:2]):
# tmp = C[j]
# C[j] = C[j-1]
# C[j-1] = tmp
# print(' '.join(C))
#バブルソート
def BubbleSort(C,N):
flag = 1
while flag:
flag = 0
for j in range(N-1,0,-1):
if int(C[j][1:2]) < int(C[j-1][1:2]):
tmp = C[j]
C[j] = C[j-1]
C[j-1] = tmp
flag = 1
print(' '.join(C))
#選択ソート
def SelectionSort(C,N):
for i in range(0,N,1):
minj = i
for j in range(i,N,1):
if int(C[j][1:2]) < int(C[minj][1:2]):
minj = j
tmp = C[i]
C[i] = C[minj]
C[minj] = tmp
print(' '.join(C))
#安定かどうかの判定
def isStable(inp, out,N):
for i in range(0,N):
for j in range(i+1,N):
for a in range(0,N):
for b in range(a+1,N):
# print("inp(i,j):",inp[i],inp[j],"out(b,a):",out[b],out[a]+"\n")
if int(inp[i][1]) == int(inp[j][1]) and inp[i] == out[b] and inp[j] == out[a]:
print('Not stable')
return
print('Stable')
愚直に調べるパターン
N = int(input())
A = list(input().split())
Bubble_A = A.copy()
Selection_A = A.copy()
BubbleSort(Bubble_A,N)
isStable(A,Bubble_A,N)
SelectionSort(Selection_A,N)
isStable(A,Selection_A,N)
|
s345785444 | p02261 | u308033440 | 1526012576 | Python | Python3 | py | Runtime Error | 0 | 0 | 1323 | #バブルソート
def BubbleSort(C,N):
flag = 1
while flag:
flag = 0
for j in range(N-1,0,-1):
if int(C[j][1:2]) < int(C[j-1][1:2]):
tmp = C[j]
C[j] = C[j-1]
C[j-1] = tmp
flag = 1
print(' '.join(C))
#選択ソート
def SelectionSort(C,N):
for i in range(0,N,1):
minj = i
for j in range(i,N,1):
if int(C[j][1:2]) < int(C[minj][1:2]):
minj = j
tmp = C[i]
C[i] = C[minj]
C[minj] = tmp
print(' '.join(C))
#安定かどうかの判定
def isStable(inp, out,N):
for i in range(0,N):
for j in range(i+1,N):
for a in range(0,N):
for b in range(a+1,N):
# print("inp(i,j):",inp[i],inp[j],"out(b,a):",out[b],out[a]+"\n")
if int(inp[i][1]) == int(inp[j][1]) and inp[i] == out[b] and inp[j] == out[a]:
print('Not stable')
return
print('Stable')
愚直に調べるパターン
N = int(input())
A = list(input().split())
Bubble_A = A.copy()
Selection_A = A.copy()
BubbleSort(Bubble_A,N)
isStable(A,Bubble_A,N)
SelectionSort(Selection_A,N)
isStable(A,Selection_A,N)
|
s857219389 | p02261 | u356729014 | 1528433430 | Python | Python3 | py | Runtime Error | 0 | 0 | 1731 | package main
import (
"bufio"
"fmt"
"os"
"strconv"
"reflect"
)
var sc = bufio.NewScanner(os.Stdin)
var wtr = bufio.NewWriter(os.Stdout)
func nextInt() int {
sc.Scan()
i, e := strconv.Atoi(sc.Text())
if e != nil {
panic(e)
}
return i
}
type Card struct {
mark string
number int
}
func nextCard() Card {
sc.Scan()
text := sc.Text()
mark := text[0:1]
number, e := strconv.Atoi(text[1:])
if e != nil {
panic(e)
}
return Card{mark, number}
}
func main() {
sc.Split(bufio.ScanWords)
var n int = nextInt()
var A []Card
for i := 0; i < n; i++ {
A = append(A, nextCard())
}
bubble_A := make([]Card, n)
copy(bubble_A, A)
var flag = true
for flag {
flag = false
for i := n - 1; i >= 1; i-- {
if bubble_A[i].number < bubble_A[i-1].number {
bubble_A[i], bubble_A[i-1] = bubble_A[i-1], bubble_A[i]
flag = true
}
}
}
//fprintCardArray(A)
for i := 0; i < n; i++ {
var minj = i
for j := i; j < n; j++ {
if A[j].number < A[minj].number {
minj = j
}
}
if A[i].number != A[minj].number {
A[i], A[minj] = A[minj], A[i]
}
}
fprintCardArray(A)
fmt.Fprintln(wtr,"Stable")
fprintCardArray(bubble_A)
if reflect.DeepEqual(A,bubble_A){
fmt.Fprintln(wtr,"Stable")
}else {
fmt.Fprintln(wtr,"Not stable")
}
_ = wtr.Flush()
}
func fprintIntArray(arr []int) {
for i := 0; i < len(arr); i++ {
if i == 0 {
fmt.Fprintf(wtr, "%d", arr[i])
} else {
fmt.Fprintf(wtr, " %d", arr[i])
}
}
fmt.Fprintln(wtr)
}
func fprintCardArray(arr []Card) {
for i := 0; i < len(arr); i++ {
if i == 0 {
fmt.Fprintf(wtr, "%s%d", arr[i].mark, arr[i].number)
} else {
fmt.Fprintf(wtr, " %s%d", arr[i].mark, arr[i].number)
}
}
fmt.Fprintln(wtr)
}
|
s754432796 | p02261 | u298224238 | 1529386472 | Python | Python3 | py | Runtime Error | 0 | 0 | 1564 | class Card:
def __init__(self, mark, value):
self.mark = mark
self.value = value
def __eq__(self, other):
if not isinstance(other, Card):
return NotImplemented
return self.value == other.value and self.mark == other.mark
def __lt__(self, other):
return self.value < other.value
def __str__(self):
return self.mark + str(self.value)
def BubbleSort(arr):
res = [Card(c.mark, c.value) for c in arr]
swap_flg = True
i = 0
while swap_flg:
swap_flg = False
for j in range(len(res) - 1, i, -1):
if (res[j] < res[j - 1]):
res[j], res[j - 1] = res[j - 1], res[j]
swap_flg = True
i += 1
return res
def SelectionSort(arr):
res = [Card(c.mark, c.value) for c in arr]
for i in range(0, len(res)):
minj = i
for j in range(i, N):
if res[j] < res[minj]:
minj = j
if (i != minj):
res[i], res[minj] = res[minj], res[i]
return res
def isStable(in_arr, out_arr):
stable_arr = BubbleSort(in_arr)
return all(out_arr[i] == stable_arr[i] for i in range(0, len(out_arr)))
def printJudgeStable(in_arr, out_arr):
print('Stable' if isStable(in_arr, out_arr) else 'Not stable')
N = int(input())
arr = [Card(s[0], int(s[1])) for s in input().split()]
b_arr = BubbleSort(arr)
print(' '.join(map(str, b_arr)))
printJudgeStable(arr, b_arr):
s_arr = SelectionSort(arr)
print(' '.join(map(str, s_arr)))
printJudgeStable(arr, s_arr):
|
s391848830 | p02261 | u298224238 | 1529386506 | Python | Python3 | py | Runtime Error | 0 | 0 | 1575 | class Card:
def __init__(self, mark, value):
self.mark = mark
self.value = value
def __eq__(self, other):
if not isinstance(other, Card):
return NotImplemented
return self.value == other.value and self.mark == other.mark
def __lt__(self, other):
return self.value < other.value
def __str__(self):
return self.mark + str(self.value)
def BubbleSort(arr):
res = [Card(c.mark, c.value) for c in arr]
swap_flg = True
i = 0
while swap_flg:
swap_flg = False
for j in range(len(res) - 1, i, -1):
if (res[j] < res[j - 1]):
res[j], res[j - 1] = res[j - 1], res[j]
swap_flg = True
i += 1
return res
def SelectionSort(arr):
res = [Card(c.mark, c.value) for c in arr]
for i in range(0, len(res)):
minj = i
for j in range(i, N):
if res[j] < res[minj]:
minj = j
if (i != minj):
res[i], res[minj] = res[minj], res[i]
return res
def isStable(in_arr, out_arr):
stable_arr = BubbleSort(in_arr)
return all(out_arr[i] == stable_arr[i] for i in range(0, len(out_arr)))
def printJudgeStable(in_arr, out_arr):
print('Stable' if isStable(in_arr, out_arr) else 'Not stable')
return
N = int(input())
arr = [Card(s[0], int(s[1])) for s in input().split()]
b_arr = BubbleSort(arr)
print(' '.join(map(str, b_arr)))
printJudgeStable(arr, b_arr):
s_arr = SelectionSort(arr)
print(' '.join(map(str, s_arr)))
printJudgeStable(arr, s_arr):
|
s812307435 | p02261 | u677291728 | 1530604483 | Python | Python3 | py | Runtime Error | 0 | 0 | 1040 | def bubble(A):
flag = True
n = len(A)
i = 0
while flag:
flag = False
for j in range(n-1,i,-1):
if A[j][1] < A[j-1][1]:
A[j],A[j-1] = A[j-1],A[j]
flag = True
i += 1
def selection(A):
n = len(A)
for i in range(n):
minj = i
for j in range(i,n):
if A[j][1] < A[minj][1]:
minj = j
if i != minj:
A[i],A[minj] = A[minj],A[i]
n = int(input())
ss = [x for x in input().split()]
ss2 = ss.copy()
bubble(ss)
for i in range(len(ss)-1):
print(ss[i], end=' ')
print(ss[-1])
print('Stable')
selection(ss2)
for i in range(len(ss2)-1):
print(ss2[i], end=' ')
print(ss2[-1])
if ss == ss2:
print('Stable')
else:
print('Not stable')
|
s027463483 | p02261 | u677291728 | 1530604582 | Python | Python3 | py | Runtime Error | 0 | 0 | 1033 | def bubble(A):
flag = True
n = len(A)
i = 0
while flag:
flag = False
for j in range(n-1,i,-1):
if A[j][1] < A[j-1][1]:
A[j],A[j-1] = A[j-1],A[j]
flag = True
i += 1
def selection(A):
n = len(A)
for i in range(n):
minj = i
for j in range(i,n):
if A[j][1] < A[minj][1]:
minj = j
if i != minj:
A[i],A[minj] = A[minj],A[i]
n = int(input())
ss = list(map(int,input().split()))
ss2 = ss.copy()
bubble(ss)
for i in range(len(ss)-1):
print(ss[i], end=' ')
print(ss[-1])
print('Stable')
selection(ss2)
for i in range(len(ss2)-1):
print(ss2[i], end=' ')
print(ss2[-1])
if ss == ss2:
print('Stable')
else:
print('Not stable')
|
s113504799 | p02261 | u677291728 | 1530604699 | Python | Python3 | py | Runtime Error | 0 | 0 | 1033 | def bubble(A):
flag = True
n = len(A)
i = 0
while flag:
flag = False
for j in range(n-1,i,-1):
if A[j][1] < A[j-1][1]:
A[j],A[j-1] = A[j-1],A[j]
flag = True
i += 1
def selection(A):
n = len(A)
for i in range(n):
minj = i
for j in range(i,n):
if A[j][1] < A[minj][1]:
minj = j
if i != minj:
A[i],A[minj] = A[minj],A[i]
n = int(input())
ss = list(map(int,input().split()))
ss2 = ss.copy()
bubble(ss)
for i in range(len(ss)-1):
print(ss[i], end=' ')
print(ss[-1])
print('Stable')
selection(ss2)
for i in range(len(ss2)-1):
print(ss2[i], end=' ')
print(ss2[-1])
if ss == ss2:
print('Stable')
else:
print('Not stable')
|
s842847978 | p02261 | u922633376 | 1530671432 | Python | Python3 | py | Runtime Error | 0 | 0 | 5106 | Last login: Thu Jun 28 18:57:04 on ttys001
fujitaryuuki-no-MacBook-Pro:~ fujitaryuki$ ls
Applications
Applications (Parallels)
Desktop
Documents
Downloads
KUT Master
Library
Logicool ゲームソフトウェア 8.82.lnk
Movies
Music
Pictures
Public
PythonStudy
Windows 10
eclipse
matsuzaki-lab
tenhou
wget
就活
fujitaryuuki-no-MacBook-Pro:~ fujitaryuki$ cd matsuzaki-lab/
fujitaryuuki-no-MacBook-Pro:matsuzaki-lab fujitaryuki$ ls
2048player
ACG2017へ投稿した論文,プログラム
AOJ
IFST
IFST.pptx
ISFT 原稿.docx
ISFT2017_fujita.doc
ISFTslides.pptx
ISFT論文 最終版 (Was_ Re_ データ再送)
ISFT論文 最終版 (Was_ Re_ データ再送).zip
Kiyou
Mahjong
N-Bakuuchi.pptx
README.md
Report
Study
TA.pdf
TCB.png
TCB.xlsx
TCB8staging.xlsx
TDFver2
cppStudy
figure1.pptx
seminar
special-1rep.docx
src
supervised_2048
vdw.pdf
写真(2015-09-17 19.19) 12-48-45-461.jpg
スクリーンショット 2017-10-20 12.13.11.png
スクリーンショット 2017-10-20 12.14.36.png
スクリーンショット 2017-10-20 4.11.06.png
スクリーンショット 2017-10-20 4.11.25.png
スクリーンショット 2017-10-24 18.22.45.png
スクリーンショット 2017-10-24 18.32.46.png
スクリーンショット 2018-01-30 0.52.09.png
スクリーンショット 2018-04-21 17.10.48.png
スクリーンショット 2018-04-22 21.45.32.png
スクリーンショット 2018-04-23 10.03.54.png
スクリーンショット 2018-04-23 10.12.21.png
スクリーンショット 2018-04-23 10.16.25.png
スクリーンショット 2018-04-23 18.07.52.png
スクリーンショット 2018-04-23 8.33.58.png
スクリーンショット 2018-04-23 9.02.26.png
スクリーンショット 2018-04-23 9.12.48.png
スクリーンショット 2018-04-23 9.15.41.png
スクリーンショット 2018-04-23 9.16.00.png
スクリーンショット 2018-04-23 9.26.32.png
スクリーンショット 2018-04-23 9.43.01.png
スクリーンショット 2018-04-23 9.43.30.png
スクリーンショット 2018-04-23 9.43.40.png
スクリーンショット 2018-04-23 9.52.31.png
スクリーンショット 2018-04-25 11.30.40.png
fujitaryuuki-no-MacBook-Pro:matsuzaki-lab fujitaryuki$ cd A
ACG2017へ投稿した論文,プログラム/ AOJ/
fujitaryuuki-no-MacBook-Pro:matsuzaki-lab fujitaryuki$ cd A
ACG2017へ投稿した論文,プログラム/ AOJ/
fujitaryuuki-no-MacBook-Pro:matsuzaki-lab fujitaryuki$ cd AOJ/
fujitaryuuki-no-MacBook-Pro:AOJ fujitaryuki$ ls
#copy.java# copy.java
DPfibonacci.class copy.java~
DPfibonacci.java copylcs.class
DPfibonacci.java~ copylcs.java
ExhaustiveSearch.class copylcs.java~
ExhaustiveSearch.java dpLcs.class
ExhaustiveSearch.java~ dpLcs.java
LCS.class dpLcs.java~
LCS.java dpLcsv2.java
LCS.java~ dpLcsv2.java~
Main.class fibonacci.class
RepeatedSubsequences.class fibonacci.java
RepeatedSubsequences.java fibonacci.java~
RepeatedSubsequences.java~ recursiveLcs.class
Xcubic.java recursiveLcs.java
Xcubic.java~ recursiveLcs.java~
copy.class recursivelca.java
fujitaryuuki-no-MacBook-Pro:AOJ fujitaryuki$ touch ALDS1_1_D.py
fujitaryuuki-no-MacBook-Pro:AOJ fujitaryuki$ emacs ALDS1_1_D.py
[1]+ Stopped emacs ALDS1_1_D.py
fujitaryuuki-no-MacBook-Pro:AOJ fujitaryuki$ touch ALDS1_2_C.py
fujitaryuuki-no-MacBook-Pro:AOJ fujitaryuki$ emacs ALDS1_
fujitaryuuki-no-MacBook-Pro:AOJ fujitaryuki$ emacs ALDS1_2_C.py
fujitaryuuki-no-MacBook-Pro:AOJ fujitaryuki$ python3 ALDS1_2_C.py
5
H4 C9 S4 D2 C3
D2 C3 H4 S4 C9
Stable
D2 C3 S4 H4 C9
Not stable
fujitaryuuki-no-MacBook-Pro:AOJ fujitaryuki$ emacs ALDS1_2_C.py
[2]+ Stopped emacs ALDS1_2_C.py
fujitaryuuki-no-MacBook-Pro:AOJ fujitaryuki$ python3 ALDS1_2_C.py
5
H4 C9 S4 D2 C35
['H4', 'C9', 'S4', 'D2', 'C3']
['H4', 'C9', 'S4', 'D2', 'C3']
D2 C3 H4 S4 C9
Stable
D2 C3 S4 H4 C9
Not stable
fujitaryuuki-no-MacBook-Pro:AOJ fujitaryuki$ fg
emacs ALDS1_2_C.py
[2]+ Stopped emacs ALDS1_2_C.py
fujitaryuuki-no-MacBook-Pro:AOJ fujitaryuki$ python3 ALDS1_2_C.py
5
H4 C9 S4 D2 C35
['H4', 'C9', 'S4', 'D2', 'C3']
['H4', 'C9', 'S4', 'D2', 'C3']
D2 C3 H4 S4 C9
Stable
D2 C3 S4 H4 C9
Not stable
fujitaryuuki-no-MacBook-Pro:AOJ fujitaryuki$ fg
emacs ALDS1_2_C.py
[2]+ Stopped emacs ALDS1_2_C.py
fujitaryuuki-no-MacBook-Pro:AOJ fujitaryuki$ fg
emacs ALDS1_2_C.py
input_line = int(input())
out_bubble = input().split()
out_selection = out_bubble[:]
# bubblesort
for i in range(n):
for j in range(n-1, i, -1):
if out_bubble[j][1] < out_bubble[j-1][1]:
out_bubble[j], out_bubble[j-1] = out_bubble[j-1],out_bubble[j]
print(*out_bubble)
print("Stable")
# selectionsort
for i in range(n):
minj = i
for j in range(i, n):
if out_selection[j][1] < out_selection[minj][1]:
minj = j
out_selection[i], out_selection[minj] = out_selection[minj], out_selection[i]
print(*out_selection)
print("Stable" if out_b == out_selection else "Not stable")
|
s464855727 | p02261 | u922633376 | 1530671560 | Python | Python3 | py | Runtime Error | 0 | 0 | 795 | input_line = int(input())
out_selection = input().split()
out_bubble = out_bubble[:]
# bubblesort
for i in range(n):
for j in range(n-1, i, -1):
if out_bubble[j][1] < out_bubble[j-1][1]:
out_bubble[j], out_bubble[j-1] = out_bubble[j-1],out_bubble[j]
print(*out_bubble)
print("Stable")
# selectionsort
for i in range(n):
minj = i
for j in range(i, n):
if out_selection[j][1] < out_selection[minj][1]:
minj = j
out_selection[i], out_selection[minj] = out_selection[minj], out_selection[i]
print(*out_selection)
print("Stable" if out_bubble == out_selection else "Not stable")
|
s501210889 | p02261 | u922633376 | 1530671905 | Python | Python3 | py | Runtime Error | 0 | 0 | 795 | input_line = int(input())
out_selection = input().split()
out_bubble = out_bubble[:]
# bubblesort
for i in range(n):
for j in range(n-1, i, -1):
if out_bubble[j][1] < out_bubble[j-1][1]:
out_bubble[j], out_bubble[j-1] = out_bubble[j-1],out_bubble[j]
print(*out_bubble)
print("Stable")
# selectionsort
for i in range(n):
minj = i
for j in range(i, n):
if out_selection[j][1] < out_selection[minj][1]:
minj = j
out_selection[i], out_selection[minj] = out_selection[minj], out_selection[i]
print(*out_selection)
print("Stable" if out_bubble == out_selection else "Not stable")
|
s124736143 | p02261 | u782850731 | 1379686838 | Python | Python | py | Runtime Error | 0 | 0 | 1118 | #!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin
def bubble(cards):
for i in range(len(cards)):
for j in range(len(cards)-1, i, -1):
if cards[j][1] < cards[j-1][1]:
cards[j], cards[j-1] = cards[j-1], cards[j]
def selection(cards):
for i in range(len(cards)):
mini = i
for j in range(i, len(cards)):
if cards[j][1] < cards[mini][1]:
mini = j
cards[i], cards[mini] = cards[mini], cards[i]
def stable_test(orders, crads):
for order in orders:
n = -1
for c in order:
p = n
n = cards.index(c)
if p > n:
return False
return True
stdin.readline()
data1 = stdin.readline().split()
data2 = data1[:]
orders = [[c for c in data1 if s.endswith(str(i))] for i in range(1, 10)]
orders = [o for o in orders if len(s) > 1]
bubble(data1)
print(*data1)
print('Stable' if stable_test(orders, data1) else 'Not stable')
selection(data2)
print(*data2)
print('Stable' if stable_test(orders, data2) else 'Not stable') |
s176057408 | p02261 | u140201022 | 1389651306 | Python | Python | py | Runtime Error | 0 | 0 | 1153 | #!/usr/bin/env python
# -*- coding:utf-8 -*-
from __future__ import print_function
import time
import sys
import io
import re
import math
start = time.clock()
def bubble(cards):
for i in range(len(cards)):
for j in range(len(cards)-1, i, -1):
if cards[j][1]<cards[j-1][1]:
cards[j],cards[j-1]=cards[j-1],cards[j]
def selection(cards):
for i in range(len(cards)):
mini=i
for j in range(i,len(cards)):
if cards[j][1]<cards[mini][1]:
mini=j
cards[i],cards[mini]=cards[mini],cards[i]
def stabel_test(orders,cards):
for order in orders:
n=-1
for c in order:
p=n
n=cards.index(c)
if p>n:
return False
return True
sys.stdin.readline()
data1=sys.stdin.readline().split()
data2=data1[:]
orders=[[c for c in data1 if c.endswitch(str(i))] for i in range(1,10)]
orders=[o for o in orders if len(c)>1]
bubble(data1)
print(*data1)
print('Stable' if stabel_test(orders, data1) else 'Not stable')
selection(data2)
print(*data2)
print('Stable' if stable_test(orders, data2) else 'Not stable') |
s097344607 | p02262 | u427752990 | 1535598565 | Python | Python3 | py | Runtime Error | 0 | 0 | 704 | def printing(m, G, cnt, A):
print(m)
for i in range(len(G)):
if i != len(G) - 1:
print(G[i], end=' ')
else:
print(G[i])
print(cnt)
for i in A:
print(i)
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):
m = 2
G = [4, 1]
for i in range(0, m):
cnt = insertionSort(A, n, G[i], cnt)
printing(m, G, cnt, A)
N = int(input())
inputList = list(map(int, input().split()))
cnt = 0
shellSort(inputList, N, cnt)
|
s057736993 | p02262 | u635209856 | 1541240797 | Python | Python3 | py | Runtime Error | 0 | 0 | 621 | import System
if sys.version_info[0]>=3: raw_input=InputStream
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)
|
s404443071 | p02262 | u099826363 | 1546005803 | Python | Python3 | py | Runtime Error | 0 | 0 | 986 | #include <bits/stdc++.h>
using namespace std;
#define ll long long
ll cnt = 0;
void swap(int& a, int& b){
int tmp = a;
a = b;
b = tmp;
}
void insertionSort(int A[], int n, int g) {
for(int i=g;i<n;i++){
int v = A[i];
int j = i - g;
// cout << "g=" << g << "i=" << i << "j=" << j << endl;
while( j>= 0 && A[j] > v) {
// cout << "g=" << g << "i=" << i << "j=" << j << endl;
A[j + g] = A[j];
j -= g;
cnt++;
// cout <<" cnt=" << cnt << endl;
}
A[j + g] = v;
}
}
// void shellSort(int A[], int n, vector<int> G[]){
//
// }
int main(){
int N; cin >> N;
int a[N];
vector<int> G;
for(int i=0;i<N;i++){
cin >> a[i];
}
int h = 1;
while(h<N){
G.push_back(h);
h = 3 * h + 1;
}
cout << G.size() << endl;
for(int i=G.size()-1;i>=0;i--){
cout << G[i];
if(i) cout << " ";
}
cout << endl;
for(int i = G.size()-1;i>=0;i--){
insertionSort(a, N, G[i]);
}
cout << cnt << endl;
for(int k=0;k<N;k++){
cout << a[k] << endl;
}
return 0;
}
|
s190014655 | p02262 | u908238078 | 1546487915 | Python | Python3 | py | Runtime Error | 0 | 0 | 939 | #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
long long cnt;
int l;
int A[1000000];
int n;
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) {
for (int h = 1; ;) {
if (h > n) break;
G.push_back(h);
h = 3 * h + 1;
}
for (int i = G.size() - 1; i >= 0; i--) {
insertionSort(A, n, G[i]);
}
}
int main() {
cin >> n;
for (int i = 0; i < n; i++) scanf("%d", &A[i]);
cnt = 0;
shellSort(A, n);
cout << G.size() << endl;
for (int i = G.size() - 1; i >= 0; i--) {
printf("%d", G[i]);
if (i) printf(" ");
}
printf("\n");
printf("%lld\n", cnt);
for (int i = 0; i < n; i++) printf("%d\n", A[i]);
return 0;
}
|
s565929638 | p02262 | u840247626 | 1556033535 | Python | Python3 | py | Runtime Error | 20 | 5620 | 385 | n = int(input())
G = [g for g in [1, 4, 10, 23, 57, 132, 301, 701] if g < n]
while True:
g = int(2.25 * G[-1])
if g > n:
break
G.append(g)
G.reverse()
A = [int(input()) for _ in range(n)]
cnt = 0
for g in G:
for j, v in enumerate(A[g:]):
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j -= g
cnt += 1
A[j+g] = v
print(len(G))
print(*G)
print(cnt)
for a in A:
print(a)
|
s561786327 | p02262 | u840247626 | 1556034095 | Python | Python3 | py | Runtime Error | 0 | 0 | 410 | n = int(input())
if n == 1:
G = [1]
else:
G = [g for g in [1, 4, 10, 23, 57, 132, 301, 701] if g < n]
while True:
g = int(2.25 * G[-1])
if g > n:
break
G.append(g)
G.reverse()
A = [int(input()) for _ in range(n)]
cnt = 0
for g in G:
for j, v in enumerate(A[g:]):
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j -= g
cnt += 1
A[j+g] = v
print(len(G))
print(*G)
print(cnt, a*, sep='\n')
|
s126319962 | p02262 | u840247626 | 1556034117 | Python | Python3 | py | Runtime Error | 0 | 0 | 410 | n = int(input())
if n == 1:
G = [1]
else:
G = [g for g in [1, 4, 10, 23, 57, 132, 301, 701] if g < n]
while True:
g = int(2.25 * G[-1])
if g > n:
break
G.append(g)
G.reverse()
A = [int(input()) for _ in range(n)]
cnt = 0
for g in G:
for j, v in enumerate(A[g:]):
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j -= g
cnt += 1
A[j+g] = v
print(len(G))
print(*G)
print(cnt, *a, sep='\n')
|
s932986131 | p02262 | u286589639 | 1556421282 | Python | Python3 | py | Runtime Error | 0 | 0 | 497 | def insertion_sort(A ,N, g):
grobal 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 shell_sort(A, N):
grobal 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 g in G:
insertion_sort(A, N, g)
return m, G
N = int(input())
A = [int(input()) for i in range(N)]
shell_sort(A, N)
print(cnt)
for a in A:
print(a)
|
s510707291 | p02262 | u535719732 | 1559410408 | Python | Python3 | py | Runtime Error | 0 | 0 | 571 | n = int(input())
a = []
for i in range(n):
a.append(int(input()))
def insertion_sort(datan,n,g):
cnt = 0
for i in range(g,n):
v = data[i]
j = i - g
while j >= 0 and data[j] > v:
data[j+g] = data[j]
j = j - g
cnt += 1
data[j+g] = v
return cnt
def shellsort(data,n):
cnt = 0
m = 2
G = [4,1]
for i in range(m):
cnt = insertion_sort(data,n,G[i])
cnt += 1
print(m)
print(*G)
print(cnt)
for i in range(n):
print(data[i])
shellsort(a,n)
|
s423362647 | p02262 | u482227082 | 1559453767 | Python | Python3 | py | Runtime Error | 0 | 0 | 828 | 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
G = []
if n <= 3:
m = 1:
G[0] = 1
else:
m = n // 2
G = [0] * m
G[0] = n // m
for i in range(1, m):
G[i] = G[i-1] // 2
if G[i] == 0:
G[i] = 1
print(m)
print(*G)
for i in range(m):
cnt = insertionSort(A, n, G[i], cnt)
print(cnt)
def main():
n = int(input())
a = []
for i in range(n):
a.append(int(input()))
shellSort(a, n)
for i in range(n):
print(a[i])
if __name__ == '__main__':
main()
|
s454409727 | p02262 | u482227082 | 1559453797 | Python | Python3 | py | Runtime Error | 20 | 5608 | 827 | 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
G = []
if n <= 3:
m = 1
G[0] = 1
else:
m = n // 2
G = [0] * m
G[0] = n // m
for i in range(1, m):
G[i] = G[i-1] // 2
if G[i] == 0:
G[i] = 1
print(m)
print(*G)
for i in range(m):
cnt = insertionSort(A, n, G[i], cnt)
print(cnt)
def main():
n = int(input())
a = []
for i in range(n):
a.append(int(input()))
shellSort(a, n)
for i in range(n):
print(a[i])
if __name__ == '__main__':
main()
|
s775058603 | p02262 | u535719732 | 1559489036 | Python | Python3 | py | Runtime Error | 0 | 0 | 682 | def shell_sort(array):
n = len(array)
h = 0
k = 0
cnt = 0
g = []
while h <= n/9:
h = 3*h + 1
g.append = h
while g[k] > 0:
for i in range(h,n):
tmp = array[i]
if tmp < array[i-g[k]]:
j = i
while True:
array[j] = array[j-g[k]]
j -= h
c += 1
if j < h or tmp >= array[j-g[k]]:
break
array[j] = tmp
print(len(g))
print(*g)
for i in range(array): print(array[i])
d = []
for i in range(int(input())):
d.append = int(input())
shell_sort(d)
|
s932047761 | p02262 | u535719732 | 1559489077 | Python | Python3 | py | Runtime Error | 0 | 0 | 681 | def shell_sort(array):
n = len(array)
h = 0
k = 0
cnt = 0
g = []
while h <= n/9:
h = 3*h + 1
g.append = h
while g[k] > 0:
for i in range(h,n):
tmp = array[i]
if tmp < array[i-g[k]]:
j = i
while True:
array[j] = array[j-g[k]]
j -= h
c += 1
if j < h or tmp >= array[j-g[k]]:
break
array[j] = tmp
print(len(g))
print(*g)
for i in range(array): print(array[i])
d = []
for i in range(int(input())):
d.append(int(input()))
shell_sort(d)
|
s054000585 | p02262 | u535719732 | 1559489092 | Python | Python3 | py | Runtime Error | 0 | 0 | 680 | def shell_sort(array):
n = len(array)
h = 0
k = 0
cnt = 0
g = []
while h <= n/9:
h = 3*h + 1
g.append(h)
while g[k] > 0:
for i in range(h,n):
tmp = array[i]
if tmp < array[i-g[k]]:
j = i
while True:
array[j] = array[j-g[k]]
j -= h
c += 1
if j < h or tmp >= array[j-g[k]]:
break
array[j] = tmp
print(len(g))
print(*g)
for i in range(array): print(array[i])
d = []
for i in range(int(input())):
d.append(int(input()))
shell_sort(d)
|
s231359879 | p02262 | u535719732 | 1559536526 | Python | Python3 | py | Runtime Error | 0 | 0 | 466 | 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
def shellsort(A,n):
cnt = 0
h = 0
while(h <= n / 9): h = 3*h + 1
G = []
while h > 0:
G.append(h)
h /= 3
print(len(G))
print(*G)
for i in range(len(G)):
insertionSort(A,n,G[i])
for i in A:
print(i)
n = int(input())
A = []
for _ in range(n):
A.append(int(input()))
shellsort(A,n)
|
s633921540 | p02262 | u535719732 | 1559536967 | Python | Python3 | py | Runtime Error | 0 | 0 | 484 | 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
def shellsort(A,n):
cnt = 0
h = 0
while(h <= n / 9): h = 3*h + 1
G = []
while h > 0:
G.append(h)
h /= 3
print(len(G))
print(" ".join(map(str,G)))
for i in range(len(G)):
insertionSort(A,n,G[i])
for i in A:
print(i)
n = int(input())
A = []
for _ in range(n):
A.append(int(input()))
shellsort(A,n)
|
s496059193 | p02262 | u535719732 | 1559537046 | Python | Python3 | py | Runtime Error | 0 | 0 | 484 | 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
def shellsort(A,n):
cnt = 0
h = 0
while(h <= n / 9): h = 3*h + 1
G = []
while h > 0:
G.append(h)
h /= 3
print(len(G))
print(" ".join(map(int,G)))
for i in range(len(G)):
insertionSort(A,n,G[i])
for i in A:
print(i)
n = int(input())
A = []
for _ in range(n):
A.append(int(input()))
shellsort(A,n)
|
s302153037 | p02262 | u535719732 | 1559537070 | Python | Python3 | py | Runtime Error | 0 | 0 | 466 | 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
def shellsort(A,n):
cnt = 0
h = 0
while(h <= n / 9): h = 3*h + 1
G = []
while h > 0:
G.append(h)
h /= 3
print(len(G))
print(*G)
for i in range(len(G)):
insertionSort(A,n,G[i])
for i in A:
print(i)
n = int(input())
A = []
for _ in range(n):
A.append(int(input()))
shellsort(A,n)
|
s393580999 | p02262 | u535719732 | 1559537446 | Python | Python3 | py | Runtime Error | 0 | 0 | 489 | 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
def shellsort(A,n):
cnt = 0
h = 0
while(h <= n / 9): h = 3*h + 1
G = []
while h > 0:
G.append(h)
h /= 3
print(len(G))
print(" ".join(map(str,G)))
for i in range(len(G)):
insertionSort(A,n,G[i])
for i in A:
print(i)
n = int(input())
A = []
for _ in range(n):
A.append(int(input()))
shellsort(A,n)
|
s463634742 | p02262 | u535719732 | 1559537483 | Python | Python3 | py | Runtime Error | 0 | 0 | 496 | 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
def shellsort(A,n):
cnt = 0
h = 0
while(h <= n / 9):
h = 3*h + 1
G = []
while h > 0:
G.append(h)
h /= 3
print(len(G))
print(" ".join(map(str,G)))
for i in range(len(G)):
insertionSort(A,n,G[i])
for i in A:
print(i)
n = int(input())
A = []
for _ in range(n):
A.append(int(input()))
shellsort(A,n)
|
s759915886 | p02262 | u535719732 | 1559537570 | Python | Python3 | py | Runtime Error | 0 | 0 | 499 | 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
def shellsort(A,n):
cnt = 0
h = 0
while(h <= n / 9): h = 3*h + 1
G = []
while h > 0:
G.append(h)
h /= 3
print("-----")
print(len(G))
print(" ".join(map(str,G)))
for i in range(len(G)):
insertionSort(A,n,G[i])
for i in A:
print(i)
n = int(input())
A = []
for _ in range(n):
A.append(int(input()))
shellsort(A,n)
|
s246833138 | p02262 | u535719732 | 1559537594 | Python | Python3 | py | Runtime Error | 0 | 0 | 504 | def insertionSort(A,n,g):
cnt = 0
for i in range(int(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):
cnt = 0
h = 0
while(h <= n / 9): h = 3*h + 1
G = []
while h > 0:
G.append(h)
h /= 3
print("-----")
print(len(G))
print(" ".join(map(str,G)))
for i in range(len(G)):
insertionSort(A,n,G[i])
for i in A:
print(i)
n = int(input())
A = []
for _ in range(n):
A.append(int(input()))
shellsort(A,n)
|
s534923542 | p02262 | u535719732 | 1559538098 | Python | Python3 | py | Runtime Error | 0 | 0 | 767 | 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
return cnt
def shellsort(A,n):
cnt = 0
h = 1
G = []
while h <= 1:
G.append(h)
h = 3*h + 1
G.reverse()
print(len(G))
print(" ".join(map(str,G)))
for i in range(len(G)):
cnt += insertionSort(A,n,G[i])
print(cnt)
for i in A:
print(i)
n = int(input())
A = []
for _ in range(n):
A.append(int(input()))
shellsort(A,n)
|
s682972977 | p02262 | u535719732 | 1559538149 | Python | Python3 | py | Runtime Error | 0 | 0 | 662 | 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
return cnt
def shellsort(A,n):
cnt = 0
h = 1
G = []
while h <= 1:
G.append(h)
h = 3*h + 1
G.reverse()
print(len(G))
print(" ".join(map(str,G)))
for i in range(len(G)):
cnt += insertionSort(A,n,G[i])
print(cnt)
for i in A:
print(i)
n = int(input())
A = []
for _ in range(n):
A.append(int(input()))
shellsort(A,n)
|
s636021132 | p02262 | u535719732 | 1559538233 | Python | Python3 | py | Runtime Error | 0 | 0 | 667 | 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
return cnt
def shellsort(A,n):
cnt = 0
h = 1
G = []
while h <= 1:
G.append(h)
h = 3*h + 1
G.reverse()
m = len(G)
print(m
print(" ".join(map(str,G)))
for i in range(m:
cnt += insertionSort(A,n,G[i])
print(cnt)
for i in A:
print(i)
n = int(input())
A = []
for _ in range(n):
A.append(int(input()))
shellsort(A,n)
|
s442703723 | p02262 | u535719732 | 1559538255 | Python | Python3 | py | Runtime Error | 0 | 0 | 668 | 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
return cnt
def shellsort(A,n):
cnt = 0
h = 1
G = []
while h <= 1:
G.append(h)
h = 3*h + 1
G.reverse()
m = len(G)
print(m
print(" ".join(map(str,G)))
for i in range(m):
cnt += insertionSort(A,n,G[i])
print(cnt)
for i in A:
print(i)
n = int(input())
A = []
for _ in range(n):
A.append(int(input()))
shellsort(A,n)
|
s841019775 | p02262 | u379499530 | 1415372879 | Python | Python | py | Runtime Error | 0 | 0 | 594 | def insertion(A, n, g):
c = 0
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 -= g
c += 1
A[j + g] = key
return c
def main():
n = input()
A = [input() for i in range(n)]
h = range(n - 1, 0, -1)
G = list()
cnt = 0
for i in range(n - 1):
j = insertion(A, n, h[i])
if j > 0:
G.append(h[i])
cnt += j
print(len(G))
print(" ".join(map(str, G)))
print(cnt)
for i in G:
print(G[i])
main() |
s059755475 | p02262 | u379499530 | 1415415151 | Python | Python | py | Runtime Error | 19930 | 67884 | 568 | def insertion(A, n, g):
c = 0
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 -= g
c += 1
A[j + g] = key
return c
def main():
n = input()
A = [input() for i in range(n)]
G = [1]
h = 4
while h < n:
G[0:0] = [h]
h = h * 3 + 1
cnt = 0
for i in G:
j = insertion(A, n, i)
cnt += j
print(len(G))
print(" ".join(map(str, G)))
print(cnt)
for k in A:
print(k)
main() |
s691474256 | p02262 | u379499530 | 1415436323 | Python | Python | py | Runtime Error | 0 | 0 | 548 | def insertion(A, n, g):
c = 0
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 -= g
c += 1
A[j + g] = key
return c
def main():
n = input()
A = [input() for i in range(n)]
G = list()
h = 1
while h <= n:
G[0:0] = h
h = 3 * h + 1
cnt = 0
for i in G:
cnt += insertion(A, n, i)
print(len(G))
print(" ".join(map(str, G)))
print(cnt)
for k in A: print(k)
main() |
s780827084 | p02262 | u379499530 | 1415436367 | Python | Python | py | Runtime Error | 19930 | 67884 | 550 | def insertion(A, n, g):
c = 0
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 -= g
c += 1
A[j + g] = key
return c
def main():
n = input()
A = [input() for i in range(n)]
G = list()
h = 1
while h <= n:
G[0:0] = [h]
h = 3 * h + 1
cnt = 0
for i in G:
cnt += insertion(A, n, i)
print(len(G))
print(" ".join(map(str, G)))
print(cnt)
for k in A: print(k)
main() |
s375972186 | p02262 | u379499530 | 1415439328 | Python | Python | py | Runtime Error | 19930 | 67880 | 529 | def insertion(A, n, g):
c = 0
for i in range(g, n):
j = i - g
while j >= 0 and A[j] > A[j + g]:
A[j + g], A[j] = A[j], A[j + g]
j -= g
c += 1
return c
def main():
n = input()
A = [input() for i in range(n)]
G = list()
h = 1
while h <= n:
G[0:0] = [h]
h = 3 * h + 1
cnt = 0
for i in G:
cnt += insertion(A, n, i)
print(len(G))
print(" ".join(map(str, G)))
print(cnt)
for k in A: print(k)
main() |
s523926878 | p02262 | u379499530 | 1415439789 | Python | Python | py | Runtime Error | 19930 | 67876 | 511 | def insertion(A, n, g):
c = 0
for i in range(g, n):
while i >= g and A[i - g] > A[i]:
A[i], A[i - g] = A[i - g], A[i]
i -= g
c += 1
return c
def main():
n = input()
A = [input() for i in range(n)]
G = list()
h = 1
while h <= n:
G[0:0] = [h]
h = 3 * h + 1
cnt = 0
for i in G:
cnt += insertion(A, n, i)
print(len(G))
print(" ".join(map(str, G)))
print(cnt)
for j in A: print(j)
main() |
s903893176 | p02262 | u379499530 | 1415440533 | Python | Python | py | Runtime Error | 19930 | 75688 | 544 | def insertion(A, n, g):
c = 0
for i in range(g, n):
while i >= g and A[i - g] > A[i]:
A[i], A[i - g] = A[i - g], A[i]
i -= g
c += 1
return c
def main():
n = int(raw_input())
A = [int(raw_input()) for i in range(n)]
G = list()
h = 1
while h <= n:
G.append(h)
h = 3 * h + 1
G = G[::-1]
cnt = 0
for i in G:
cnt += insertion(A, n, i)
print(len(G))
print(" ".join(map(str, G)))
print(cnt)
for j in A: print(j)
main() |
s913889741 | p02262 | u379499530 | 1415441236 | Python | Python | py | Runtime Error | 19930 | 75692 | 546 | def insertion(A, n, g):
global cnt
for i in range(g, n):
while i >= g and A[i - g] > A[i]:
A[i], A[i - g] = A[i - g], A[i]
i -= g
cnt += 1
def main():
global cnt
cnt = 0
n = int(raw_input())
A = [int(raw_input()) for i in range(n)]
G = list()
h = 1
while h <= n:
G.append(h)
h = 3 * h + 1
G = G[::-1]
for i in G:
insertion(A, n, i)
print(len(G))
print(" ".join(map(str, G)))
print(cnt)
for j in A: print(j)
main() |
s532298659 | p02262 | u567380442 | 1421314363 | Python | Python3 | py | Runtime Error | 19930 | 47308 | 590 | def insertionSort(A, g):
cnt = 0
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
return cnt
def shellSort(A):
cnt = 0
m = 0
n = len(A)
while n:
n //= 4
m +=1
G = [4 ** i for i in range(m - 1, -1, -1)]
for g in G:
cnt += insertionSort(A, g)
print(m)
print(*G)
print(cnt)
N = int(input())
A = [int(input()) for _ in range(N)]
shellSort(A)
print(*A, sep='\n') |
s659355545 | p02262 | u567380442 | 1421314924 | Python | Python3 | py | Runtime Error | 19930 | 46920 | 688 | def insertionSort(A, g):
cnt = 0
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
return cnt
def shellSort(A):
cnt = 0
m = 0
n = len(A)
while n:
n //= 4
m +=1
G = [4 ** i for i in range(m - 1, -1, -1)]
for g in G:
cnt += insertionSort(A, g)
print(m)
print(*G)
print(cnt)
N = int(input())
A = []
sp = 10000
for _ in range(N // sp):
A += [int(input()) for _ in range(sp)]
A += [int(input()) for _ in range(N % sp)]
shellSort(A)
print(*A, sep='\n') |
s461914114 | p02262 | u567380442 | 1421315638 | Python | Python3 | py | Runtime Error | 19930 | 47308 | 591 | 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
m = 0
n = len(A)
while n:
n //= 4
m +=1
G = [4 ** i for i in range(m - 1, -1, -1)]
print(m)
print(*G)
for g in G:
insertionSort(A, g)
N = int(input())
A = [int(input()) for _ in range(N)]
shellSort(A)
print(cnt)
for a in A:
print(a) |
s009473172 | p02262 | u567380442 | 1421318686 | Python | Python3 | py | Runtime Error | 19930 | 47316 | 604 | 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 = []
for _ in range(N):
A += [int(input())]
shellSort(A)
print(cnt)
for a in A:
print(a) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.