Submission #65492976
Source Code Expand
Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
import sys
import math
from copy import deepcopy as dc
sys.setrecursionlimit(10 ** 6)
from collections import defaultdict as dd
import heapq
from itertools import permutations as per
_S = input;_R = range;_P = print; _E = enumerate;
def _RR(a): return range(a-1,-1,-1)
def _I(): return int(_S())
def _M(): return map(int, _S().split())
def _SS(): return _S().strip().split()
def _L(): return list(_M())
def _T(): return list(_S())
def _O(): return list(map(int, open(0).read().split()))
def yn(b): print("Yes" if b else "No")
def fs(b): print("First" if b else "Second")
biga = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";smaa = "abcdefghijklmnopqrstuvwxyz"
ctoi = lambda c: ord(c) - ord('a')
ctoi2 = lambda c: ord(c) - ord('A')
itoc = lambda i: chr(ord('a') + i)
itoc2 = lambda i: chr(ord('A') + i)
inf = 10 ** 18
mod = 998244353
def around(x,y,type_=False):
rt = []
rt.extend([(x+1,y),(x-1,y),(x,y+1),(x,y-1)])
if type_:
rt.extend([(x+1,y+1),(x-1,y-1),(x-1,y+1),(x+1,y-1)])
return rt
def acc(a):
b = [0]
for i in a:
b.append(b[-1] + i)
return b
class heap:
l = []
def __init__(self,*s): self.l = list(s);heapq.heapify(self.l)
def min(self): return False if (len(self.l) == 0) else self.l[0]
def pop(self): return False if (len(self.l) == 0) else heapq.heappop(self.l)
def push(self,n): heapq.heappush(self.l,n)
def dump(self): return heapq.nsmallest(len(self.l),self.l)
def max(self): return False if (len(self.l) == 0) else heapq.nlargest(1,self.l)[0]
def len(self): return len(self.l)
class base:
bn = 0; dig = 0; num = []
def __init__(self,base_num,digit = 0):
self.bn = base_num; self.dig = digit; self.num = [0]*digit
def max(self): return(self.bn**self.dig-1)
def dump(self): return(self.num[::-1])
def ncp(self,digit,n): self.num[digit] = min(self.num[digit]+n,self.bn-1)
def plus(self,digit,n):
for i in _R(digit-self.dig+1): self.num.append(0)
self.dig = max(self.dig,digit+1)
if (self.num[digit]+n >= self.bn):
self.plus(digit+1,(self.num[digit]+n)//self.bn)
self.num[digit] = (self.num[digit]+n)%self.bn
def copy(self,n):
self.num = dc(n)
dig = len(self.num)
def change(self,n):
digit = int(math.log(n,self.bn))if n!=0 else 0+1
for i in _R(digit-self.dig+1): self.num.append(0)
self.dig = max(self.dig,digit+1)
for i in _R(self.dig):
self.num[i] = n%self.bn**(i+1)//self.bn**i
n -= self.num[i]
return self.dump()
def b10(self): return(sum([self.num[i]*self.bn**i for i in _R(self.dig)]))
def gin(N, M=None):
g = [[] for _ in range(N)]
for _ in range(N-1 if M is None else M):
u, v = map(int, input().split());u -= 1;v -= 1
g[u].append(v);g[v].append(u)
return g
def ginh(N, M):
g = [[] for _ in range(N)]
for i in range(M):
u, v, h = map(int, input().split());u -= 1;v -= 1
g[u].append((v,h));g[v].append((u,h))
return g
#from atcoder.segtree import SegTree
def ub(lis,n):
l = 0
r = len(lis)
while r-l>1:
m = (l+r)//2
if (lis[m]>n):
r = m
else:
l = m
return l
def msum(a, b):
return (a + b)
class rhash:
hs = None
def __init__(self,S,N):
self.hs = SegTree(msum,0,[ctoi(S[i])*pow(31,i,mod) for i in _R(N)])
def get(self,l,r):
return self.hs.prod(l,r+1)*pow(pow(31,l,mod),mod-2,mod)%mod
def getall(self):
return self.hs.all_prod()
def change(self,n,c):
self.hs.set(n,ctoi(c)*pow(31,n,mod))
def nwse(s,x,y,rev=False):
if (rev):
s = {"N":"S","S":"N","W":"E","E":"W"}[s]
if s=="N": return (x-1,y)
elif s=="W": return (x,y-1)
elif s=="S": return (x+1,y)
elif s=="E": return (x,y+1)
#--------------ごっつりしていってね--------------
#あぁそうそう ごちうさ楽しみ
import pulp
def solve(N, M, L, R, S):
# Create LP problem to minimize sum of A
prob = pulp.LpProblem("MinimizeSumA", pulp.LpMinimize)
# Define variables: A[1], ..., A[N], all positive integers (≥1)
A = [pulp.LpVariable(f"A_{i}", lowBound=1, cat='Integer') for i in range(N)]
# Objective: minimize sum of A
prob += pulp.lpSum(A)
# Constraints: for each i, sum A[L[i]-1 : R[i]] == S[i]
for i in range(M):
prob += pulp.lpSum(A[L[i]-1:R[i]]) == S[i]
# Solve without outputting messages
result = prob.solve(pulp.PULP_CBC_CMD(msg=False))
if pulp.LpStatus[result] == 'Optimal':
min_sum = pulp.value(prob.objective)
A_values = [int(pulp.value(var)) for var in A]
return min_sum, A_values
else:
return -1, [] # No valid sequence
# 使用例(必要に応じて入力を変更してください)
N,M = _M()
L,R,S = [0]*M,[0]*M,[0]*M
for i in _R(M):
L[i],R[i],S[i]=_M()
min_sum, A_sequence = solve(N, M, L, R, S)
print(int(min_sum))
Submission Info
Submission Time |
|
Task |
G - Specified Range Sums |
User |
potat_p |
Language |
Python (PyPy 3.10-v7.3.12) |
Score |
0 |
Code Size |
5099 Byte |
Status |
WA |
Exec Time |
2244 ms |
Memory |
598816 KiB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
0 / 600 |
Status |
|
|
Set Name |
Test Cases |
Sample |
sample_01.txt, sample_02.txt, sample_03.txt |
All |
sample_01.txt, sample_02.txt, sample_03.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt, test_20.txt, test_21.txt, test_22.txt, test_23.txt, test_24.txt, test_25.txt, test_26.txt, test_27.txt, test_28.txt, test_29.txt, test_30.txt, test_31.txt, test_32.txt, test_33.txt, test_34.txt, test_35.txt, test_36.txt, test_37.txt, test_38.txt, test_39.txt, test_40.txt, test_41.txt, test_42.txt, test_43.txt, test_44.txt, test_45.txt, test_46.txt, test_47.txt, test_48.txt, test_49.txt, test_50.txt, test_51.txt, test_52.txt, test_53.txt, test_54.txt, test_55.txt, test_56.txt, test_57.txt, test_58.txt, test_59.txt, test_60.txt, test_61.txt, test_62.txt, test_63.txt, test_64.txt, test_65.txt, test_66.txt, test_67.txt, test_68.txt, test_69.txt, test_70.txt, test_71.txt, test_72.txt, test_73.txt, test_74.txt, test_75.txt, test_76.txt, test_77.txt, test_78.txt, test_79.txt, test_80.txt, test_81.txt, test_82.txt, test_83.txt, test_84.txt, test_85.txt, test_86.txt, test_87.txt, test_88.txt, test_89.txt, test_90.txt, test_91.txt |
Case Name |
Status |
Exec Time |
Memory |
sample_01.txt |
AC |
369 ms |
106476 KiB |
sample_02.txt |
AC |
368 ms |
106560 KiB |
sample_03.txt |
AC |
372 ms |
106528 KiB |
test_01.txt |
AC |
368 ms |
106584 KiB |
test_02.txt |
AC |
371 ms |
106296 KiB |
test_03.txt |
AC |
371 ms |
106512 KiB |
test_04.txt |
WA |
725 ms |
116964 KiB |
test_05.txt |
AC |
461 ms |
117000 KiB |
test_06.txt |
AC |
455 ms |
116976 KiB |
test_07.txt |
AC |
452 ms |
116956 KiB |
test_08.txt |
AC |
444 ms |
114056 KiB |
test_09.txt |
AC |
588 ms |
123832 KiB |
test_10.txt |
WA |
588 ms |
123640 KiB |
test_11.txt |
AC |
374 ms |
106268 KiB |
test_12.txt |
AC |
389 ms |
109276 KiB |
test_13.txt |
AC |
480 ms |
115824 KiB |
test_14.txt |
AC |
570 ms |
127832 KiB |
test_15.txt |
AC |
565 ms |
126324 KiB |
test_16.txt |
AC |
606 ms |
135284 KiB |
test_17.txt |
AC |
395 ms |
110132 KiB |
test_18.txt |
AC |
374 ms |
106732 KiB |
test_19.txt |
AC |
579 ms |
127996 KiB |
test_20.txt |
AC |
540 ms |
120336 KiB |
test_21.txt |
AC |
570 ms |
121856 KiB |
test_22.txt |
AC |
734 ms |
143488 KiB |
test_23.txt |
WA |
373 ms |
106704 KiB |
test_24.txt |
WA |
376 ms |
106524 KiB |
test_25.txt |
WA |
454 ms |
112636 KiB |
test_26.txt |
AC |
390 ms |
109196 KiB |
test_27.txt |
WA |
457 ms |
115868 KiB |
test_28.txt |
WA |
453 ms |
115724 KiB |
test_29.txt |
AC |
369 ms |
106524 KiB |
test_30.txt |
AC |
373 ms |
106492 KiB |
test_31.txt |
TLE |
2240 ms |
529912 KiB |
test_32.txt |
AC |
1293 ms |
362032 KiB |
test_33.txt |
TLE |
2240 ms |
499948 KiB |
test_34.txt |
TLE |
2238 ms |
598816 KiB |
test_35.txt |
AC |
587 ms |
127420 KiB |
test_36.txt |
AC |
482 ms |
113876 KiB |
test_37.txt |
AC |
1066 ms |
198660 KiB |
test_38.txt |
AC |
507 ms |
119764 KiB |
test_39.txt |
TLE |
2242 ms |
523320 KiB |
test_40.txt |
AC |
690 ms |
165408 KiB |
test_41.txt |
AC |
372 ms |
106792 KiB |
test_42.txt |
WA |
378 ms |
106528 KiB |
test_43.txt |
TLE |
2217 ms |
132648 KiB |
test_44.txt |
WA |
506 ms |
115624 KiB |
test_45.txt |
TLE |
2218 ms |
145072 KiB |
test_46.txt |
WA |
648 ms |
123040 KiB |
test_47.txt |
AC |
458 ms |
111196 KiB |
test_48.txt |
AC |
416 ms |
110120 KiB |
test_49.txt |
TLE |
2241 ms |
526136 KiB |
test_50.txt |
TLE |
2240 ms |
505444 KiB |
test_51.txt |
TLE |
2239 ms |
476700 KiB |
test_52.txt |
TLE |
2241 ms |
501004 KiB |
test_53.txt |
AC |
390 ms |
109320 KiB |
test_54.txt |
AC |
374 ms |
106536 KiB |
test_55.txt |
TLE |
2243 ms |
568028 KiB |
test_56.txt |
TLE |
2241 ms |
510468 KiB |
test_57.txt |
TLE |
2241 ms |
503012 KiB |
test_58.txt |
TLE |
2240 ms |
497540 KiB |
test_59.txt |
WA |
396 ms |
109412 KiB |
test_60.txt |
WA |
378 ms |
106736 KiB |
test_61.txt |
WA |
681 ms |
125908 KiB |
test_62.txt |
TLE |
2233 ms |
385360 KiB |
test_63.txt |
WA |
661 ms |
124604 KiB |
test_64.txt |
WA |
1415 ms |
168796 KiB |
test_65.txt |
AC |
398 ms |
109720 KiB |
test_66.txt |
AC |
383 ms |
106588 KiB |
test_67.txt |
AC |
463 ms |
112908 KiB |
test_68.txt |
AC |
503 ms |
118356 KiB |
test_69.txt |
AC |
693 ms |
169580 KiB |
test_70.txt |
AC |
610 ms |
134984 KiB |
test_71.txt |
AC |
375 ms |
106760 KiB |
test_72.txt |
AC |
397 ms |
109668 KiB |
test_73.txt |
AC |
454 ms |
114260 KiB |
test_74.txt |
AC |
508 ms |
120792 KiB |
test_75.txt |
AC |
568 ms |
125076 KiB |
test_76.txt |
AC |
582 ms |
123248 KiB |
test_77.txt |
AC |
374 ms |
106620 KiB |
test_78.txt |
AC |
372 ms |
106552 KiB |
test_79.txt |
WA |
439 ms |
113280 KiB |
test_80.txt |
WA |
426 ms |
111788 KiB |
test_81.txt |
WA |
454 ms |
115812 KiB |
test_82.txt |
WA |
450 ms |
116084 KiB |
test_83.txt |
AC |
402 ms |
110176 KiB |
test_84.txt |
AC |
369 ms |
106768 KiB |
test_85.txt |
AC |
1249 ms |
339592 KiB |
test_86.txt |
TLE |
2239 ms |
510384 KiB |
test_87.txt |
TLE |
2243 ms |
549336 KiB |
test_88.txt |
TLE |
2244 ms |
577040 KiB |
test_89.txt |
AC |
445 ms |
111184 KiB |
test_90.txt |
AC |
575 ms |
127888 KiB |
test_91.txt |
TLE |
2240 ms |
548544 KiB |