-
Notifications
You must be signed in to change notification settings - Fork 0
/
mohanty.py
145 lines (104 loc) · 3.04 KB
/
mohanty.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
from functools import reduce
from determinant import det
from matrix import mat , transpose , reverse , show , subscripts , parse
from combinatorics import C
from information import comparator
def mohanty ( compare , Mo , m , n ) :
"""
>>> compare = comparator( [ ] )
>>> Mo = mat( 0 , 0 )
>>> mohanty( compare , Mo , 0 , 0 )
>>> abs( det( Mo , 0 ) )
1
>>> compare = comparator( [ [ ] , [ ] , [ ] ] )
>>> Mo = mat( 3 , 3 )
>>> mohanty( compare , Mo , 3 , 0 )
>>> abs( det( Mo , 3 ) )
1
>>> compare = comparator( [ [ -1 ] ] )
>>> Mo = mat( 1 , 1 )
>>> mohanty( compare , Mo , 1 , 1 )
>>> abs( det( Mo , 1 ) )
1
>>> compare = comparator( [ [ 1 ] ] )
>>> Mo = mat( 1 , 1 )
>>> mohanty( compare , Mo , 1 , 1 )
>>> abs( det( Mo , 1 ) )
1
>>> compare = comparator( [ [ 0 ] ] )
>>> Mo = mat( 1 , 1 )
>>> mohanty( compare , Mo , 1 , 1 )
>>> abs( det( Mo , 1 ) )
2
>>> compare = comparator( [ [ 0 , 0 ] , [ 0 , 0 ] ] )
>>> Mo = mat( 2 , 2 )
>>> mohanty( compare , Mo , 2 , 2 )
>>> abs( det( Mo , 2 ) )
6
>>> compare = comparator( [ [ 0 , 0 ] , [ 0 , 0 ] ] )
>>> Mo = mat( 2 , 2 )
>>> mohanty( compare , Mo , 2 , 2 )
>>> abs( det( Mo , 2 ) )
6
>>> compare = comparator( [ [ 1 , 0 ] , [ 1 , 0 ] ] )
>>> Mo = mat( 2 , 2 )
>>> mohanty( compare , Mo , 2 , 2 )
>>> abs( det( Mo , 2 ) )
3
>>> compare = comparator( [ [ -1 , -1 ] , [ -1 , -1 ] ] )
>>> Mo = mat( 2 , 2 )
>>> mohanty( compare , Mo , 2 , 2 )
>>> abs( det( Mo , 2 ) )
1
>>> compare = comparator( [ [ -1 , -1 ] , [ 0 , 0 ] ] )
>>> Mo = mat( 2 , 2 )
>>> mohanty( compare , Mo , 2 , 2 )
>>> abs( det( Mo , 2 ) )
3
>>> compare = comparator( [ [ 1 , 1 ] , [ 1 , 1 ] ] )
>>> Mo = mat( 2 , 2 )
>>> mohanty( compare , Mo , 2 , 2 )
>>> abs( det( Mo , 2 ) )
1
>>> compare = comparator( [ [ 0 , -1 ] , [ 1 , 0 ] ] )
>>> Mo = mat( 2 , 2 )
>>> mohanty( compare , Mo , 2 , 2 )
>>> abs( det( Mo , 2 ) )
4
>>> compare = comparator( [ [ 0 , -1 ] , [ 1 , 1 ] ] )
>>> Mo = mat( 2 , 2 )
>>> mohanty( compare , Mo , 2 , 2 )
>>> abs( det( Mo , 2 ) )
2
>>> compare = comparator( [ [ -1 , -1 ] , [ 1 , 0 ] ] )
>>> Mo = mat( 2 , 2 )
>>> mohanty( compare , Mo , 2 , 2 )
>>> abs( det( Mo , 2 ) )
2
"""
for i , j in subscripts( 0 , m , 0 , m ) :
b = reduce( min , ( t + 1 for t in range( n ) if compare( i , t ) < 0 ) , n + 1 )
a = reduce( max , ( t + 1 for t in range( n ) if compare( j , t ) > 0 ) , 0 )
Mo[i][j] = C( b - a , j - i + 1 )
def compute ( compare , m , n ) :
Mo = mat( m , m )
mohanty( compare , Mo , m , n )
print( "mohanty matrix" )
print( show( Mo ) , end = "" )
d = det( Mo , m )
print( "after gaussian elimination" )
print( show( Mo ) , end = "" )
return d
def main ( lines ) :
M , m , n = parse( lines )
if n > m :
M = transpose( M , m , n )
reverse( M )
m , n = n , m
print( "partial information" )
print( show( M ) , end = "" )
compare = comparator( M )
print( compute( compare , m , n ) )
if __name__ == "__main__" :
import fileinput
main( fileinput.input( ) )