結果

問題 No.453 製薬会社
ユーザー Yuki_UtaaiYuki_Utaai
提出日時 2018-03-25 18:36:55
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 18 ms / 2,000 ms
コード長 1,277 bytes
コンパイル時間 90 ms
コンパイル使用メモリ 10,904 KB
実行使用メモリ 8,100 KB
最終ジャッジ日時 2023-09-07 11:59:57
合計ジャッジ時間 1,135 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,072 KB
testcase_01 AC 17 ms
7,960 KB
testcase_02 AC 16 ms
8,060 KB
testcase_03 AC 17 ms
7,992 KB
testcase_04 AC 16 ms
8,028 KB
testcase_05 AC 17 ms
8,076 KB
testcase_06 AC 16 ms
8,016 KB
testcase_07 AC 17 ms
8,028 KB
testcase_08 AC 17 ms
8,040 KB
testcase_09 AC 17 ms
8,100 KB
testcase_10 AC 17 ms
8,032 KB
testcase_11 AC 16 ms
7,964 KB
testcase_12 AC 16 ms
8,032 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

c,d=[int(i) for i in input().split()]

gyou=5
retsu=7

matrix=[[0 for i in range(retsu)] for j in range(gyou)]

#評価関数
matrix[0][0], matrix[0][1]= -1000, -2000 
#x, yは正
matrix[3][0], matrix[4][1]= -1, -1 

#薬品の使用量
matrix[1][0], matrix[1][1]= 3/4, 2/7
matrix[2][0], matrix[2][1]= 1/4, 5/7
#定数項
matrix[1][6], matrix[2][6]=c, d
#スラック変数
matrix[1][2]=1
matrix[2][3]=1
matrix[3][4]=1
matrix[4][5]=1

for i in range(10):
    if min(matrix[0])>=0:
        break
    else:
        p_column=min(enumerate(matrix[0]), key=lambda x: x[1])[0]
        const_per_p=[10**6 for i in range(gyou)]

        for j in range(gyou):
            if matrix[j][p_column]>0:
                const_per_p[j]=matrix[j][6]/matrix[j][p_column]

        k_row=min(enumerate(const_per_p), key=lambda x: x[1])[0]
        pivot=matrix[k_row][p_column]

    new_matrix=[[0 for i in range(retsu)] for j in range(gyou)]
    for l in range(gyou):
        for j in range(retsu):
            if l==k_row:
                new_matrix[l][j]/=pivot
            else:
                new_matrix[l][j]=matrix[l][j]-matrix[l][p_column]*matrix[k_row][j]/pivot
     
    matrix=new_matrix[:][:]


#    print(k_row, p_column)

#for i in range(5):
#    print(matrix[i])
print(matrix[0][6])
0