Skip to content

Commit ea050d6

Browse files
committed
649 added
1 parent 9bea68e commit ea050d6

File tree

24 files changed

+539
-0
lines changed

24 files changed

+539
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"mainSolution": {
3+
"value": "/Users/dipta007/my-world/gdrive/Programming/Contest-LIFE/@SITES/acmx/Codeforces - Codeforces Round #649 (Div. 2)/A. XXXXX/template.py"
4+
},
5+
"bruteSolution": {},
6+
"generator": {},
7+
"checker": {}
8+
}
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
""" Python 3 compatibility tools. """
2+
from __future__ import division, print_function
3+
import itertools
4+
import sys
5+
import os
6+
from io import BytesIO, IOBase
7+
8+
9+
if sys.version_info[0] < 3:
10+
input = raw_input
11+
range = xrange
12+
13+
filter = itertools.ifilter
14+
map = itertools.imap
15+
zip = itertools.izip
16+
17+
18+
def is_it_local():
19+
script_dir = str(os.getcwd()).split('/')
20+
username = "dipta007"
21+
return username in script_dir
22+
23+
24+
def READ(fileName):
25+
if is_it_local():
26+
sys.stdin = open(f'./{fileName}', 'r')
27+
28+
# region fastio
29+
BUFSIZE = 8192
30+
31+
class FastIO(IOBase):
32+
newlines = 0
33+
34+
def __init__(self, file):
35+
self._fd = file.fileno()
36+
self.buffer = BytesIO()
37+
self.writable = "x" in file.mode or "r" not in file.mode
38+
self.write = self.buffer.write if self.writable else None
39+
40+
def read(self):
41+
while True:
42+
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
43+
if not b:
44+
break
45+
ptr = self.buffer.tell()
46+
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
47+
self.newlines = 0
48+
return self.buffer.read()
49+
50+
def readline(self):
51+
while self.newlines == 0:
52+
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
53+
self.newlines = b.count(b"\n") + (not b)
54+
ptr = self.buffer.tell()
55+
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
56+
self.newlines -= 1
57+
return self.buffer.readline()
58+
59+
def flush(self):
60+
if self.writable:
61+
os.write(self._fd, self.buffer.getvalue())
62+
self.buffer.truncate(0), self.buffer.seek(0)
63+
64+
65+
class IOWrapper(IOBase):
66+
def __init__(self, file):
67+
self.buffer = FastIO(file)
68+
self.flush = self.buffer.flush
69+
self.writable = self.buffer.writable
70+
self.write = lambda s: self.buffer.write(s.encode("ascii"))
71+
self.read = lambda: self.buffer.read().decode("ascii")
72+
self.readline = lambda: self.buffer.readline().decode("ascii")
73+
74+
if not is_it_local():
75+
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
76+
input = lambda: sys.stdin.readline().rstrip("\r\n")
77+
78+
# endregion
79+
80+
81+
def input1(type=int):
82+
return type(input())
83+
84+
85+
def input2(type=int):
86+
[a, b] = list(map(type, input().split()))
87+
return a, b
88+
89+
90+
def input3(type=int):
91+
[a, b, c] = list(map(type, input().split()))
92+
return a, b, c
93+
94+
95+
def input_array(type=int):
96+
return list(map(type, input().split()))
97+
98+
99+
def input_string():
100+
s = input()
101+
return list(s)
102+
103+
if is_it_local():
104+
def debug(*args):
105+
st = ""
106+
for arg in args:
107+
st += f"{arg} "
108+
print(st)
109+
else:
110+
def debug(*args):
111+
pass
112+
113+
##############################################################
114+
115+
def main():
116+
t = input1()
117+
for ci in range(t):
118+
n, k = input2()
119+
arr = input_array()
120+
cum = 0
121+
cum_a = []
122+
cum_a.append(cum)
123+
124+
for v in arr:
125+
cum += v
126+
cum %= k
127+
cum_a.append(cum)
128+
129+
last = cum_a[-1]
130+
ind = -1
131+
for i, v in enumerate(cum_a):
132+
if v != last:
133+
ind = i
134+
135+
res = -1
136+
for i in range(1, len(cum_a)):
137+
nw = cum_a[i-1]
138+
# debug(i, nw, last, ind, res)
139+
if last == nw and ind != -1:
140+
res = max(res, ind - i + 1)
141+
elif last != nw:
142+
res = max(res, len(cum_a) - i)
143+
144+
print(res)
145+
146+
pass
147+
148+
if __name__ == '__main__':
149+
# READ('in.txt')
150+
main()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2
2+
3
3+
-1
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
3
2+
3 3
3+
1 2 3
4+
3 4
5+
1 2 3
6+
2 2
7+
0 6
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2
2+
3
3+
-1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"mainSolution": {
3+
"value": "/Users/dipta007/my-world/gdrive/Programming/Contest-LIFE/@SITES/acmx/Codeforces - Codeforces Round #649 (Div. 2)/B. Most socially-distanced subsequence/template.py"
4+
},
5+
"bruteSolution": {},
6+
"generator": {},
7+
"checker": {}
8+
}
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
""" Python 3 compatibility tools. """
2+
from __future__ import division, print_function
3+
import itertools
4+
import sys
5+
import os
6+
from io import BytesIO, IOBase
7+
8+
9+
if sys.version_info[0] < 3:
10+
input = raw_input
11+
range = xrange
12+
13+
filter = itertools.ifilter
14+
map = itertools.imap
15+
zip = itertools.izip
16+
17+
18+
def is_it_local():
19+
script_dir = str(os.getcwd()).split('/')
20+
username = "dipta007"
21+
return username in script_dir
22+
23+
24+
def READ(fileName):
25+
if is_it_local():
26+
sys.stdin = open(f'./{fileName}', 'r')
27+
28+
# region fastio
29+
BUFSIZE = 8192
30+
31+
class FastIO(IOBase):
32+
newlines = 0
33+
34+
def __init__(self, file):
35+
self._fd = file.fileno()
36+
self.buffer = BytesIO()
37+
self.writable = "x" in file.mode or "r" not in file.mode
38+
self.write = self.buffer.write if self.writable else None
39+
40+
def read(self):
41+
while True:
42+
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
43+
if not b:
44+
break
45+
ptr = self.buffer.tell()
46+
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
47+
self.newlines = 0
48+
return self.buffer.read()
49+
50+
def readline(self):
51+
while self.newlines == 0:
52+
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
53+
self.newlines = b.count(b"\n") + (not b)
54+
ptr = self.buffer.tell()
55+
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
56+
self.newlines -= 1
57+
return self.buffer.readline()
58+
59+
def flush(self):
60+
if self.writable:
61+
os.write(self._fd, self.buffer.getvalue())
62+
self.buffer.truncate(0), self.buffer.seek(0)
63+
64+
65+
class IOWrapper(IOBase):
66+
def __init__(self, file):
67+
self.buffer = FastIO(file)
68+
self.flush = self.buffer.flush
69+
self.writable = self.buffer.writable
70+
self.write = lambda s: self.buffer.write(s.encode("ascii"))
71+
self.read = lambda: self.buffer.read().decode("ascii")
72+
self.readline = lambda: self.buffer.readline().decode("ascii")
73+
74+
if not is_it_local():
75+
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
76+
input = lambda: sys.stdin.readline().rstrip("\r\n")
77+
78+
# endregion
79+
80+
81+
def input1(type=int):
82+
return type(input())
83+
84+
85+
def input2(type=int):
86+
[a, b] = list(map(type, input().split()))
87+
return a, b
88+
89+
90+
def input3(type=int):
91+
[a, b, c] = list(map(type, input().split()))
92+
return a, b, c
93+
94+
95+
def input_array(type=int):
96+
return list(map(type, input().split()))
97+
98+
99+
def input_string():
100+
s = input()
101+
return list(s)
102+
103+
if is_it_local():
104+
def debug(*args):
105+
st = ""
106+
for arg in args:
107+
st += f"{arg} "
108+
print(st)
109+
else:
110+
def debug(*args):
111+
pass
112+
113+
##############################################################
114+
115+
arr = []
116+
n = 0
117+
mp = {}
118+
119+
from collections import deque
120+
121+
def main():
122+
t = input1()
123+
for ci in range(t):
124+
global arr, n, mp
125+
n = input1()
126+
arr = input_array()
127+
# print(arr)
128+
129+
res = [arr[i] for i in range(n) if i==0 or i == n-1 or arr[i-1] > arr[i] < arr[i+1] or arr[i-1] < arr[i] > arr[i+1]]
130+
print(len(res))
131+
print(*res)
132+
# print(" ".join([str(x) for x in res]))
133+
134+
135+
pass
136+
137+
if __name__ == '__main__':
138+
# READ('in.txt')
139+
main()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2
2+
3 1
3+
3
4+
1 4 2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
3
2+
7 1 5
3+
2
4+
1 2
5+
2
6+
2 1
7+
3
8+
1 4 2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
4
2+
7
3+
7 6 3 2 1 4 5
4+
2
5+
1 2
6+
2
7+
2 1
8+
4
9+
1 4 3 2

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy