Skip to content

Instantly share code, notes, and snippets.

@cocodrips
Created January 20, 2014 19:28
Show Gist options
  • Save cocodrips/8527363 to your computer and use it in GitHub Desktop.
Save cocodrips/8527363 to your computer and use it in GitHub Desktop.
CodeForces 225 Div2 B TLEなバブルソートver.ケース3は通るけど最大ケースが無理ぽ
def solve(n,m,k,data):
ans = []
if k == 1:
data = [[dd * -1 for dd in d] for d in data]
for i in xrange(n):
isSorted = False
while not isSorted:
swapCnt = 0
for j in xrange(m - 1):
if data[i][j] > data[i][j+1]:
swapCnt+=1
ans.append([str(j+1), str(j+2)])
for l in xrange(n):
if data[l][j] > data[l][j+1]:
tmp = data[l][j]
data[l][j] = data[l][j+1]
data[l][j+1] = tmp
break
if swapCnt == 0:
isSorted = True
print len(ans)
if k == 1:
for a in ans:
print ' '.join(a[::-1])
else:
for a in ans:
print ' '.join(a)
if __name__ == "__main__":
n, m, k = map(int, raw_input().split())
import time
time1 = time.clock()
data = []
for _ in xrange(n):
data.append(map(int, raw_input().split()))
# data = [[i for i in range(100)[::-1]] for i in xrange(1000)]
# solve(1000, 100, 0, data)
solve(n, m, k, data)
time2 = time.clock()
print time2 - time1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment