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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
s641747631 | p02274 | u567281053 | 1458134714 | Python | Python | py | Runtime Error | 0 | 0 | 299 | import numpy
def countInversions(A, cnt):
if len(A) == 1:
return cnt
maxi = numpy.argmax(A)
cnt += len(A) - maxi - 1
del A[maxi]
return countInversions(A, cnt)
if __name__ == "__main__":
input()
A = map(int, raw_input().split())
print countInversions(A, 0) |
s807305061 | p02274 | u567281053 | 1458135048 | Python | Python | py | Runtime Error | 10 | 6432 | 425 | def countInversions(A, cnt):
if len(A) == 1:
return cnt
maxi = argmax(A)
cnt += len(A) - maxi - 1
del A[maxi]
return countInversions(A, cnt)
def argmax(A):
max = maxi = 0
for i in range(len(A)):
if A[i] > max:
max = A[i]
maxi = i
return maxi
if ... |
s278051251 | p02274 | u294007207 | 1458572051 | Python | Python | py | Runtime Error | 10 | 6544 | 1068 | import array
def merge_sort(A):
if len(A) <= 1:
return A, 0
mid = len(A) // 2
left, lcount = merge_sort(A[:mid])
right, rcount = merge_sort(A[mid:])
merged, count = merge(left, right)
return merged, lcount + rcount + count
def merge(left, right):
lpos = 0
rpos = 0
rcount = ... |
s071062685 | p02274 | u294007207 | 1458572320 | Python | Python | py | Runtime Error | 10 | 6540 | 1068 | import array
def merge_sort(A):
if len(A) <= 1:
return A, 0
mid = len(A) // 2
left, lcount = merge_sort(A[:mid])
right, rcount = merge_sort(A[mid:])
merged, count = merge(left, right)
return merged, lcount + rcount + count
def merge(left, right):
lpos = 0
rpos = 0
rcount = ... |
s061946076 | p02274 | u963402991 | 1459479502 | Python | Python3 | py | Runtime Error | 0 | 0 | 231 | from collections import deque
n = int(input())
A = deque(map(int, input().split()))
num = list(sorted(A, reverse=True))
count = 0
for i in range(n - 1):
count += len(A) - 1 - A.index(num[i])
A.remove(num[i])
print(count) |
s854815774 | p02274 | u963402991 | 1459480359 | Python | Python3 | py | Runtime Error | 0 | 0 | 230 | from collections import deque
n = int(input())
A = deque(map(int, input().split()))
num = list(sorted(A, reverse=True))
count = 0
for i in range(n - 1):
count += len(A) - 1 - A.index(num[i])
A.remove(num[i])
print(count) |
s754508052 | p02274 | u130979865 | 1459839962 | Python | Python | py | Runtime Error | 0 | 0 | 195 | # -*- coding: utf-8 -*-
n = int(raw_input())
A = map(int, raw_input().split())
count = 0
for i in range(n):
for j = in range(i, n):
if A[i] > A[j]:
count += 1
print count |
s562236116 | p02274 | u569960318 | 1465803862 | Python | Python3 | py | Runtime Error | 40 | 7724 | 246 | def invNum(A):
if len(A)==1: return 0
cnt = 0
for i in range(1,len(A)):
if A[0] > A[i]: cnt += 1
return cnt + invNum(A[1:])
if __name__=='__main__':
n = int(input())
print(invNum(list(map(int,input().split())))) |
s176368175 | p02274 | u742013327 | 1477887665 | Python | Python3 | py | Runtime Error | 30 | 7700 | 839 | def bubble_sort_revision(target_list):
list_length = len(target_list)
flag = True
change_count = 0
for top_index in range(1,list_length):
for i in range(top_index, list_length)[::-1]:
if target_list[i] < target_list[i - 1] and target_list[top_index] >= target_list[i]:
... |
s049440295 | p02274 | u130834228 | 1491372398 | Python | Python3 | py | Runtime Error | 0 | 0 | 162 | n = int(input())
A = list(map(int, input().split()))
cnt = 0
for i in range(n):
for j in range(i+1, n):
if A[i] > A[j]:
cnt++
print(cnt) |
s982427589 | p02274 | u130834228 | 1492065174 | Python | Python3 | py | Runtime Error | 0 | 0 | 887 | def merge(A, left, mid, right):
n1 = mid-left
n2 = right-mid
#L = [0 for i in range(n1+1)]
#R = [0 for i in range(n2+1)]
#for i in range(n1):
# L[i] = A[left+i]
#for i in range(n2):
# R[i] = A[mid+i]
L = A[left:mid]
R = A[mid:right]
L.append(float('inf'))
R.append(... |
s205424197 | p02274 | u193453446 | 1501553789 | Python | Python3 | py | Runtime Error | 0 | 0 | 383 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
def main():
""" ????????? """
num = int(input().strip())
A = list(map(int,input().split()))
cnt = 0
for i in range(num-1):
for j in range(i,num):
if i > j:
cnt++
if cnt % 2 == 0:
cnt += 1
else:
... |
s575713100 | p02274 | u426534722 | 1516976288 | Python | Python3 | py | Runtime Error | 0 | 0 | 130 | N = int(input())
A = tuple(map(int, input().split()))
print(len(1 for i in range(N - 1) for j in range(i + 1, N) if A[i] > A[j]))
|
s960564865 | p02274 | u464859367 | 1525321775 | Python | Python3 | py | Runtime Error | 0 | 0 | 1873 | using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ALDS1_5_B
{
class Program
{
static long cnt = 0;
static void Main(string[] args)
{
int n = int.Parse(Console.ReadLine());
int[] S = Arra... |
s994874665 | p02274 | u011621222 | 1526041484 | Python | Python3 | py | Runtime Error | 0 | 0 | 953 | MAX = 500000;
maxnum = 1000000010;
cnt=0
def Merge_sort(A):
def merge(A,left,mid,right):
global cnt
t1=array.array('L',[])
t2=array.array('L',[])
for i in range(left,mid):
t1.append(A[i])
for i in range(mid,right):
t2.append(A[i])
... |
s800669911 | p02274 | u564105430 | 1527154562 | Python | Python3 | py | Runtime Error | 0 | 0 | 368 | def shakerSort(A):
cnt=0
left=0
right=len(A)-1
while left<right:
for i in range(left,right):
if A[i]>A[i+1]:
A[i],A[i+1]=A[i+1],A[i]
sh=i
cnt+=1
right=sh
for j in range(right,left,-1):
if A[j]<A[j-1]:
A[j],A[j-1]=A[j-1],A[j]
sh=j
cnt+=1
left=sh
return cnt
n=int(input())
A=lis... |
s776178404 | p02274 | u564105430 | 1527154576 | Python | Python3 | py | Runtime Error | 20 | 5600 | 369 | def shakerSort(A):
cnt=0
left=0
right=len(A)-1
while left<right:
for i in range(left,right):
if A[i]>A[i+1]:
A[i],A[i+1]=A[i+1],A[i]
sh=i
cnt+=1
right=sh
for j in range(right,left,-1):
if A[j]<A[j-1]:
A[j],A[j-1]=A[j-1],A[j]
sh=j
cnt+=1
left=sh
return cnt
n=int(input())
A=lis... |
s613079792 | p02274 | u782850499 | 1527826622 | Python | Python3 | py | Runtime Error | 0 | 0 | 716 | cnt = 0
def merge(A,left,mid,right):
global cnt
n1 = mid - left
n2 = right - mid
L = [A[i] for i in range(left, mid)]
R = [A[i] for i in range(mid, right)]
L.append(float("inf"))
R.append(float("inf"))
i = 0
j = 0
for k in range(left, right):
if L[i] <= R[j]:
... |
s040864485 | p02274 | u007270338 | 1528174586 | Python | Python3 | py | Runtime Error | 650 | 16476 | 631 | #coding:utf-8
n = int(input())
A = list(map(int, input().split()))
def Merge(A, left, mid, right):
L = A[left:mid]
R = A[mid:right]
L.append(510000)
R.append(510000)
i,j = 0,0
global cnt
for k in range(left,right):
if L[i] <= R[j]:
A[k] = L[i]
i += 1
... |
s865466949 | p02275 | u657361950 | 1531377589 | Python | Python3 | py | Runtime Error | 0 | 0 | 960 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(reader.readLine());
String[] strA... |
s675647583 | p02275 | u153665391 | 1532162564 | Python | Python3 | py | Runtime Error | 0 | 0 | 416 | def counting_sort(MAX):
C = [0 for _ in range(MAX+1)]
for i in range(N):
C[A[i]] += 1
for i in range(1, MAX+1):
C[i] = C[i] + C[i-1]
for i in range(N-1, -1, -1):
C[A[i]] -= 1
B[C[A[i]]] = A[i]
N = int(input())
A = list(map(int, input().split()))
MAX = 0
for n in A:
... |
s870515981 | p02275 | u487861672 | 1534940227 | Python | Python3 | py | Runtime Error | 20 | 5600 | 351 | def counting_sort(A, k):
B = [0] * len(A)
C = [0] * k
for a in A:
C[a] += 1
for i in range(1, k):
C[i] += C[i - 1]
for a in reversed(A):
B[C[a] - 1] = a
C[a] -= 1
return B
def main():
n = int(input())
A = [int(x) for x in input().split()]
print(*... |
s894993784 | p02275 | u803657704 | 1545368733 | Python | Python3 | py | Runtime Error | 20 | 5600 | 547 | def CountingSort(A, B, k):
C = [0] * (k+1)
#C[i] に i の出現数を記録する
for j in range(0,k):
C[A[j]]+=1
#print("C ",j,C[:k+1])
#C[i] に i 以下の数の出現数を記録する
for i in range(1,k+1):
C[i] = C[i] + C[i-1]
#print("C' ",j,C[:k+1])
for j in range(k-1,-1,-1):
B[C[A[j]]] = A[j]
... |
s328622135 | p02275 | u237270455 | 1545369825 | Python | Python3 | py | Runtime Error | 20 | 6500 | 451 | n = int(input())
temp = [int(i) for i in input().split()]
A = [None for i in range(10000)]
B = [0 for i in range(n)]
k = 0
for i in range(n):
A[i] = temp[i]
if(A[i]>k):
k=A[i]
def cntSort(A, B, k):
C = [0 for i in range(k)]
for j in range(0, n):
C[A[j]] += 1
for i in range(1, k):
... |
s504494930 | p02275 | u237270455 | 1545369980 | Python | Python3 | py | Runtime Error | 50 | 7976 | 483 | n = int(input())
temp = [int(i) for i in input().split()]
A = [None for i in range(200000)]
B = [0 for i in range(n)]
k = 0
for i in range(n):
A[i] = temp[i]
if(A[i]>k):
k=A[i]
if(k>10000):
break
def cntSort(A, B, k):
C = [0 for i in range(k)]
for j in range(0, n):
C[A[j]] +=... |
s151307829 | p02275 | u237270455 | 1545370052 | Python | Python3 | py | Runtime Error | 70 | 7976 | 483 | n = int(input())
temp = [int(i) for i in input().split()]
A = [None for i in range(200001)]
B = [0 for i in range(n)]
k = 0
for i in range(n):
A[i] = temp[i]
if(A[i]>k):
k=A[i]
if(k>10000):
break
def cntSort(A, B, k):
C = [0 for i in range(k)]
for j in range(0, n):
C[A[j]] +=... |
s183824544 | p02275 | u237270455 | 1545370247 | Python | Python3 | py | Runtime Error | 40 | 8076 | 549 | n = int(input())
temp = [int(i) for i in input().split()]
A = [None for i in range(200001)]
B = [0 for i in range(n)]
k = 0
for i in range(n):
try:
A[i] = temp[i]
if(A[i]>k):
k=A[i]
if(k>10000):
break
except IndexError:
break
def cntSort(A, B, k):
C = ... |
s528510020 | p02275 | u237270455 | 1545370566 | Python | Python3 | py | Runtime Error | 40 | 8072 | 573 | n = int(input())
temp = [int(i) for i in input().split()]
A = [None for i in range(200001)]
B = [0 for i in range(n)]
k = 0
for i in range(n):
try:
A[i] = temp[i]
if(A[i]>k):
k=A[i]
if(k>10000):
break
except IndexError:
n = len(A[i])-1
break
def cn... |
s820381094 | p02275 | u237270455 | 1545371032 | Python | Python3 | py | Runtime Error | 40 | 8072 | 565 | n = int(input())
temp = [int(i) for i in input().split()]
A = [None for i in range(200000)]
B = [0 for i in range(n)]
k = 0
for i in range(n):
try:
A[i] = temp[i]
if(A[i]>k):
k=A[i]
if(k>10000):
break
except IndexError:
n = n-1
break
def cntSort(A,... |
s687367983 | p02275 | u237270455 | 1545371202 | Python | Python3 | py | Runtime Error | 30 | 8076 | 627 | n = int(input())
temp = [int(i) for i in input().split()]
A = [None for i in range(200000)]
B = [0 for i in range(n)]
k = 0
for i in range(n):
try:
A[i] = temp[i]
if(A[i]>k):
k=A[i]
if(k>10000):
break
except IndexError:
n = n-1
break
def cntSort(A,... |
s046534502 | p02275 | u363774867 | 1556206867 | Python | Python3 | py | Runtime Error | 20 | 5604 | 417 | def countingsort(a,k):
c=[0]*(k+1)
n=len(a)
for i in a:
c[i]+=1
for i in range(1,k+1):
c[i]=c[i]+c[i-1]
b=[0]*n
for i in range(n-1,-1,-1):
b[c[a[i]]-1]=a[i]
c[a[i]]-=1
return b
q=int(input())
a=list(map(int,input().split()))
ret=countingsort(a,q)
for i in rang... |
s046257173 | p02275 | u363774867 | 1556206983 | Python | Python3 | py | Runtime Error | 0 | 0 | 412 | def countingsort(a,k):
c=[0]*(k+1)
n=len(a)
for i in a:
c[i]+=1
for i in range(1,k+1):
c[i]=c[i]+c[i-1]
b=[0]*n
for i in range(n-1,-1,-1):
b[c[a[i]]-1]=a[i]
c[a[i]]-=1
return b
o=int(input())
a=list(map(int,input().split()))
q=max(a)
ret=countingsort(a,q)
for ... |
s241325775 | p02275 | u805716376 | 1556765891 | Python | Python3 | py | Runtime Error | 0 | 0 | 321 | #計数ソート
n = int(input())
a = list(map(int, input().split()))
def countSort(a):
N = max(a)
c = [0]*(N+2)
b = [0]*len(a)
for i in a:
c[i] += 1
for i in range(1,len(c)):
c[i] += c[i-1]
for i in a:
b[c[i]-1] = i
c[i] -= 1
print(b)
countSort(*a)
|
s830923495 | p02275 | u548252256 | 1559567106 | Python | Python3 | py | Runtime Error | 20 | 5604 | 488 | def CountingSort(A,B,num):
C = [0 for _ in range(num)]
#C[i]にiの出現回数を記録する
for i in A:
C[i] += 1
#C[i]にi以下の数の出現数を記録する =>累積度数分布を出力
k = max(A)
for j in range(k+1):
C[j] += C[j-1]
for h in range(k+1):
B[C[A[h]]-1] = A[h]
C[A[h]] -= 1
if __name__ == '__main__':
num = int(input())
A = [int(i) for i in i... |
s572567553 | p02275 | u548252256 | 1559569777 | Python | Python3 | py | Runtime Error | 20 | 5608 | 509 | def CountingSort(A,B,num):
C = [0 for _ in range(num+1)]
#C[i]にiの出現回数を記録する
for i in A:
C[i] += 1
#C[i]にi以下の数の出現数を記録する =>累積度数分布を出力
k = max(A)
for j in range(1,k+1):
C[j] += C[j-1]
for h in range(num-1,-1,-1):
B[C[A[h]]-1] = A[h]
C[A[h]] -= 1
if __name__ == '__main__':
num = int(input())
A = [int(i) ... |
s021027269 | p02275 | u963402991 | 1459733596 | Python | Python3 | py | Runtime Error | 0 | 0 | 496 |
def counting_sort(A, k):
B = [0 for i in range(len(A))]
C = [0 for i in range(0, k + 1)]
# C[i]???i???????????°????¨??????????
for j in range(1, n):
C[A[j]] += 1
# C[i]???i??\????????°???????????°????¨??????????
for i in range(1, k + 1):
C[i] += C[i - 1]
for j in revers... |
s102288708 | p02275 | u130979865 | 1459916711 | Python | Python | py | Runtime Error | 10 | 6864 | 480 | # -*- coding: utf-8 -*-
def countSort(A, m):
count = [0]*(m+1)
n = len(A)
B = [0]*m
j = 0
for i in range(n):
count[A[i]] += 1
for i in range(1, m):
count[i] += count[i-1]
for i in range(n-1, -1, -1):
j = count[A[i]]
B[j] = A[i]
count[A[i]] = j-1
f... |
s270117966 | p02275 | u130979865 | 1459916833 | Python | Python | py | Runtime Error | 40 | 22500 | 486 | # -*- coding: utf-8 -*-
def countSort(A, m):
count = [0]*(m+1)
n = len(A)
B = [0]*2000000
j = 0
for i in range(n):
count[A[i]] += 1
for i in range(1, m):
count[i] += count[i-1]
for i in range(n-1, -1, -1):
j = count[A[i]]
B[j] = A[i]
count[A[i]] = j-1... |
s246946181 | p02275 | u742013327 | 1478597896 | Python | Python3 | py | Runtime Error | 0 | 0 | 566 |
def counting_sort(target_list):
counter = [0 for i in range(10000)]
for n in target_list:
counter[n] += 1
for i in range(1,10000):
counter[i] = counter[i] + counter[i-1]
result = [0 for i in range(len(target_list))]
for n in target_list[::-1]:
result[counter[n] - 1] = n
... |
s039396554 | p02275 | u022407960 | 1478861863 | Python | Python3 | py | Runtime Error | 30 | 8776 | 699 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
def counting_sort(A, k):
B = [0] * k
C = [0] * k
for j in range(array_length):
C[A[j]] += 1
# print('1', C[:array_length])
for i in range(1, k):
C[i] += C[i - 1]
# print('2', C[:array_length])
for m in range(array... |
s901136393 | p02275 | u022407960 | 1478862060 | Python | Python3 | py | Runtime Error | 20 | 8716 | 699 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
def counting_sort(A, k):
B = [0] * k
C = [0] * k
for j in range(array_length):
C[A[j]] += 1
# print('1', C[:array_length])
for i in range(1, k):
C[i] += C[i - 1]
# print('2', C[:array_length])
for m in range(array... |
s653995451 | p02275 | u564398841 | 1486275720 | Python | Python3 | py | Runtime Error | 60 | 12644 | 447 | def CountingSort(A, k):
C = [0] * k
B = C[:]
for a in A:
C[a] += 1
for i in range(1, len(C)):
C[i] += C[i - 1]
for i in range(len(A) - 1, -1, -1):
B[C[A[i]]] = A[i]
C[A[i]] -= 1
return B
if __name__ == '__main__':
N = int(input())
A = [int(i) for i in i... |
s526485922 | p02275 | u564398841 | 1486275791 | Python | Python3 | py | Runtime Error | 80 | 17428 | 446 | def CountingSort(A, k):
C = [0] * k
B = C[:]
for a in A:
C[a] += 1
for i in range(1, len(C)):
C[i] += C[i - 1]
for i in range(len(A) - 1, -1, -1):
B[C[A[i]]] = A[i]
C[A[i]] -= 1
return B
if __name__ == '__main__':
N = int(input())
A = [int(i) for i in in... |
s354247541 | p02275 | u564398841 | 1486275857 | Python | Python3 | py | Runtime Error | 0 | 0 | 448 | def CountingSort(A, k):
C = [0] * k
B = C[:]
for a in A:
C[a] += 1
for i in range(1, len(C)):
C[i] += C[i - 1]
for i in range(len(A) - 1, -1, -1):
B[C[A[i]]] = A[i]
C[A[i]] -= 1
return B
if __name__ == '__main__':
N = int(input())
A = [int(i) for i in ... |
s063138590 | p02275 | u564398841 | 1486275876 | Python | Python3 | py | Runtime Error | 0 | 0 | 492 | def CountingSort(A, k):
C = [0] * k
B = C[:]
for a in A:
C[a] += 1
for i in range(1, len(C)):
C[i] += C[i - 1]
for i in range(len(A) - 1, -1, -1):
B[C[A[i]]] = A[i]
C[A[i]] -= 1
return B
fin = open('sample.txt')
input = fin.readline
if __name__ == '__main__':
... |
s949611255 | p02275 | u539803218 | 1496291586 | Python | Python3 | py | Runtime Error | 20 | 7548 | 463 | def counting_sort(array, maxval):
m = maxval + 1
count = [0] * (m)
for a in array:
count[a] += 1
i = 0
for a in range(m):
for c in range(count[a]):
array[i] = a
i += 1
return array
if __name__ == '__main__':
N = int(input())
l = list(map(int, inp... |
s094813552 | p02275 | u091533407 | 1499064044 | Python | Python3 | py | Runtime Error | 0 | 0 | 430 | def CountingSort(A, B, k):
C = [0 for i in range(k+2)]
for j in range(n):
C[A[j]] += 1
for i in range(k+1):
C[i] += C[i-1]
for j in range(n-1, -1, -1):
B[C[A[j]]-1] = A[j]
C[A[j]] -= 1
if __name__=="__main__":
n = int(input())
D = list(map(... |
s380206750 | p02275 | u548155360 | 1512315316 | Python | Python3 | py | Runtime Error | 20 | 6304 | 693 | # coding=utf-8
def counting_sort(input_list: list, upper: int) -> list:
number = len(input_list)
# noinspection PyUnusedLocal
b = [0 for i in range(number+1)]
# noinspection PyUnusedLocal
counter_list = [0 for i in range(upper+1)]
for j in input_list:
counter_list[j] += 1
for i in... |
s033489758 | p02275 | u146816547 | 1512651854 | Python | Python | py | Runtime Error | 0 | 0 | 372 | def counting_sort(A, B, k):
C = [0 for _ in xrange(k+1)]
for a in A:
C[a] += 1
for i in xrange(k):
C[i] = C[i] + C[i-1]
for i in xrange(n-1, -1, -1):
B[C[A[i]]-1] = A[i]
C[A[i]] -= 1
n = int(raw_input())
A = map(int, raw_input().split())
B = [0 for _ in xrange(n)]
co... |
s418049986 | p02275 | u613534067 | 1521105051 | Python | Python3 | py | Runtime Error | 20 | 5604 | 427 | def counting_sort(A, k):
C = [0 for i in range(k)]
# C[i]にiの出現数を記録する
for l in A:
C[l] += 1
# C[i]にi以下の数の出現数を記録する
for i in range(1, k):
C[i] = C[i] + C[i-1]
B = [None for i in range(len(A))]
for l in A[::-1]:
B[C[l]-1] = l
C[l] -= 1
return B
input()
a = list(map... |
s612826947 | p02275 | u912143677 | 1521769986 | Python | Python3 | py | Runtime Error | 0 | 0 | 368 | n = int(input())
a = list(map(int, input().split()))
def countingsort(a, k):
c = [0 for i in range(k)]
b = [0 for i in range(n)]
for j in range(n):
c[a[j]] += 1
for i in range(k):
c[i+1] += c[i]
for j in reversed(range(n)):
b[c[a[j]]] = a[j]
c[a[j]] -= 1
... |
s629230074 | p02275 | u126478680 | 1525368415 | Python | Python3 | py | Runtime Error | 20 | 5604 | 410 | def counting_sort(A, k):
n = len(A)
B = [0 for i in range(n)]
C = [0 for i in range(k+1)]
for j in range(n):
C[A[j]] += 1
for i in range(1, k):
C[i] = C[i] + C[i-1]
for j in range(n-1, -1, -1):
B[C[A[j]]-1] = A[j]
C[A[j]] -= 1
return B
n = int(input())
A ... |
s312454040 | p02275 | u938045879 | 1527411402 | Python | Python3 | py | Runtime Error | 20 | 5600 | 414 | n = int(input())
s = list(map(int, input().split()))
k = len(set(s))
c = [0 for i in range(k+1)]
def counting_sort(a, k):
global c
b = [0 for i in range(len(a)+1)]
for i in range(n):
c[a[i]] += 1
for i in range(1,k+1):
c[i] = c[i] + c[i - 1]
for i in reversed(range(n)):
b[c... |
s788126510 | p02275 | u007270338 | 1528125339 | Python | Python3 | py | Runtime Error | 20 | 6724 | 386 | #coding:utf-8
n = int(input())
A = list(map(int, input().split()))
k = 10000
C = [0 for i in range(k)]
B = [0 for i in range(n)]
def CountingSort(A,B,k):
for i in range(n):
C[A[i]] += 1
for i in range(k):
C[i] += C[i-1]
for i in range(n):
B[C[A[i]]-1] = A[i]
C[A[i]] -= 1
C... |
s230090955 | p02275 | u007270338 | 1528170012 | Python | Python3 | py | Runtime Error | 30 | 6724 | 403 | #coding:utf-8
n = int(input())
A = list(map(int, input().split()))
k = 10000
C = [0 for i in range(k)]
B = [0 for i in range(n)]
def CountingSort(A,B,k):
for i in range(n):
C[A[i]] += 1
for i in range(k):
C[i] += C[i-1]
for i in range(n-1,-1,-1):
B[C[A[i]]-1] = A[i]
C[A[i]]... |
s704416795 | p02275 | u007270338 | 1528170054 | Python | Python3 | py | Runtime Error | 20 | 6724 | 395 | #coding:utf-8
n = int(input())
A = list(map(int, input().split()))
k = 10000
C = [0 for i in range(k)]
B = [0 for i in range(n)]
def CountingSort(A,B,k):
for i in range(n):
C[A[i]] += 1
for i in range(k):
C[i] += C[i-1]
for i in range(n):
B[C[A[i]]-1] = A[i]
C[A[i]] -= 1
C... |
s050047795 | p02276 | u356729014 | 1551415826 | Python | Python3 | py | Runtime Error | 0 | 0 | 373 | def partition(A, p, r):
x = A[r]
i = p - 1
for j in range(p, r):
if A[j] <= x:
i += 1
A[i], A[j] = A[j], A[i]
A[i + 1], A[r] = A[r], A[i + 1]
return i + 1
n = int(input())
A = [int(num) for num in input().split()]
p = 0
r = n
q = partition(A, p, r)
A_str = [str(a) for a in A]
A_s... |
s176338949 | p02276 | u356729014 | 1551416182 | Python | Python3 | py | Runtime Error | 0 | 0 | 367 | def partition(A, p, r):
x = A[r]
i = p - 1
for j in range(p, r):
if A[j] <= x:
i += 1
A[i], A[j] = A[j], A[i]
A[i + 1], A[r] = A[r], A[i + 1]
return i + 1
n = int(input())
A = [int(num) for num in input().split()]
p = 0
r = n
q = partition(A, p, r)
A_str = [str(a) for a in A]
A_str[q]... |
s015066530 | p02276 | u356729014 | 1551416362 | Python | Python3 | py | Runtime Error | 0 | 0 | 361 | def partition(A, p, r):
x = A[r]
i = p - 1
for j in range(p, r):
if A[j] <= x:
i += 1
A[i], A[j] = A[j], A[i]
A[i + 1], A[r] = A[r], A[i + 1]
return i + 1
A = [int(num) for num in input().split()][1:]
p = 0
r = len(A)-1
q = partition(A, p, r)
A_str = [str(a) for a in A]
A_str[q] = "["... |
s941511366 | p02276 | u387603681 | 1556265547 | Python | Python3 | py | Runtime Error | 0 | 0 | 306 | def partition(A, p, r):
x = A[r]
i = p-1
for j in range(p, r-1):
if A[j] <= i:
i += 1
A[i], A[j] = A[j], A[i]
A[i + 1], A[r] = A[r], A[i + 1]
return i + 1
n = int(input())
*A, = map(int, input().split())
r = A[-1]
p = min(A)
A[partition(A, p, r)] = "["+r+"]"
print(' '.join(A))
|
s736819025 | p02276 | u253463900 | 1442386041 | Python | Python3 | py | Runtime Error | 0 | 0 | 467 | def Partition(A,p,r):
x = A[r]
i = p-1
for j in range(p,r):
if (A[j] <= x):
i += 1
A[i],A[j] = A[j],A[i]
A[i+1],A[r] = A[r],A[i+1]
return i+1
n = int(input())
st = input()
data = list(map(int,st.split()))
mid = Partition(data,0,len(data)-1)
for i in range(0,mid):
... |
s951000642 | p02276 | u488601719 | 1448793521 | Python | Python3 | py | Runtime Error | 0 | 0 | 290 | def partition(a, p, r):
x = a[r]
i = p - 1
for j in range(p, r):
if a[j] <= x:
i = i + 1
a[i], a[j] = a[j], a[i]
a[i+1], a[r] = a[r], a[i+1]
print(*a)
return i+1
n = int(input())
a = list(map(int, input().split()))
partition(a, 0, n) |
s936228354 | p02276 | u488601719 | 1448793695 | Python | Python3 | py | Runtime Error | 0 | 0 | 322 | def partition(a, p, r):
x = a[r]
i = p - 1
for j in range(p, r):
if a[j] <= x:
i = i + 1
a[i], a[j] = a[j], a[i]
a[i+1], a[r] = a[r], a[i+1]
return i+1
n = int(input())
a = list(map(int, input().split()))
m = partition(a, 0, n-1)
a[m] = "[%s]"%(a[m])
print(" ".join(a... |
s583212725 | p02276 | u963402991 | 1459737470 | Python | Python3 | py | Runtime Error | 0 | 0 | 335 |
def partition(A, p, r):
x = A[r]
i = p - 1
for j in range(p, r):
if A[j] <= x:
i += 1
A[i], A[j] = A[j], A[i]
A[i + 1], A[r] = A[r], A[i + 1]
return i + 1
n = int(input())
A = list(map(int, input().split()))
q =partition(A, 1, len(A) - 1)
print(*A[:q] + " [{0}] ... |
s392850139 | p02276 | u963402991 | 1459904099 | Python | Python3 | py | Runtime Error | 0 | 0 | 335 |
def partition(A, p, r):
x = A[r]
i = p - 1
for j in range(p, r):
if A[j] <= x:
i += 1
A[i], A[j] = A[j], A[i]
A[i + 1], A[r] = A[r], A[i + 1]
return i + 1
n = int(input())
A = list(map(int, input().split()))
q =partition(A, 1, len(A) - 1)
print(*A[:q] + " [{0}] ... |
s825753577 | p02276 | u918457647 | 1469261346 | Python | Python3 | py | Runtime Error | 0 | 0 | 386 | def partition(a, p, r):
x = a[r]
i = p-1
for j in range(p, r):
if a[j] <= x:
i += 1
tmp = a[i]
a[i] = a[j]
a[j] = tmp
tmp = a[i+1]
a[i+1] = a[r]
a[r] = tmp
return a, i+1
n = int(input())
A = list(map(int, input().split()))
ans, idx ... |
s656947416 | p02276 | u918457647 | 1469261421 | Python | Python3 | py | Runtime Error | 0 | 0 | 386 | def partition(a, p, r):
x = a[r]
i = p-1
for j in range(p, r):
if a[j] <= x:
i += 1
tmp = a[i]
a[i] = a[j]
a[j] = tmp
tmp = a[i+1]
a[i+1] = a[r]
a[r] = tmp
return a, i+1
n = int(input())
A = list(map(int, input().split()))
ans, idx ... |
s934012144 | p02276 | u918457647 | 1469261775 | Python | Python3 | py | Runtime Error | 0 | 0 | 314 | def partition(p, r):
x = a[r]
i = p-1
for j in range(p, r):
if a[j] <= x:
i += 1
a[i], a[j] = a[j], a[i]
a[i+1], a[r] = a[r], a[i+1]
return i+1
n = int(input())
a = list(map(int, input().split()))
idx = partition(0, n-1)
print(*a[:idx], [a[idx]], *a[idx+1:]) |
s823548226 | p02276 | u811733736 | 1480892419 | Python | Python3 | py | Runtime Error | 0 | 0 | 920 | def partition(A, p, r):
"""
???????????????????????????????????????A[r]?????°?????????????????????????????????????????????A[r-1]??¨?´??????????????????§??¨???
"""
x = A[r]p
i = p - 1
for j in range(p, r):
if A[j] <= x:
i += 1
temp = A[i]
A[i] = A[j]
... |
s365250637 | p02276 | u564398841 | 1486264075 | Python | Python3 | py | Runtime Error | 0 | 0 | 546 | def partition(A, p, r):
x = A[r]
i = p - 1
for j in range(p, r):
if A[j] < x:
i += 1
A[i], A[j] = A[j], A[i]
A[i + 1], A[r] = A[r], A[i + 1]
return i + 1
fin = open('sample.txt')
input = fin.readline
if __name__ == '__main__':
N = int(input().strip())
AA = ... |
s330649724 | p02276 | u300946041 | 1490582153 | Python | Python3 | py | Runtime Error | 0 | 0 | 413 | # -*- coding: utf-8 -*-
def partition(A, p, r):
x = A[r]
i = p
for j in range(1, r):
if A[j] <= x:
i += 1
A[i], A[j] = A[j], A[i]
A[i], A[r] = A[r], A[i]
return i
def main():
n = int(input())
A = [int(e) for e in input().split()]
p = 0
r = len(A)... |
s394720646 | p02276 | u546285759 | 1492338485 | Python | Python3 | py | Runtime Error | 0 | 0 | 310 | def partition(A, p, r):
x = A[r]
i = p-1
for j in range(p, r):
if A[j] <= x:
i += 1
A[i], A[j] = A[j], A[i]
A[i+1], A[r] = A[r], A[i+1]
return i+1
n = int(input())
A = list(map(int, input().split()))
i = partition(A, 0, n)
A[i] = "["+str(A[i])+"]"
print(*A) |
s888926531 | p02276 | u426534722 | 1498489422 | Python | Python3 | py | Runtime Error | 0 | 0 | 397 | def partition(p, r):
x = A[r]
i = p - 1
for j in range(p, r):
if A[j] <= x:
i += 1
A[i], A[j] = A[j], A[i]
A[i + 1], A[r] = A[r], A[i + 1]
return i + 1
n = int(input())
A = [int(i) for i in input().split()]
q = partition(0, n - 1);
print(*A[:q], "[" + str(A[q]) + "]",... |
s728948316 | p02276 | u426534722 | 1498489502 | Python | Python3 | py | Runtime Error | 0 | 0 | 377 | def partition(p, r):
x = A[r]
i = p - 1
for j in range(p, r):
if A[j] <= x:
i += 1
A[i], A[j] = A[j], A[i]
A[i + 1], A[r] = A[r], A[i + 1]
return i + 1
n = int(input())
A = [int(i) for i in input().split()]
q = partition(0, n - 1);
print(*A[:q], "[" + str(A[q]) + "]",... |
s538195242 | p02276 | u426534722 | 1498489539 | Python | Python3 | py | Runtime Error | 0 | 0 | 378 | n = int(input())
A = [int(i) for i in input().split()]
def partition(p, r):
x = A[r]
i = p - 1
for j in range(p, r):
if A[j] <= x:
i += 1
A[i], A[j] = A[j], A[i]
A[i + 1], A[r] = A[r], A[i + 1]
return i + 1
q = partition(0, n - 1);
print(*A[:q], "[" + str(A[q]) + "]"... |
s014981213 | p02276 | u426534722 | 1498489752 | Python | Python3 | py | Runtime Error | 0 | 0 | 377 | n = int(input())
A = [int(i) for i in input().split()]
def partition(p, r):
x = A[r]
i = p - 1
for j in range(p, r):
if A[j] <= x:
i += 1
A[i], A[j] = A[j], A[i]
A[i + 1], A[r] = A[r], A[i + 1]
return i + 1
q = partition(0, n - 1)
print(*A[:q], "[" + str(A[q]) + "]",... |
s773487402 | p02276 | u193453446 | 1501834803 | Python | Python3 | py | Runtime Error | 0 | 0 | 1409 | import sys
def swap(A, i, j):
x = A[i]
A[i] = A[j]
A[j] = x
def partition(A, p, r, idx):
x = A[r][idx] # 1 x = A[r]
i = p - 1 # 2 i = p-1
for j in range(p, r): # 3 for j = p to r-1
if A[j][idx] <= x: # 4 if A[j] <= x
i += 1... |
s574054424 | p02276 | u918276501 | 1507977754 | Python | Python3 | py | Runtime Error | 0 | 0 | 305 | def partition(A,p=0, r=None):
if r is None:
r = len(A)-1
x = A[r]
i = p-1
for j in range(p,r):
while A[j] <= x:
i += 1
swap(A,i,j)
swap(A,i+1,r)
return i+1
k = partition(A)
B = list(map(str, A))
B[k] = "[{}]".format(B[k])
print(" ".join(B)) |
s209213016 | p02276 | u918276501 | 1507977830 | Python | Python3 | py | Runtime Error | 0 | 0 | 407 | def partition(A,p=0, r=None):
if r is None:
r = len(A)-1
x = A[r]
i = p-1
for j in range(p,r):
while A[j] <= x:
i += 1
swap(A,i,j)
swap(A,i+1,r)
return i+1
if __name__ == "__main__:
input()
A = list(map(int, input().strip().split()))
k = parti... |
s992520929 | p02276 | u918276501 | 1507977918 | Python | Python3 | py | Runtime Error | 20 | 7732 | 465 | def swap(A,i,j):
A[i],A[j] = A[j],A[i]
return A
def partition(A,p=0, r=None):
if r is None:
r = len(A)-1
x = A[r]
i = p-1
for j in range(p,r):
while A[j] <= x:
i += 1
swap(A,i,j)
swap(A,i+1,r)
return i+1
if __name__ == "__main__":
input()
... |
s760473715 | p02276 | u918276501 | 1507978050 | Python | Python3 | py | Runtime Error | 20 | 7664 | 465 | def swap(A,i,j):
A[i],A[j] = A[j],A[i]
return A
def partition(A,p=0, r=None):
if r is None:
r = len(A)-1
x = A[r]
i = p-1
for j in range(p,r):
while A[j] <= x:
i += 1
swap(A,i,j)
swap(A,i+1,r)
return i+1
if __name__ == "__main__":
input()
... |
s293091259 | p02276 | u024715419 | 1508301757 | Python | Python3 | py | Runtime Error | 0 | 0 | 222 | n = int(input())
a = list(map(int,input().split()))
x = a[-1]
i = -1
for j in range(len(a)-1):
if a[j] <= x:
i += 1
a[i], a[j] = a[j], a[i]
a[i + 1], a[n] = "[" + str(a[n]) + "]", a[i + 1]
print(*a) |
s234753546 | p02276 | u150984829 | 1518707515 | Python | Python3 | py | Runtime Error | 0 | 0 | 213 | n=int(input())-1
A=list(map(int,input().split()))
i=0
for j in range(n):
if A[j]<=A[-1]:A[i],A[j]=A[j],A[i];i+=1
A[i],A[n]=A[n],A[i]
print(" ".join(map(str,A[:k]))+" ["+str(A[i])+"] "+" ".join(map(str,A[k+1:])))
|
s472070148 | p02276 | u150984829 | 1520050949 | Python | Python3 | py | Runtime Error | 0 | 0 | 253 | def s():
n=int(input())-1
A=list(map(int,input().split()))
i=0
for j in range(n):A[j]<=A[-1]and A[i],A[j]=A[j],A[i];i+=1
A[i],A[n]=A[n],A[i]
print(" ".join(map(str,A[:i]))+" ["+str(A[i])+"] "+" ".join(map(str,A[i+1:])))
if'__main__'==__name__:s()
|
s937400055 | p02276 | u559106458 | 1529402274 | Python | Python3 | py | Runtime Error | 0 | 0 | 469 | MAX=100000
list=[]
def partition(p,r):
t=0
x=list[r]
i=p-1
j=p
while(j<r):
if(int(list[j])<=x):
i+=1
t=int(list[i])
list[i]=list[j]
list[j]=t
j+=1
t=int(list[i+1])
list[i+1]=list[r]
list[r]=t
return i+1
n=int(input())
i=0
while(i<n):
list.append(int(input()))
i+=1
q=partition(0,n-1)
i=0... |
s268990490 | p02276 | u559106458 | 1529402634 | Python | Python3 | py | Runtime Error | 0 | 0 | 531 | list=[]
def partition(p,r):
t=0
x=list[r]
i=p-1
j=p
while(j<r):
if(int(list[j])<=x):
i+=1
t=int(list[i])
list[i]=list[j]
list[j]=t
j+=1
t=int(list[i+1])
list[i+1]=list[r]
list[r]=t
return i+1
def main():
n=int(input())
i=0
while(i<n):
list.append(int(input()))
i+=1
q=partition(0,n-... |
s017832533 | p02276 | u559106458 | 1529402914 | Python | Python3 | py | Runtime Error | 0 | 0 | 531 | list=[]
def partition(p,r):
t=0
x=list[r]
i=p-1
j=p
while(j<r):
if(int(list[j])<=x):
i+=1
t=int(list[i])
list[i]=list[j]
list[j]=t
j+=1
t=int(list[i+1])
list[i+1]=list[r]
list[r]=t
return i+1
def main():
n=int(input())
i=0
while(i<n):
list.append(int(input()))
i+=1
q=partition(0,n-... |
s259190785 | p02276 | u559106458 | 1529403676 | Python | Python3 | py | Runtime Error | 0 | 0 | 539 | list=[]
def partition(p,r):
t=0
x=list[r]
i=p-1
j=p
while(j<r):
if(int(list[j])<=x):
i+=1
t=int(list[i])
list[i]=list[j]
list[j]=t
j+=1
t=int(list[i+1])
list[i+1]=list[r]
list[r]=t
return i+1
def main():
n=int(input())
i=0
while(i<n):
list.append(int(input().split()))
i+=1
q=partit... |
s828433104 | p02277 | u153665391 | 1532150242 | Python | Python3 | py | Runtime Error | 40 | 6344 | 1486 | import copy
def partition(p, r):
i = p
for j in range(p, r):
if A[r][1] >= A[j][1]:
A[i], A[j] = A[j], A[i]
i += 1
A[r], A[i] = A[i], A[r]
return i
def quick_sort(p, r):
if p < r:
q = partition(p, r)
quick_sort(p, q-1)
quick_sort(q+1, r)
def... |
s351724737 | p02277 | u363774867 | 1556201932 | Python | Python3 | py | Runtime Error | 0 | 0 | 1242 | import copy
INF = 10000000000
def merge(A, left, mid, right):
count = 0
L = A[left:mid] + [(INF,INF)]
R = A[mid:right] + [(INF,INF)]
i, j = 0, 0
for k in range(left, right):
count = count + 1
if L[i][1] <= R[j][1]:
A[k] = L[i]
i = i + 1
else:
... |
s609627580 | p02277 | u363774867 | 1556202310 | Python | Python3 | py | Runtime Error | 0 | 0 | 1247 | import copy
INF = 10000000000
def merge(A, left, mid, right):
count = 0
L = A[left:mid] + [(INF,INF)]
R = A[mid:right] + [(INF,INF)]
i, j = 0, 0
for k in range(left, right):
count = count + 1
if L[i][1] <= R[j][1]:
A[k] = L[i]
i = i + 1
else:
... |
s981716302 | p02277 | u363774867 | 1556202363 | Python | Python3 | py | Runtime Error | 0 | 0 | 1245 | import copy
INF = 10000000000
def merge(A, left, mid, right):
count = 0
L = A[left:mid] + [(INF,INF)]
R = A[mid:right] + [(INF,INF)]
i, j = 0, 0
for k in range(left, right):
count = count + 1
if L[i][1] <= R[j][1]:
A[k] = L[i]
i = i + 1
else:
... |
s574950056 | p02277 | u805716376 | 1556771183 | Python | Python3 | py | Runtime Error | 0 | 0 | 777 | a = []
n = int(input())
for _ in range(n):
s, i = input().split()
a += [(s, int(i))]
b.setdefault(int(d), []).append(v)
b = {val: iter(s).__next__ for val, s in D.items()}
def partition(a, left, right):
standard = a[right][1]
cnt = left
for i in range(left, right):
if a[i][1] <= standar... |
s086753553 | p02277 | u805716376 | 1556771233 | Python | Python3 | py | Runtime Error | 0 | 0 | 784 | a = []
b = {}
n = int(input())
for _ in range(n):
s, i = input().split()
a += [(s, int(i))]
b.setdefault(int(d), []).append(v)
b = {val: iter(s).__next__ for val, s in D.items()}
def partition(a, left, right):
standard = a[right][1]
cnt = left
for i in range(left, right):
if a[i][1] <= ... |
s403333794 | p02277 | u805716376 | 1556771279 | Python | Python3 | py | Runtime Error | 0 | 0 | 784 | a = []
b = {}
n = int(input())
for _ in range(n):
s, i = input().split()
a += [(s, int(i))]
b.setdefault(int(i), []).append(s)
b = {val: iter(s).__next__ for val, s in D.items()}
def partition(a, left, right):
standard = a[right][1]
cnt = left
for i in range(left, right):
if a[i][1] <= ... |
s067568932 | p02277 | u567380442 | 1421672814 | Python | Python3 | py | Runtime Error | 0 | 0 | 737 | def partition(a, p, r):
q = p
for i in range(p, r):
if a[i][1] <= a[r][1]:
a[q], a[i] = a[i], a[q]
q += 1
a[q], a[r] = a[r], a[q]
return q
def quicksort(a, p, r):
if p < r:
q = partition(a, p, r)
quicksort(a, p, q-1)
quicksort(a, q+1, r)
de... |
s359738590 | p02277 | u885889402 | 1442389202 | Python | Python3 | py | Runtime Error | 0 | 0 | 832 | def partition(a,p,r):
x=int(a[r][1:])
i=p-1
for j in range(p,r):
if(int(a[j][1:])<=x):
i+=1
a[i],a[j]=a[j],a[i]
a[i+1],a[r]=a[r],a[i+1]
return i+1
def quicksort(a,p,r):
if(p<r):
q=partition(a,p,r)
quicksort(a,p,q-1)
quicksort(a,q+1,r)
a=[... |
s080917881 | p02277 | u894381890 | 1442389923 | Python | Python | py | Runtime Error | 10 | 6364 | 1446 | import sys
def partition(A, p, r):
x = int(A[r][1])
i = p - 1
for j in range(p, r):
if int(A[j][1]) <= x:
i = i + 1
A[i], A[j] = A[j], A[i]
A[i + 1], A[r] = A[r], A[i + 1]
return i + 1
def quickSort(A, p, r):
if p < r:
q = partition(A, p, r)
quickSort(A, p, q - 1)
quickSort(A,... |
s890525307 | p02277 | u253463900 | 1442476760 | Python | Python3 | py | Runtime Error | 0 | 0 | 1496 | def Partition(A,p,r):
x = A[r]
i = p-1
for j in range(p,r):
if (A[j] <= x):
i += 1
A[i],A[j] = A[j],A[i]
A[i+1],A[r] = A[r],A[i+1]
return i+1
def qsort(A,p,r):
if p < r:
q = Partition(A,p,r)
qsort(A,p,q-1)
qsort(A,q+1,r)
class card(object... |
s449351581 | p02277 | u313994256 | 1442583714 | Python | Python | py | Runtime Error | 0 | 0 | 1519 | def mergesort(A, left, right):
if left + 1 < right:
mid = (left + right)/2
mergesort(A, left, mid)
mergesort(A, mid, right)
merge(A, left, mid, right)
def merge(A, left, mid, right):
n1 = mid -left
n2 = right - mid
L = []
R = []
x = [" "," ", 10000... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.