QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#334280#1364. CondorcetchmproWA 11ms9984kbPython3669b2024-02-21 16:53:332024-02-21 16:53:33

Judging History

你现在查看的是最新测评结果

  • [2024-02-21 16:53:33]
  • 评测
  • 测评结果:WA
  • 用时:11ms
  • 内存:9984kb
  • [2024-02-21 16:53:33]
  • 提交

answer

import itertools
import sys
input=sys.stdin.readline
N,M=map(int,input().split())
G=[[0]*N for _ in range(N)]
for _ in range(M):
  s,k=input().split();k=int(k)
  for i in range(N):
    for j in range(i+1,N):
      G[ord(s[i])-65][ord(s[j])-65]+=k
      G[ord(s[j])-65][ord(s[i])-65]-=k

ans=1e9
for r in range(3,N+1):
  for nCr in itertools.combinations(range(N),r):
    for perm in itertools.permutations(range(1,r)):
      A=[nCr[0]]
      for i in perm:A.append(nCr[i])
      B=[0]*r
      for i in range(r):B[i]=G[A[i-1]][A[i]]
      s=sum(B)
      t=0
      if s<0:t=(r-s-1)//(r-1)+1
      t=max(t,1-min(B))
      ans=min(ans,t)
print(ans)

詳細信息

Test #1:

score: 100
Accepted
time: 11ms
memory: 9904kb

input:

3 3
ABC 1
BCA 1
CAB 1

output:

0

result:

ok single line: '0'

Test #2:

score: 0
Accepted
time: 11ms
memory: 9972kb

input:

3 6
CAB 35
ACB 142
ABC 34
BCA 66
CBA 53
BAC 44

output:

49

result:

ok single line: '49'

Test #3:

score: 0
Accepted
time: 4ms
memory: 9880kb

input:

3 6
BCA 41
ABC 103
ACB 49
BAC 79
CAB 52
CBA 57

output:

66

result:

ok single line: '66'

Test #4:

score: 0
Accepted
time: 7ms
memory: 9792kb

input:

3 6
CBA 49
BAC 50
ABC 64
ACB 98
BCA 35
CAB 70

output:

69

result:

ok single line: '69'

Test #5:

score: 0
Accepted
time: 4ms
memory: 9984kb

input:

3 5
BCA 102
BAC 89
ACB 77
CAB 43
ABC 69

output:

91

result:

ok single line: '91'

Test #6:

score: 0
Accepted
time: 6ms
memory: 9792kb

input:

5 120
DEABC 125
DACBE 207
DABCE 167
BCDEA 186
BCEDA 118
AEBDC 175
CDBEA 252
CDEBA 208
ABCED 131
ADEBC 114
ABECD 132
CDAEB 365
BEADC 162
BEDAC 169
ECDBA 242
ECDAB 137
CEADB 215
EBDAC 179
EBADC 222
DABEC 248
EDBAC 177
DBEAC 207
EDACB 157
ECABD 67
DCBEA 143
BDECA 174
DACEB 195
AECDB 242
ABCDE 156
CABDE...

output:

0

result:

ok single line: '0'

Test #7:

score: -100
Wrong Answer
time: 8ms
memory: 9856kb

input:

4 22
CDAB 27
DABC 114
CADB 126
BCDA 51
CABD 58
BACD 16
DACB 87
DCAB 25
BADC 88
CBDA 31
ACBD 82
BCAD 45
CBAD 58
ADCB 26
DBCA 20
DBAC 85
ABCD 27
ADBC 28
BDAC 17
DCBA 44
ABDC 60
ACDB 11

output:

61

result:

wrong answer 1st lines differ - expected: '125', found: '61'