Submission #65475854
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):
prob = pulp.LpProblem("MinimizeSumA", pulp.LpMinimize)
A = [pulp.LpVariable(f"A_{i}", lowBound=1, cat='Integer') for i in range(N)]
prob += pulp.lpSum(A)
for i in range(M):
prob += pulp.lpSum(A[L[i]-1:R[i]]) == S[i]
result = prob.solve(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, []
N,M = _M()
L = [0]*M
R = [0]*M
S = [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("Minimum Sum:", min_sum)
print("A Sequence:", A_sequence)
Submission Info
| Submission Time |
|
| Task |
G - Specified Range Sums |
| User |
potat_p |
| Language |
Python (PyPy 3.10-v7.3.12) |
| Score |
0 |
| Code Size |
4790 Byte |
| Status |
RE |
| Exec Time |
1746 ms |
| Memory |
312964 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 |
RE |
455 ms |
106804 KiB |
| sample_02.txt |
RE |
384 ms |
106356 KiB |
| sample_03.txt |
RE |
385 ms |
106688 KiB |
| test_01.txt |
RE |
377 ms |
106140 KiB |
| test_02.txt |
RE |
386 ms |
106580 KiB |
| test_03.txt |
RE |
384 ms |
106452 KiB |
| test_04.txt |
RE |
406 ms |
110384 KiB |
| test_05.txt |
RE |
413 ms |
110324 KiB |
| test_06.txt |
RE |
411 ms |
110340 KiB |
| test_07.txt |
RE |
413 ms |
110356 KiB |
| test_08.txt |
RE |
404 ms |
110384 KiB |
| test_09.txt |
RE |
499 ms |
113940 KiB |
| test_10.txt |
RE |
507 ms |
114112 KiB |
| test_11.txt |
RE |
387 ms |
106476 KiB |
| test_12.txt |
RE |
392 ms |
106708 KiB |
| test_13.txt |
RE |
411 ms |
110224 KiB |
| test_14.txt |
RE |
427 ms |
112092 KiB |
| test_15.txt |
RE |
424 ms |
111160 KiB |
| test_16.txt |
RE |
432 ms |
112580 KiB |
| test_17.txt |
RE |
396 ms |
110052 KiB |
| test_18.txt |
RE |
386 ms |
106512 KiB |
| test_19.txt |
RE |
425 ms |
111152 KiB |
| test_20.txt |
RE |
416 ms |
111152 KiB |
| test_21.txt |
RE |
423 ms |
111132 KiB |
| test_22.txt |
RE |
437 ms |
112564 KiB |
| test_23.txt |
RE |
386 ms |
106544 KiB |
| test_24.txt |
RE |
385 ms |
106748 KiB |
| test_25.txt |
RE |
403 ms |
110052 KiB |
| test_26.txt |
RE |
388 ms |
106652 KiB |
| test_27.txt |
RE |
404 ms |
110040 KiB |
| test_28.txt |
RE |
407 ms |
110248 KiB |
| test_29.txt |
RE |
383 ms |
106580 KiB |
| test_30.txt |
RE |
385 ms |
106588 KiB |
| test_31.txt |
RE |
735 ms |
150432 KiB |
| test_32.txt |
RE |
530 ms |
124292 KiB |
| test_33.txt |
RE |
1583 ms |
290192 KiB |
| test_34.txt |
RE |
882 ms |
171468 KiB |
| test_35.txt |
RE |
504 ms |
113628 KiB |
| test_36.txt |
RE |
460 ms |
110176 KiB |
| test_37.txt |
RE |
501 ms |
114684 KiB |
| test_38.txt |
RE |
414 ms |
110948 KiB |
| test_39.txt |
RE |
1060 ms |
206868 KiB |
| test_40.txt |
RE |
440 ms |
114076 KiB |
| test_41.txt |
RE |
380 ms |
106648 KiB |
| test_42.txt |
RE |
394 ms |
106592 KiB |
| test_43.txt |
RE |
474 ms |
112684 KiB |
| test_44.txt |
RE |
444 ms |
111524 KiB |
| test_45.txt |
RE |
514 ms |
114328 KiB |
| test_46.txt |
RE |
511 ms |
114132 KiB |
| test_47.txt |
RE |
440 ms |
109880 KiB |
| test_48.txt |
RE |
414 ms |
109304 KiB |
| test_49.txt |
RE |
1029 ms |
196808 KiB |
| test_50.txt |
RE |
1612 ms |
295956 KiB |
| test_51.txt |
RE |
1746 ms |
312964 KiB |
| test_52.txt |
RE |
1642 ms |
304020 KiB |
| test_53.txt |
RE |
402 ms |
109436 KiB |
| test_54.txt |
RE |
388 ms |
106508 KiB |
| test_55.txt |
RE |
787 ms |
157500 KiB |
| test_56.txt |
RE |
1249 ms |
228912 KiB |
| test_57.txt |
RE |
1694 ms |
305056 KiB |
| test_58.txt |
RE |
1655 ms |
302488 KiB |
| test_59.txt |
RE |
401 ms |
108896 KiB |
| test_60.txt |
RE |
388 ms |
106648 KiB |
| test_61.txt |
RE |
522 ms |
114640 KiB |
| test_62.txt |
RE |
654 ms |
139444 KiB |
| test_63.txt |
RE |
524 ms |
115504 KiB |
| test_64.txt |
RE |
545 ms |
119476 KiB |
| test_65.txt |
RE |
400 ms |
109776 KiB |
| test_66.txt |
RE |
387 ms |
106588 KiB |
| test_67.txt |
RE |
409 ms |
110288 KiB |
| test_68.txt |
RE |
411 ms |
110824 KiB |
| test_69.txt |
RE |
447 ms |
115224 KiB |
| test_70.txt |
RE |
432 ms |
112608 KiB |
| test_71.txt |
RE |
385 ms |
106520 KiB |
| test_72.txt |
RE |
403 ms |
109508 KiB |
| test_73.txt |
RE |
406 ms |
110104 KiB |
| test_74.txt |
RE |
419 ms |
111128 KiB |
| test_75.txt |
RE |
427 ms |
111412 KiB |
| test_76.txt |
RE |
428 ms |
111540 KiB |
| test_77.txt |
RE |
391 ms |
106744 KiB |
| test_78.txt |
RE |
384 ms |
106556 KiB |
| test_79.txt |
RE |
408 ms |
109988 KiB |
| test_80.txt |
RE |
408 ms |
110228 KiB |
| test_81.txt |
RE |
403 ms |
110244 KiB |
| test_82.txt |
RE |
415 ms |
110312 KiB |
| test_83.txt |
RE |
409 ms |
109596 KiB |
| test_84.txt |
RE |
382 ms |
106700 KiB |
| test_85.txt |
RE |
517 ms |
122292 KiB |
| test_86.txt |
RE |
1186 ms |
225168 KiB |
| test_87.txt |
RE |
1036 ms |
202268 KiB |
| test_88.txt |
RE |
650 ms |
144028 KiB |
| test_89.txt |
RE |
431 ms |
109604 KiB |
| test_90.txt |
RE |
486 ms |
114108 KiB |
| test_91.txt |
RE |
954 ms |
184672 KiB |