[ create a new paste ] login | about

Link: http://codepad.org/a0Ldgh9W    [ raw code | output | fork ]

Python, pasted on Mar 12:
import sys
import numpy as np
from gurobipy import *
def solve(filename):
    m = Model()
    n,A,B = map(int,input().split(' '))
    a_var = np.zeros(A,dtype=Var)
    na_var = np.zeros(A,dtype=Var)
    b_var = np.zeros(B,dtype=Var)
    nb_var = np.zeros(B,dtype=Var)
    z = np.zeros(n,dtype=Var)
    for i in range(A):
        a_var[i] = m.addVar(vtype=GRB.BINARY,name="a_"+str(i))
    for i in range(A):
        na_var[i] = m.addVar(vtype=GRB.BINARY,name="na_"+str(i))
    for i in range(B):
        b_var[i] = m.addVar(vtype=GRB.BINARY,name="b_"+str(i))
    for i in range(B):
        nb_var[i] = m.addVar(vtype=GRB.BINARY,name="nb_"+str(i))
    for i in range(n):
        z[i] = m.addVar(vtype=GRB.BINARY,name="z_"+str(i))
    m.update()
    for i in range(A):
        m.addConstr(a_var[i]+na_var[i]==1)
    for i in range(B):
        m.addConstr(b_var[i]+nb_var[i]==1)
    sum_satisfied = 0
    for i in range(n):
        s1,a,s2,b = map(int,input().split(' '))
        a -= 1;
        b -= 1;
        s1 -= 1
        s2 -= 1
        # print(s1,a,s2,b)
        cond = 0
        if(s1 == 0):
            cond += a_var[a]
            cond += (1-b_var[b])
        else:
            cond += b_var[a]
            cond += (1-a_var[b])
        m.addConstr(2*z[i] <= cond)
        
    m.setObjective(quicksum(z),GRB.MAXIMIZE)
    m.optimize()
    dudes_a = []
    dudes_b = []
    for i in range(A):
        if(a_var[i].X > 0):
            dudes_a.append(i+1)
    for i in range(B):
        if(b_var[i].X > 0):
            dudes_b.append(i+1)
    print(len(dudes_a),file=filename)
    print(' '.join(map(str,dudes_a)),file=filename)
    print(len(dudes_b),file=filename)
    print(' '.join(map(str,dudes_b)),file=filename)
t = int(input())
with open("output.txt","w") as filename:
    for i in range(t):
        solve(filename)


Output:
1
2
3
4
  Line 54
    print(len(dudes_a),file=filename)
                           ^
SyntaxError: invalid syntax


Create a new paste based on this one


Comments: