s_id stringlengths 10 10 | p_id stringlengths 6 6 | u_id stringlengths 10 10 | date stringlengths 10 10 | language stringclasses 1
value | original_language stringclasses 11
values | filename_ext stringclasses 1
value | status stringclasses 1
value | cpu_time stringlengths 1 5 | memory stringlengths 1 7 | code_size stringlengths 1 6 | code stringlengths 1 539k |
|---|---|---|---|---|---|---|---|---|---|---|---|
s874010880 | p03945 | u679154596 | 1586739895 | Python | Python (3.4.3) | py | Runtime Error | 78 | 4836 | 344 | S = list(input())
L = len(S)
def f(i, result):
if S[i] == S[i-1]:
if i == 1:
print(result)
exit()
else:
f(i-1, result)
else:
if i == 1:
result += 1
print(result)
exit()
else:
result += 1
f(i-1, result)
if L == 1:
result = 0
print(result)
exit()
else:
f(L-1, 0) |
s990396837 | p03945 | u539969758 | 1585803740 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3188 | 104 | S = input()
length = len(S)
ans = 0
for i in range(n-1):
if S[i] != S[i+1]:
ans += 1
print(ans) |
s767712674 | p03945 | u506858457 | 1583019384 | Python | Python (3.4.3) | py | Runtime Error | 48 | 3188 | 89 | S=input()
for i in range(len(S)-1):
cnt=0
if S[i]!=S[i+1]:
cnt+=1
print(cnt)
|
s672462313 | p03945 | u620157187 | 1582679619 | Python | Python (3.4.3) | py | Runtime Error | 22 | 5364 | 95 | S = input()
w = S.split('B')
w.remove('')
b = S.split('W')
b.remove('')
print(len(w)+len(b)-1) |
s142600578 | p03945 | u857070771 | 1580426550 | Python | Python (3.4.3) | py | Runtime Error | 56 | 5488 | 150 | s=input()
ans=[]
for i in range(len(s)-1):
if s[i] != s[i+1]:
ans.append(s[i])
if s[-1] != s[-2]:
ans.append(s[-1])
print(ans)
print(len(ans)-1)
|
s230377106 | p03945 | u813174766 | 1580179179 | Python | Python (3.4.3) | py | Runtime Error | 43 | 3188 | 83 | a=input()
cnt=0
for i in range(len(a)-1):
if(a[i]==a[i+1]):
cnt+=1
print(cmt) |
s000295396 | p03945 | u417014669 | 1578688807 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 130 | word=inpput()
# word="WBWBWBWBWB"
ans=0
for i in range(len(word)-1):
if word[i]!=word[i+1]:
ans+=1
print(ans) |
s818022844 | p03945 | u417014669 | 1578688705 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 130 | word=inpput()
# word="WBWBWBWBWB"
ans=0
for i in range(len(word)-1):
if word[i]!=word[i+1]:
ans+=1
print(ans) |
s297710357 | p03945 | u676685606 | 1577406602 | Python | Python (2.7.6) | py | Runtime Error | 68 | 100940 | 191 | S = raw_input()
def count_least_turns(s, n=0):
stripped = s.lstrip(s[0])
if len(stripped):
return count_least_turns(stripped, n + 1)
return n
print count_least_turns(S)
|
s748288501 | p03945 | u676685606 | 1577406467 | Python | Python (2.7.6) | py | Runtime Error | 67 | 100888 | 196 | S = raw_input()
def count_least_turns(s, n=0):
stripped = s.lstrip(s[0])
if len(stripped) <= 1:
return n
return count_least_turns(stripped, n + 1)
print count_least_turns(S)
|
s047192380 | p03945 | u676685606 | 1577406378 | Python | Python (2.7.6) | py | Runtime Error | 136 | 197968 | 208 | S = raw_input()
def count_least_turns(s, n=0):
print s
stripped = s.lstrip(s[0])
if len(stripped) <= 1:
return n
return count_least_turns(stripped, n + 1)
print count_least_turns(S)
|
s427019104 | p03945 | u875600867 | 1576430715 | Python | Python (3.4.3) | py | Runtime Error | 866 | 134568 | 496 | import re
# 盤面の状態
s = input()
cnt = 0
while True:
print(s)
# 全部Wになるまで or 1文字残しまで繰り返す
if s.count("W") == len(s):
break
# Bがどちらにあるか調べる
if s[0] != "B":
# 逆向きにする
s = s[::-1]
# 先頭を置換する
if s[0] == "B":
s = re.sub(r'[B]+', "", s,1)
cnt +=1
elif s[0] == "W":
s = re.sub(r'[W]+', "", s,1)
cnt +=1
print(cnt) |
s329649174 | p03945 | u875600867 | 1576430664 | Python | Python (3.4.3) | py | Runtime Error | 773 | 134556 | 503 | import re
# 盤面の状態
s = input()
cnt = 0
while True:
print(s)
# 全部Wになるまで or 1文字残しまで繰り返す
if s.count("W") == len(s):
break
# Bがどちらにあるか調べる
if s[len(s)-1] == "B":
# 逆向きにする
s = s[::-1]
# 先頭を置換する
if s[0] == "B":
s = re.sub(r'[B]+', "", s,1)
cnt +=1
elif s[0] == "W":
s = re.sub(r'[W]+', "", s,1)
cnt +=1
print(cnt) |
s639938097 | p03945 | u875600867 | 1576430549 | Python | Python (3.4.3) | py | Runtime Error | 780 | 134560 | 592 | import re
# 盤面の状態
s = input()
cnt = 0
while True:
print(s)
# 全部Wになるまで or 1文字残しまで繰り返す
if s.count("W") == len(s):
break
# Bがどちらにあるか調べる
if s[len(s)-1] == "B":
# 逆向きにする
s = s[::-1]
else:
# Bが末尾に見つからなければ、何もしない
pass
# 先頭を置換する
if s[0] == "B":
s = re.sub(r'[B]+', "", s,1)
cnt +=1
elif s[0] == "W":
s = re.sub(r'[W]+', "", s,1)
cnt +=1
print(cnt) |
s039227645 | p03945 | u875600867 | 1576429807 | Python | Python (3.4.3) | py | Runtime Error | 766 | 134572 | 399 | import re
# 盤面の状態
s = input()
cnt = 0
while True:
# 全部Wになるまで or 1文字残しまで繰り返す
if s.count("W") == len(s) or len(s)==1:
break
else:
print(s)
# 先頭を置換する
if s[0] == "W":
s = re.sub(r'[W]+', "", s,1)
cnt +=1
elif s[0] == "B":
s = re.sub(r'[B]+', "", s,1)
cnt +=1
print(cnt) |
s120904553 | p03945 | u377989038 | 1569864638 | Python | Python (3.4.3) | py | Runtime Error | 278 | 3188 | 206 | s = input()
f = 0
ans = 0
if s[0] == "B":
ans += 1
while s[0] == "B":
s = s[1:]
s = s[::-1]
if s[0] == "B":
ans += 1
while s[0] == "B":
s = s[1:]
print(ans+s.count("B")*2) |
s006075704 | p03945 | u463655976 | 1569668665 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 154 | s = input()
w = ""
cnt1 = 0
for x in s[1:]:
if x != w:
cnt1 += 1
cnt2 = 0
for x in s[-2::-1]:
if x != w:
cnt2 += 1
print(min(cnt1, cnt2))
|
s303584697 | p03945 | u673361376 | 1568930563 | Python | PyPy3 (2.4.0) | py | Runtime Error | 172 | 38256 | 85 | ans = 0
S = input()
for i in range(1,len(S)): if S[i-1] != S[i]: ans += 1
print(ans) |
s173491683 | p03945 | u134712256 | 1566157292 | Python | Python (3.4.3) | py | Runtime Error | 23 | 3956 | 301 | s = list(input())
i = 0
count = 0
while True:
#print("line6 s=",s,"i =",i,"s[i] =",s[i])
if len(s)==1:break
if len(set(s)) == 1:break
while s[i] == s[i+1]and i<len(s)-2:
i+=1
s[i] = s[i+1]
count += 1
j=0
while j<=i:
s[j]=tmp
j+=1
print(count)
|
s785480391 | p03945 | u134712256 | 1566157248 | Python | Python (3.4.3) | py | Runtime Error | 28 | 5436 | 300 | s = list(input())
i = 0
count = 0
while True:
print("line6 s=",s,"i =",i,"s[i] =",s[i])
if len(s)==1:break
if len(set(s)) == 1:break
while s[i] == s[i+1]and i<len(s)-2:
i+=1
s[i] = s[i+1]
count += 1
j=0
while j<=i:
s[j]=tmp
j+=1
print(count)
|
s678227702 | p03945 | u134712256 | 1566156410 | Python | Python (3.4.3) | py | Runtime Error | 2104 | 3956 | 286 | s = list(input())
i = 0
count = 0
while True:
#print("line6 s=",s,"i =",i,"s[i] =",s[i])
while s[i] == s[i+1]and i<len(s)-2:
i+=1
if len(set(s)) == 1:
break
tmp = s[i+1]
count += 1
j=0
while j<=i:
s[j]=tmp
j+=1
print(count)
|
s076265529 | p03945 | u777283665 | 1565634454 | Python | PyPy3 (2.4.0) | py | Runtime Error | 170 | 39664 | 246 | s = input()
left = 0
right = 0
count = 0
while True:
if s[right+1] != s[left]:
count += 1
right += 1
left = right
if right == len(s) - 1:
break
else:
right += 1
if right == len(s) - 1:
break
print(count) |
s653366049 | p03945 | u845620905 | 1560868683 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3188 | 147 | b = input()
d = []
isWhite = False
cnt = 0
for i in range(len(b-1)):
if b[i] != b[i+1]:
d.append(cnt)
else:
cnt+=1
print(len(d))
|
s798198492 | p03945 | u280978334 | 1559774365 | Python | Python (3.4.3) | py | Runtime Error | 33 | 3188 | 139 | S = input()
count = 0
temp = S[-1]
for s in S[-2::-1]:
if s != temp:
count += 1
temp = s
print(0 if count == 0 else temp-1) |
s244110329 | p03945 | u319818856 | 1554739892 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3188 | 184 | def _1d_reversi(S: str) -> int:
n = len(S)
return sum(s[i] != s[i-1] for i in range(1, n))
if __name__ == "__main__":
S = input()
ans = _1d_reversi(S)
print(ans)
|
s242667581 | p03945 | u371467115 | 1554598421 | Python | Python (3.4.3) | py | Runtime Error | 20 | 3444 | 87 | s=int(input())
cnt=0
for i in range(len(s)-1):
if s[i]!=s[i+1]:
cnt+=1
print(cnt) |
s679657120 | p03945 | u013408661 | 1554469268 | Python | Python (3.4.3) | py | Runtime Error | 18 | 2940 | 81 | s=input()
ans=0
for i in range(len(s):):
if s[i]!=s[i+1]:
ans+=1
print(ans) |
s722589816 | p03945 | u905715926 | 1552529382 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3188 | 92 | s = input()
ans = 0
for i in range(1,n):
if(s[i]!=s[i-1]):
ans += 1
print(ans)
|
s499272704 | p03945 | u444856278 | 1551660282 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 146 | [print(len(list(i.groupby(input())))-1)for i in[__import__('itertools')]][print(len(list(i.groupby(input())))-1)for i in[__import__('itertools')]] |
s199701656 | p03945 | u623819879 | 1551484004 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 86 | s=str(input())
ans=0
for i in range(len(s)-1):
if s[i]<>[i+1]:
ans+=1
print(ans) |
s450546178 | p03945 | u543954314 | 1550719092 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3188 | 90 | s = input()
ans = 0
for i in range(len(s-1)):
if s[i] != s[i+1]:
ans += 1
print(ans) |
s015592172 | p03945 | u950708010 | 1548284944 | Python | Python (3.4.3) | py | Runtime Error | 20 | 3188 | 135 | s = input()
n = len(s)
ct = 0
if len(set(s)) == 1:
ans = 0
else:
for i in range(n-1):
if s[i] != s[i+1]:
ans+= 1
print(ans)
|
s703635052 | p03945 | u513081876 | 1544894997 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3188 | 97 | S = input()
s = s[0]
ans = 0
for i in S:
if s != i:
ans += 1
s = i
print(ans) |
s158477239 | p03945 | u142415823 | 1544045830 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3188 | 84 | S = input()
s = ''
for i in S:
if i != s[-1]:
s += i
print(len(s) - 1) |
s787466755 | p03945 | u733321071 | 1541620565 | Python | Python (3.4.3) | py | Runtime Error | 2104 | 4084 | 1031 | # -*- coding: utf-8
import sys
def leftside_reverse(s, turn):
for num in range(len(s)):
if s[num] == turn:
break
else:
s[num] = turn
return s
def rightside_reverse(s, turn):
for num in range(len(s) - 1, -1):
if s[num] == turn:
break
else:
s[num] = turn
return s
def function(s, first):
count = 0
turn = first
while True:
if s.count(first) == len(s):
break
if s[0] == turn:
s = rightside_reverse(s, turn)
count += 1
else:
s = leftside_reverse(s, turn)
count += 1
if turn == 'B':
turn = 'W'
else:
turn = 'B'
return count
if __name__ == '__main__':
s = list(input())
b = 'B'
w = 'W'
if s.count(b) == len(s) or s.count(w) == len(s):
print('0')
sys.exit(1)
b_count = function(s, b)
w_count = function(s, w)
print(min(b_count, w_count))
|
s831891024 | p03945 | u733321071 | 1541618324 | Python | Python (3.4.3) | py | Runtime Error | 25 | 4084 | 992 | # -*- coding: utf-8
import sys
def leftside_reverse(s, turn):
for num in len(s):
if s[num] == turn:
return s
else:
s[num] = turn
return s
def rightside_reverse(s, turn):
for num in range(len(s), 0, -1):
if s[num] == turn:
return s
else:
s[num] = turn
return s
def function(s, turn):
count = 0
while True:
if s.count(turn) == len(s):
return count
if s[0] == turn:
s = leftside_reverse(s, turn)
count += 1
else:
s = rightside_reverse(s, turn)
count += 1
if turn == b:
turn = w
else:
turn = b
if __name__ == '__main__':
s = list(input())
b = 'B'
w = 'W'
if s.count(b) == len(s) or s.count(w) == len(s):
print('0')
sys.exit(1)
b_count = function(s, b)
w_count = function(s, w)
print(min(b_count, w_count))
|
s878185217 | p03945 | u344545933 | 1538687008 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 214 | #include<bits/stdc++.h>
using namespace std;
int main(void){
string S;
cin>>S;
int ans=0, i, tmp=S[0];
for (i=0;i<S.length();i++){
if (S[i]!=tmp){
ans+=1;
tmp=S[i];
}
}
cout<<ans;
}
|
s843110860 | p03945 | u944209426 | 1535637551 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3188 | 77 | s=input()
a=0
for i in range(1,n):
if s[i]!=s[i-1]:
a+=1
print(a) |
s655588205 | p03945 | u005260772 | 1533934245 | Python | Python (2.7.6) | py | Runtime Error | 11 | 2568 | 116 | s, ans = raw_input(), 0
for i in range(len(s) - 1):
if (len(set(s[i : i + 2))) == 2):
ans += 1
print ans |
s066622071 | p03945 | u005260772 | 1533934191 | Python | Python (2.7.6) | py | Runtime Error | 12 | 2692 | 116 | s, ans = raw_input(), 0
for i in range(len(s) - 1):
if (len(set(s[i : i + 2))) == 2):
ans += 1
print cnt |
s493508445 | p03945 | u005260772 | 1533934181 | Python | Python (2.7.6) | py | Runtime Error | 13 | 2692 | 116 | s, ans = raw_input(), 0
for i in range(len(s) - 1):
if (len(set(s[i : i + 2))) == 2):
cnt += 1
print cnt |
s157683764 | p03945 | u480847874 | 1529339922 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3188 | 589 | def m():
n, x = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
for i in range(1, n-1, 2):
if a[i+1] > a[i-1]:
if a[i+1] + a[i] < x:
continue
ans += (a[i+1] + a[i]) -x
if a[i+1] > x:
a[i+1] = x
else:
if a[i-1] + a[i] < x:
continue
ans += (a[i-1] + a[i]) -x
if len(a) % 2 == 0:
if a[-1] + a[-2] < x:
return ans
ans += (a[-1] + a[-2]) -x
return ans
else:
return ans
print(m()) |
s772530962 | p03945 | u822353071 | 1485464114 | Python | Python (3.4.3) | py | Runtime Error | 24 | 3188 | 361 | #D 高橋君と見えざる手 / An Invisible Hand
N,T = [int(i) for i in input().split(" ")]
A=[int(i) for i in input().split(" ")]
Max = 0
count = 1
for i in range(N-1,0,-1):
for j in range(i-1,-1,-1):
temp = A[i]-A[j]
if temp>Max:
Max = temp
count = 1
elif temp==Max:
count +=1
print(count) |
s061140218 | p03945 | u371573282 | 1479876908 | Python | Python (3.4.3) | py | Runtime Error | 27 | 3188 | 60 | import re
print(len(re.sub("B+","B",re.sub("W+","W",S)))-1)
|
s571539736 | p03945 | u443512298 | 1479423779 | Python | Python (3.4.3) | py | Runtime Error | 23 | 3064 | 855 | # coding: utf-8
# R: Right hand side
# L: Left hand side
def add_stone(stone, pos, searched_stones):
sample = searched_stones[::[1, -1][pos == "R"]]
if sample[0] == stone:
return None
for n, s in enumerate(sample[1:]):
if s == stone:
return stone * (n + 2) + sample[1 + n:]
def stones_bfs(searched_stones):
queue = [searched_stones + "0"]
patterns = [["B", "R"], ["B", "L"], ["W", "R"], ["W", "L"]]
while queue:
stones = queue.pop(0)
if (stones.count("W") == len(stones) - 1 |
stones.count("B") == len(stones) - 1):
return int(stones[-1])
for p in patterns:
s = add_stone(*p, stones[:-1])
if s is not None:
queue += [s + str(int(stones[-1]) + 1)]
print(stones_bfs(input().strip())) |
s644676212 | p03945 | u443512298 | 1479423515 | Python | Python (3.4.3) | py | Runtime Error | 22 | 3064 | 880 | # coding: utf-8
# R: Right hand side
# L: Left hand side
def add_stone(stone, pos, searched_stones):
sample = searched_stones[::[1, -1][pos == "R"]]
if sample[0] == stone:
return None
for n, s in enumerate(sample[1:]):
if s == stone:
return (stone * (n + 2) + sample[1 + n:])[::[1, -1][pos == "R"]]
def stones_bfs(searched_stones):
queue = [searched_stones + "0"]
patterns = [["B", "R"], ["B", "L"], ["W", "R"], ["W", "L"]]
while queue:
stones = queue.pop(0)
if (stones.count("W") == len(stones) - 1 |
stones.count("B") == len(stones) - 1):
return int(stones[-1])
for p in patterns:
s = add_stone(*p, stones[:-1])
if s is not None:
queue += [s + str(int(stones[-1]) + 1)]
print(stones_bfs(input().strip())) |
s301785174 | p03945 | u443512298 | 1479421341 | Python | Python (3.4.3) | py | Runtime Error | 23 | 3064 | 863 | # coding: utf-8
# R: Right hand side
# L: Left hand side
def add_stone(stone, pos, searched_stones):
sample = searched_stones[::[1, -1][pos == "R"]]
if sample[0] == stone:
return None
for n, s in enumerate(sample[1:]):
if s == stone:
return (stone * (n + 2) + sample[1 + n:])[::[1, -1][pos == "R"]]
def stones_bfs(searched_stones):
queue = [[searched_stones, 0]]
patterns = [["B", "R"], ["B", "L"], ["W", "R"], ["W", "L"]]
while queue:
stones = queue.pop(0)
if (stones[0].count("W") == len(stones[0]) |
stones[0].count("B") == len(stones[0])):
return stones[-1]
for p in patterns:
s = add_stone(*p, stones[0])
if s is not None:
queue += [[s, stones[-1] + 1]]
print(stones_bfs(input().strip())) |
s047431085 | p03945 | u054556734 | 1479351727 | Python | Python (3.4.3) | py | Runtime Error | 48 | 3188 | 87 |
s=input()
count=0
for i in range(len(s)):
if s[i]!=s[i+1]: count+=1
print(count) |
s118693545 | p03945 | u054556734 | 1479351715 | Python | Python (3.4.3) | py | Runtime Error | 53 | 3188 | 87 |
s=input()
count=0
for i in range(len(s)):
if s[i]!=s[i+1]: count+=1
print(count) |
s565388486 | p03946 | u787059958 | 1599851195 | Python | PyPy3 (7.3.0) | py | Runtime Error | 2293 | 3513868 | 530 | N, T = map(int, input().split())
A = list(map(int, input().split()))
dp = [[0] * (N + 1) for _ in range(N + 1)]
max_num = max(A)
max_index = A.index(max_num)
idx = 0
dfe = 0
count = 0
while True:
print(idx)
if idx >= len(A) - 1:
break
max_num = max(A[idx:])
max_index = A.index(max_num)
min_num = min(A[idx:max_index + 1])
if dfe == max_num - min_num:
count += 1
elif dfe < max_num - min_num:
dfe = max_num - min_num
count = 1
idx = max_index + 1
print(count)
|
s522602389 | p03946 | u169350228 | 1598252313 | Python | PyPy3 (7.3.0) | py | Runtime Error | 119 | 92000 | 1062 | '''
自宅用PCでの解答
'''
import math
#import numpy as np
import itertools
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7 #998244353
dir = [(-1,0),(0,-1),(1,0),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"
def main():
n,t = map(int,ipt().split())
a = [int(i) for i in ipt().split()]
d = []
u = []
pv = 1000000
for i in range(n-1):
if pv > a[i] < a[i+1]:
d.append(a[i])
elif pv < a[i] > a[i+1]:
u.append(a[i])
if a[i] != a[i+1]:
pv = a[i]
if pv < a[-1]:
u.append(a[-1])
ds = []
if len(u) != len(d):
print(asdasd)
for ui,di in zip(u,d):
ds.append(ui-di)
dma = max(ds)
cnt = 0
for i in ds:
if dma == i:
cnt += 1
print(cnt)
return None
if __name__ == '__main__':
main()
|
s040209356 | p03946 | u242757684 | 1594030975 | Python | PyPy3 (7.3.0) | py | Runtime Error | 117 | 86548 | 438 | N,T = map(int,input().split())
a = list(map(int,input().split()))
maxDiff = 0
curMin = a[0]
for i in range(n):
if curMin > a[i]:
curMin = a[i]
if maxDiff < a[i] - curMin:
maxDiff = a[i] - curMin
isCovered = False
count = 0
curMin = a[0]
for i in range(n):
if curMin > a[i]:
curMin = a[i]
isCovered = False
if maxDiff == a[i] - curMin:
if not isCovered:
count += 1
isCovered = True
print(count) |
s488844368 | p03946 | u316464887 | 1592444341 | Python | Python (3.4.3) | py | Runtime Error | 882 | 22984 | 1285 | class SegTree:
def __init__(self, a, func):
self.n = 2**(len(a) - 1).bit_length()
self.f = func
self.d = [0] * (2 * self.n - 1)
self.d[self.n - 1:self.n - 1 + len(a)] = a
for i in reversed(range(self.n - 1)):
self.d[i] = self.f(self.d[2 * i + 1], self.d[2 * i + 2])
def update(self, i, v):
i += self.n - 1
self.d[i] = v
while i:
i = (i - 1) // 2
self.d[i] = self.f(self.d[2 * i + 1], self.d[2 * i + 2])
# l <= i < r
def query(self, l, r):
assert l <= r
l += self.n
r += self.n
s = self.d[l - 1]
while l < r:
if l & 1:
s = self.f(s, self.d[l - 1])
l += 1
if r & 1:
r -= 1
s = self.f(s, self.d[r - 1])
l //= 2
r //= 2
return s
def main():
N, T = map(int, input().split())
A = list(map(int, input().split()))
def func(a, b):
if a >= b:
return a
return b
s = SegTree(A, func)
d = {}
for i in range(N):
t = s.query(i+1, N) - A[i]
d[t] = d.get(t, 0) + 1
m = 0
for i in d:
if i > m:
m = i
return d[m]
print(main())
|
s771356397 | p03946 | u935077683 | 1590867585 | Python | Python (3.4.3) | py | Runtime Error | 92 | 15060 | 405 | n, t = map(int, input().split())
l = [int(i)for i in input().split()]
if t <= 1 or all(b >= a for a, b in zip(l, l[1:])):
print(0)
else:
mini = float("inf")
maxp = 0
maxc = 0
for n in l:
if n - mini > maxp:
maxp = n - mini
maxc = 1
elif n - mini == maxp:
maxp = n - mini
maxc += 1
mini = min(mini, n)
print(maxc) |
s708262750 | p03946 | u695079172 | 1590595291 | Python | Python (3.4.3) | py | Runtime Error | 28 | 12068 | 483 |
def main():
n,t = map(int,input().split())
lst = list(map,int(input().split()))
mn = 999999999999999999999999999
counter = 0
diff = 0
for m in lst:
if m < mn: #最小値の更新
mn = m
elif m - mn == diff: #最大値が同じものの数を+1
counter += 1
elif m - mn > diff: #最大値を更新
counter = 1
diff = m - mn
print(counter)
if __name__ == '__main__':
main()
|
s061724106 | p03946 | u535803878 | 1589508998 | Python | PyPy3 (2.4.0) | py | Runtime Error | 232 | 62704 | 934 | # ABC047D
import sys# ABC047D
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
n,t = map(int, input().split())
a = list(map(int, input().split()))
M = -1
m = 10**10
best = 0
count = 0
for num in a[::-1]:
if M<num:
M = num
m = M
elif num<m:
m = num
if best<(M-m):
best = M - m
count = 1
elif best==(M-m):
count += 1
# print(M, m, count, best)
print(count) if t%2==0 else print(1)
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
n,t = map(int, input().split())
a = list(map(int, input().split()))
M = -1
m = 10**10
best = 0
count = 0
for num in a[::-1]:
if M<num:
M = num
m = M
elif num<m:
m = num
if best<(M-m):
best = M - m
count = 1
elif best==(M-m):
count += 1
# print(M, m, count, best)
print(count) |
s196150505 | p03946 | u703950586 | 1589334224 | Python | PyPy3 (2.4.0) | py | Runtime Error | 240 | 61164 | 989 | import sys,queue,math,copy,itertools,bisect,collections,heapq
def main():
sys.setrecursionlimit(10**7)
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
N,_ = LI()
N0 = 2 ** N.bit_length()
st = [0] * (N0*2)
def add(p,x):
p += N0-1
st[p] = x
while p > 0:
p = (p-1) // 2
st[p] = max(st[p*2+1],st[p*2+2])
def get(a,b,x,l,r):
if a <= l and r <= b: return st[x]
if a >= r or b <= l: return 0
vl = get(a,b,x*2+1,l,(l+r)//2)
vr = get(a,b,x*2+2,(l+r)//2,r)
return max(vl,vr)
A = []
for a in enumerate(sys.stdin.readline().split()):
a = int(a)
A.append(a)
add(e+1,a)
max_a = -1
max_cnt = 0
for i in range(1,N):
a = get(i+1,N+1,0,0,N0) - A[i-1]
if a > max_a:
max_a = a; max_cnt = 1
elif a == max_a:
max_cnt += 1
print(max_cnt)
if __name__ == '__main__':
main() |
s362766211 | p03946 | u578323547 | 1588197600 | Python | PyPy3 (2.4.0) | py | Runtime Error | 234 | 60072 | 297 | town, apple = map(int, input().split())
prices = [int(x) for x in input().split(' ')]
revenues = []
for i in range(1, town):
revenue = 0
if (prices[i] > prices[i-1]):
revenue += prices[i] - prices[i-1]
else:
revenues += [revenue]
print(revenues.count(max(revenues))) |
s699209592 | p03946 | u578323547 | 1588197529 | Python | PyPy3 (2.4.0) | py | Runtime Error | 235 | 60072 | 296 | town, apple = map(int, input().split())
prices = [int(x) for x in input().split(' ')]
revenues = []
for i in range(1, town):
revenue = 0
if (prices[i] > prices[i-1]):
revenue = prices[i] - prices[i-1]
else:
revenues += [revenue]
print(revenues.count(max(revenues))) |
s991156259 | p03946 | u724687935 | 1587551532 | Python | PyPy3 (2.4.0) | py | Runtime Error | 634 | 79620 | 2130 | class SegmentTree():
"""
update, get を提供するSegmentTree
Attributes
----------
__n : int
葉の数。2 ^ i - 1
__dot :
Segment function
__e: int
単位元
__node: list
Segment Tree
"""
def __init__(self, A, dot, e):
"""
Parameters
----------
A : list
対象の配列
dot :
Segment function
e : int
単位元
"""
n = 2 ** (len(A) - 1).bit_length()
self.__n = n
self.__dot = dot
self.__e = e
self.__node = [e] * (2 * n)
for i in range(len(A)):
self.__node[i + n] = A[i]
for i in range(n - 1, 0, -1):
self.__node[i] = self.__dot(self.__node[2 * i], self.__node[2 * i + 1])
def update(self, i, c):
i += self.__n
node = self.__node
node[i] = c
while i > 1:
i //= 2
node[i] = self.__dot(node[2 * i], node[2 * i + 1])
def get(self, l, r):
vl, vr = self.__e, self.__e
l += self.__n
r += self.__n
while (l < r):
if l & 1:
vl = self.__dot(vl, self.__node[l])
l += 1
l //= 2
if r & 1:
r -= 1
vr = self.__dot(vr, self.__node[r])
r //= 2
return self.__dot(vl, vr)
def main():
import sys
readline = sys.stdin.readline
# readlines = sys.stdin.readlines
N, T = map(int, input().split())
A = list(map(int, readline().split()))
L = SegmentTree(A, min, float('inf'))
R = SegmentTree(A, max, 0)
profit = 0
for i in range(N):
l = L.get(0, i + 1)
r = R.get(i, N + 1)
profit = max(profit, r - l)
cnt = 0
for i in range(N):
l = L.get(0, i + 1)
r = R.get(i, N + 1)
if r - l == profit:
if l == A[i]:
L.update(i, l - 1)
else:
R.update(i, r + 1)
cnt += 1
print(cnt)
if __name__ == "__main__":
main()
|
s280116808 | p03946 | u708019102 | 1587420793 | Python | PyPy3 (2.4.0) | py | Runtime Error | 2109 | 92420 | 317 | N,T = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
ind = 0
rieki = []
while True:
ma = max(a[ind+1:N])
kioku = ind+1
ind = a.index(ma)
if kioku != ind:
mi = min(a[kioku:ind])
rieki.append(ma-mi)
if ind == N-1:
break
print(rieki.count(max(rieki))) |
s025972703 | p03946 | u679154596 | 1586752938 | Python | PyPy3 (2.4.0) | py | Runtime Error | 224 | 62704 | 382 | import sys
sys.setrecursionlimit(10000000)
N, T = map(int, input().split())
A = list(map(int, input().split()))
D = [0]
def f(a):
if a <= N:
M = max(A[a:N+1])
Mi = A.index(M)
m = min(A[a-1:Mi])
d = M - m
if D[-1] == d:
D.append(d)
elif D[-1] < d:
D.clear()
D.append(d)
f(Mi+2)
else:
pass
f(1)
result = len(D)
print(result)
|
s381134576 | p03946 | u679154596 | 1586752820 | Python | Python (3.4.3) | py | Runtime Error | 2104 | 15020 | 381 | import sys
sys.setrecursionlimit(1000000)
N, T = map(int, input().split())
A = list(map(int, input().split()))
D = [0]
def f(a):
if a <= N:
M = max(A[a:N+1])
Mi = A.index(M)
m = min(A[a-1:Mi])
d = M - m
if D[-1] == d:
D.append(d)
elif D[-1] < d:
D.clear()
D.append(d)
f(Mi+2)
else:
pass
f(1)
result = len(D)
print(result)
|
s853597989 | p03946 | u679154596 | 1586752471 | Python | Python (3.4.3) | py | Runtime Error | 2104 | 15020 | 338 | N, T = map(int, input().split())
A = list(map(int, input().split()))
D = [0]
def f(a):
if a <= N:
M = max(A[a:N+1])
Mi = A.index(M)
m = min(A[a-1:Mi])
d = M - m
if D[-1] == d:
D.append(d)
elif D[-1] < d:
D.clear()
D.append(d)
f(Mi+2)
else:
pass
f(1)
result = len(D)
print(result)
|
s237621425 | p03946 | u679154596 | 1586751925 | Python | Python (3.4.3) | py | Runtime Error | 2104 | 14676 | 261 | N, T = map(int, input().split())
A = list(map(int, input().split()))
D = []
def f(a):
if a <= N:
M = max(A[a:N+1])
Mi = A.index(M)
m = min(A[a-1:Mi])
D.append(M - m)
f(Mi+2)
else:
pass
f(1)
result = D.count(max(D))
print(result)
|
s056374755 | p03946 | u595289165 | 1583524211 | Python | PyPy3 (2.4.0) | py | Runtime Error | 2109 | 92656 | 177 | n, t = map(int, input().split())
a = list(map(int, input().split()))
ans = []
for i in range(n):
b = max(a[i+1:]) - a[i]
ans.append(b)
r = max(ans)
print(ans.count(r)) |
s055985635 | p03946 | u476604182 | 1581786681 | Python | PyPy3 (2.4.0) | py | Runtime Error | 238 | 62832 | 238 | N, T = map(int, input().split())
A = [int(c) for c in input().split()]
p = A[0]
flag = True
ls = []
st = A[-1]
for i in range(N-2,-1-1):
if st-A[i]>0:
ls += [st-A[i]]
else:
st = A[i]
ls.sort()
ans = ls.count(ls[-1])
print(ans) |
s132006124 | p03946 | u476604182 | 1581786432 | Python | PyPy3 (2.4.0) | py | Runtime Error | 247 | 62704 | 285 | N, T = map(int, input().split())
A = [int(c) for c in input().split()]
p = A[0]
flag = True
ls = []
st = A[0]
for i in range(1,N):
if A[i]>=A[i-1]:
flag = True
else:
if flag:
ls += [A[i-1]-st]
flag = False
st = A[i]
ls.sort()
ans = ls.count(ls[-1])
print(ans) |
s215827536 | p03946 | u600402037 | 1576795828 | Python | Python (3.4.3) | py | Runtime Error | 181 | 23416 | 320 | import sys
import numpy as np
stdin = sys.stdin
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip() # ignore trailing spaces
N, T = rl()
A = np.array(rl())
A_cummin = A.minimum.accumulate(A)
B = A - A_cummin
answer = (B == B.max()).sum()
print(answer) |
s070375162 | p03946 | u600402037 | 1576793376 | Python | Python (3.4.3) | py | Runtime Error | 2112 | 23464 | 429 | import sys
import numpy as np
stdin = sys.stdin
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip() # ignore trailing spaces
N, T = rl()
A = rl()
B = np.array(A)
answer = 1
profit = 0
for i in range(N):
B = B[1:]
p = B.max() - A[i]
if p > profit:
profit = p
answer = 1
elif p == profit:
answer += 1
print(answer)
# 40
|
s661590792 | p03946 | u905582793 | 1576597972 | Python | Python (3.4.3) | py | Runtime Error | 190 | 21596 | 356 | n,t=map(int,input().split())
a=list(map(int,input().split()))
b=[[a[i],i] for i in range(n)]
b.sort(reverse=True)
lmin=[a[0]]
rmax=[max(a[1:])]
mxls=[rmax[0]-lmin[0]]
mx=0
mn=n-1
for i in range(1,n):
if a[i]<=b[mn]:
mn-=1
if a[i]>=b[mx]:
mx+=1
lmin.append(b[mn])
rmax.append(b[mx])
mxls.append(b[mx]-b[mn])
print(mxls.count(max(mxls)))
|
s684568218 | p03946 | u828766688 | 1574259411 | Python | PyPy3 (2.4.0) | py | Runtime Error | 223 | 62704 | 403 |
N,T = map(int,input().split())
A = list(map(int,input().split()))
nmin = float("inf")
nsub = 0
ans = 0
Acopy = A.copy()
Acopy.sort()
for i in Acopy:
if A[-1] == i:
del A[-1]
else:
break
for i in range(len(A)):
nmin = min(nmin , A[i])
if nsub < A[i] - nmin:
nsub = A[i] - nmin
ans = 1
elif nsub == A[i] - nmin:
ans += 1
print (ans)
|
s708098395 | p03946 | u557494880 | 1573803986 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 233 | n,t = map(int,input())
A = list(map(int,input().split()))
m = 10**9+1
M = -1
ans = 0
for i in range(n):
x = A[i]
m = min(x)
p = x-A
if p > M:
ans = 0
M = p
elif p == M:
ans += 1
print(ans) |
s746945648 | p03946 | u595716769 | 1572597196 | Python | Python (3.4.3) | py | Runtime Error | 1741 | 144320 | 607 | import copy
n, t = map(int, input().split())
L = [int(i) for i in input().split()]
LL = copy.deepcopy(L)
minvalue = L[0]
maxvalue = max(LL)
subt = 0
count = 1
flag = 0
j = 0
for i in range(n-1):
if minvalue > L[i]:
minvalue = L[i]
flag = 1
if maxvalue == L[i]:
LL = LL[i-j+1:]
maxvalue = max(LL)
j = i+1
tsubt = maxvalue - minvalue
if tsubt > subt:
subt = tsubt
count = 1
elif tsubt == subt and flag == 1:
count += 1
flag = 0
print(LL)
print("L[i]:{0}, min:{1}, max:{2}, subt:{3}, count:{4}".format(L[i], minvalue, maxvalue, subt, count))
print(count) |
s068386124 | p03946 | u367130284 | 1572331406 | Python | Python (3.4.3) | py | Runtime Error | 413 | 23248 | 405 | from copy import*
from collections import*
from numpy import*
from itertools import*
a,b=map(int,input().split())
*c,=map(int,input().split())
c1=deepcopy(c)
c2=deepcopy(c)
for i in range(1,a):
c1[i]=min(c1[i-1],c1[i])
for i in range(a-1,0,-1):
c2[i-1]=max(c2[i],c2[i-1])
#print(c1,c2)
d=array([k for k,v in groupby(c2)])-array([k for k,v in groupby(c1)])
#print(d)
#print(list(d).count(max(d))) |
s757754769 | p03946 | u367130284 | 1572331165 | Python | Python (3.4.3) | py | Runtime Error | 420 | 23244 | 404 | from copy import*
from collections import*
from numpy import*
from itertools import*
a,b=map(int,input().split())
*c,=map(int,input().split())
c1=deepcopy(c)
c2=deepcopy(c)
for i in range(1,a):
c1[i]=min(c1[i-1],c1[i])
for i in range(a-1,0,-1):
c2[i-1]=max(c2[i],c2[i-1])
#print(c1,c2)
d=array([k for k,v in groupby(c2)])-array([k for k,v in groupby(c1)])
#print(d)
print(list(d).count(max(d))) |
s538696742 | p03946 | u457554982 | 1571525049 | Python | Python (3.4.3) | py | Runtime Error | 42 | 14228 | 608 | [n,t]=list(map(int,input().split()))
alist=list(map(int,input().split()))
"""
alist.reverse()
n=n-1
dp=[[0 for j in range(n)]for k in range(n)]
for i in range(n-1):
dp[i][i+1]=alist[i+1]-alist[i]
for i in reversed(range(0,n-1)):
for j in range(n-1-i):
dp[i][i+2+j]=dp[i][i+1]+dp[i+1][i+2+j]
maximum=max(dp[0])
for i in range(1,n):
if maximum<max(dp[i]):
maximum=max(dp[i])
kosu=0
for i in range(0,n):
kosu=kosu+dp[i].count(maximum)
print(kosu)
"""
salist=[]
for i in range(n-1):
saisho=min(alist[0:i])
salist.append(alist[i+1]-saisho)
saidai=max(salist)
kaisu=salist.count(saidai)
print(kaisu) |
s049402397 | p03946 | u457554982 | 1571522629 | Python | Python (3.4.3) | py | Runtime Error | 2142 | 482316 | 450 | [n,t]=list(map(int,input().split()))
alist=list(map(int,input().split()))
alist.reverse()
n=n-1
dp=[[0 for j in range(n)]for k in range(n)]
for i in range(n-1):
dp[i][i+1]=alist[i+1]-alist[i]
for i in reversed(range(0,n-1)):
for j in range(n-1-i):
dp[i][i+2+j]=dp[i][i+1]+dp[i+1][i+2+j]
maximum=max(dp[0])
for i in range(1,n):
if maximum<max(dp[i]):
maximum=max(dp[i])
kosu=0
for i in range(0,n):
kosu=kosu+dp[i].count(maximum)
print(kosu) |
s113448802 | p03946 | u911575040 | 1570419273 | Python | Python (3.4.3) | py | Runtime Error | 120 | 16024 | 368 | n,t=map(int,input().split())
a=list(map(int,input().split()))
c=[]
d=[0]*(10**5)
if a[0]<a[1]:
c.append([a[0],0])
else:
d[0]=a[0]
for i in range(1,n-1):
if a[i]>a[i+1] and a[i-1]<a[i]:
d[i]=a[i]
if a[i]<a[i+1] and a[i-1]>a[i]:
c.append([a[i],i])
d[n-1]=a[n-1]
e=[0]*(10**5)
for i in c:
E=max(d[i[1]:])-i[0]
e[E]+=1
print(max(e)) |
s383439921 | p03946 | u911575040 | 1570419013 | Python | Python (3.4.3) | py | Runtime Error | 125 | 16156 | 369 | n,t=map(int,input().split())
a=list(map(int,input().split()))
c=[]
d=[0]*(10**5)
if a[0]<a[1]:
c.append([a[0],0])
else:
d[0]=a[0]
for i in range(1,n-1):
if a[i]>a[i+1] and a[i-1]<a[i]:
d[i]=a[i]
if a[i]<a[i+1] and a[i-1]>a[i]:
c.append([a[i],i])
d[n-1]=a[n-1]
e=[0]*(10**5)
for i in c:
E=max(d[i[1]:])-i[0]
e[E]+=1
print(max(e)) |
s968817956 | p03946 | u911575040 | 1570418973 | Python | PyPy3 (2.4.0) | py | Runtime Error | 248 | 62704 | 369 | n,t=map(int,input().split())
a=list(map(int,input().split()))
c=[]
d=[0]*(10**5)
if a[0]<a[1]:
c.append([a[0],0])
else:
d[0]=a[0]
for i in range(1,n-1):
if a[i]>a[i+1] and a[i-1]<a[i]:
d[i]=a[i]
if a[i]<a[i+1] and a[i-1]>a[i]:
c.append([a[i],i])
d[n-1]=a[n-1]
e=[0]*(10**5)
for i in c:
E=max(d[i[1]:])-i[0]
e[E]+=1
print(max(e)) |
s994696583 | p03946 | u728566015 | 1568861497 | Python | Python (3.4.3) | py | Runtime Error | 94 | 14676 | 503 | N, T = map(int, input().split())
A = list(map(int, input().split()))
n = T // 2
d = -float("inf")
cnt = 1
l = 0
for r in range(1, N - 1):
if A[l] < A[r]:
if A[r] > A[r + 1]:
if d == A[r] - A[l]:
cnt += 1
elif d < A[r] - A[l]:
d = A[r] - A[l]
cnt = 1
else:
l = r
r += 1
else:
if d == A[r] - A[l]:
cnt += 1
elif d < A[r] - A[l]:
d = A[r] - A[l]
cnt = 1
print(cnt) |
s898708865 | p03946 | u761529120 | 1561427477 | Python | Python (3.4.3) | py | Runtime Error | 42 | 14252 | 289 | N, T = map(int, input().split())
A = list(map(int, input().split()))
max_bef = 0
cnt = 0
A_min = A[0]
for i in range(1,N):
tmp = A[i] - A_min
if max_bef < tmp:
max_bef = tmp
cnt = 1
if max_bef == tmp:
cnt += 1
a_min = min(a_min, a[i])
print(cnt)
|
s799233231 | p03946 | u247554097 | 1560198354 | Python | PyPy3 (2.4.0) | py | Runtime Error | 246 | 66156 | 1092 | # minより右側にあるmaxの差 * Tすれば最大になる。その差が同じペアは別解としてある
# でもこうするとTの値は意味ないよなぁ
# 「自分より左側で最小の数」「自分より右側で最大の数」の配列を作って、再度頭からなめていけば最大の差とそれをとるペアがわかる
n, t = map(int, input().split())
arr = list(map(int, input().split()))
min_arr = [10**9 for _ in range(n)]
max_arr = [-1 for _ in range(n)]
now_min, now_max = 10**9, -1
for i in range(n):
if now_min > arr[i]:
now_min = arr[i]
min_arr[i] = now_min
if now_max < arr[-i - 1]:
now_max = arr[-i-1]
max_arr[-i - 1] = now_max
max_dif = 0
dif_paris = []
for i in range(n):
if max_arr[i] - min_arr[i] > max_dif:
max_dif = max_arr[i] - min_arr[i]
dif_paris.clear()
dif_paris.append([max_arr[i], min_arr[i]])
elif max_arr[i] - min_arr[i] == max_dif:
if [max_arr[i], min_arr[i]] not in dif_paris:
dif_paris.append([max_arr[i], min_arr[i]])
print(len(dif_paris))
|
s278985868 | p03946 | u247554097 | 1560197509 | Python | Python (3.4.3) | py | Runtime Error | 130 | 14480 | 1075 | # minより右側にあるmaxの差 * Tすれば最大になる。その差が同じペアは別解としてある
# でもこうするとTの値は意味ないよなぁ
# 「自分より左側で最小の数」「自分より右側で最大の数」の配列を作って、再度頭からなめていけば最大の差とそれをとるペアがわかる
n, t = map(int, input().split())
arr = list(map(int, input().split()))
min_arr = []
max_arr = []
now_min, now_max = 10**9, -1
for i in range(n):
if now_min > arr[i]:
now_min = arr[i]
min_arr.append(now_min)
if now_max < arr[-i - 1]:
now_max = arr[-i-1]
max_arr.append(now_max)
max_arr = list(reversed(max_arr))
print(min_arr)
print(max_arr)
max_dif = 0
dif_paris = []
for i in range(len(max_arr)):
if max_arr[i] - min_arr[i] > max_dif:
max_dif = max_arr[i] - min_arr[i]
dif_paris.clear()
dif_paris.append([max_arr[i], min_arr[i]])
elif max_arr[i] - min_arr[i] == max_dif:
dif_paris.append([max_arr[i], min_arr[i]])
print(len(dif_paris))
|
s006346449 | p03946 | u247554097 | 1560197123 | Python | Python (3.4.3) | py | Runtime Error | 2104 | 14484 | 1103 | # minより右側にあるmaxの差 * Tすれば最大になる。その差が同じペアは別解としてある
# でもこうするとTの値は意味ないよなぁ
# 「自分より左側で最小の数」「自分より右側で最大の数」の配列を作って、再度頭からなめていけば最大の差とそれをとるペアがわかる
n, t = map(int, input().split())
arr = list(map(int, input().split()))
min_arr = []
max_arr = []
now_min, now_max = 10**9, -1
for i in range(n):
if now_min > arr[i]:
now_min = arr[i]
min_arr.append(now_min)
if now_max < arr[-i - 1]:
now_max = arr[-i-1]
max_arr.append(now_max)
max_arr = list(reversed(max_arr))
max_dif = 0
dif_paris = []
for i in range(len(max_arr)):
if max_arr[i] - min_arr[i] > max_dif:
max_dif = max_arr[i] - min_arr[i]
dif_paris.clear()
dif_paris.append([max_arr[i], min_arr[i]])
elif max_arr[i] - min_arr[i] == max_dif:
if [max_arr[i], min_arr[i]] not in dif_paris:
dif_paris.append([max_arr[i], min_arr[i]])
print(len(dif_paris))
|
s307834398 | p03946 | u247554097 | 1560196776 | Python | PyPy3 (2.4.0) | py | Runtime Error | 234 | 64260 | 1093 | # minより右側にあるmaxの差 * Tすれば最大になる。その差が同じペアは別解としてある
# でもこうするとTの値は意味ないよなぁ
# 「自分より左側で最小の数」「自分より右側で最大の数」の配列を作って、再度頭からなめていけば最大の差とそれをとるペアがわかる
n, t = map(int, input().split())
arr = list(map(int, input().split()))
min_arr = [10**9 for _ in range(n)]
max_arr = [-1 for _ in range(n)]
now_min, now_max = 10**9, -1
for i in range(n):
if now_min > arr[i]:
now_min = arr[i]
min_arr[i] = now_min
if now_max < arr[-i - 1]:
now_max = arr[-i-1]
max_arr[-i - 1] = now_max
max_dif = 0
dif_paris = []
for i in range(n):
if max_arr[i] - min_arr[i] > max_dif:
max_dif = max_arr[i] - min_arr[i]
dif_paris.clear()
dif_paris.append([max_arr[i], min_arr[i]])
elif max_arr[i] - min_arr[i] == max_dif:
if [max_arr[i], min_arr[i]] not in dif_paris:
dif_paris.append([max_arr[i], min_arr[i]])
print(len(dif_paris))
|
s556175652 | p03946 | u247554097 | 1560196663 | Python | PyPy3 (2.4.0) | py | Runtime Error | 235 | 66668 | 1091 | # minより右側にあるmaxの差 * Tすれば最大になる。その差が同じペアは別解としてある
# でもこうするとTの値は意味ないよなぁ
# 「自分より左側で最小の数」「自分より右側で最大の数」の配列を作って、再度頭からなめていけば最大の差とそれをとるペアがわかる
n, t = map(int, input().split())
arr = list(map(int, input().split()))
min_arr = [10e9 for _ in range(n)]
max_arr = [-1 for _ in range(n)]
now_min, now_max = 10e9, -1
for i in range(n):
if now_min > arr[i]:
now_min = arr[i]
min_arr[i] = now_min
if now_max < arr[-i - 1]:
now_max = arr[-i-1]
max_arr[-i - 1] = now_max
max_dif = 0
dif_paris = []
for i in range(n):
if max_arr[i] - min_arr[i] > max_dif:
max_dif = max_arr[i] - min_arr[i]
dif_paris.clear()
dif_paris.append([max_arr[i], min_arr[i]])
elif max_arr[i] - min_arr[i] == max_dif:
if [max_arr[i], min_arr[i]] not in dif_paris:
dif_paris.append([max_arr[i], min_arr[i]])
print(len(dif_paris))
|
s000368861 | p03946 | u059210959 | 1559841675 | Python | Python (3.4.3) | py | Runtime Error | 198 | 16848 | 953 | # encoding:utf-8
import copy
import random
import bisect #bisect_left これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000
N,T = map(int,input().split())
A = [int(i) for i in input().split()]
L_min = [mod for i in range(N)]
L_min[0] = A[0]
for i in range(1,N):
L_min[i] = min(L_min[i-1],A[i])
A.reverse()
R_max = [0 for i in range(N)]
R_max[0] = A[0]
for i in range(1,N):
R_max[i] = max(R_max[i-1],A[i])
R_max.reverse()
ans = 0
dif = 0
# print(R_max)
# print(L_min)
for i in range(1,N):
if dif < R_max[i] - L_min[i]:
dif = R_max[i] - L_min[i]
r,l = R_max[i],L_min[i]
# print(dif)
ans = 1
elif dif == R_max[i] - L_min[i]:
if r == R_max[i]:
pass
else:
r,l = R_max[i],L_min[i]
ans += 1
print(ans)
|
s275622243 | p03946 | u172386990 | 1557583917 | Python | Python (3.4.3) | py | Runtime Error | 307 | 20384 | 594 | import numpy as np
N, T = map(int, input().split())
dp_matrix = np.zeros((N, N + 1))
price_list = np.array(list(map(int, input().split())))
price_list = price_list.reshape((N, 1))
def max_selecting(m1, m2):
'''
input:
m1, m2: np matrix (same size)
output:
m: np matrix
'''
m_bool1 = m1 > m2
m_bool2 = m1 <= m2
m = m1 * m_bool1 + m2 * m_bool2
return m
diff = np.triu(price_list.T - price_list).T
for i in range(1, N+1):
dp_matrix[:, i] = max_selecting(dp_matrix[:, i-1], diff[i-1])
print(np.sum(dp_matrix[:, N] == np.max(dp_matrix[:, N]))) |
s992992775 | p03946 | u798129018 | 1557547992 | Python | PyPy3 (2.4.0) | py | Runtime Error | 212 | 62704 | 305 | n,t = map(int,input().split())
a = list(map(int,input().split()))
ma = inf
benefit = 0
ans = 1
for i in range(n):
if a[i] < ma:
ma = a[i]
else:
b = a[i]-ma
if b == benefit:
ans += 1
if b > benefit:
benefit = b
ans = 1
print(ans) |
s713494822 | p03946 | u853900545 | 1546202700 | Python | Python (3.4.3) | py | Runtime Error | 44 | 14228 | 470 | n,t = map(int,input().split())
a = list(map(int,input().split()))
i = 0
j = 0
p = 0
c = 0
while 1:
while i < n-1:
if a[i] > a[i+1]:
i += 1
else:
break
if i >= n-1:
break
j = i+1
while a[j] < [j+1]:
j += 1
if j >= n-1:
break
p1 = a[j]-a[i]
if p < p1:
c = 1
p = p1
elif p == p1:
c += 1
p = p1
i = j+1
if i >= n-1:
break
print(c) |
s131442808 | p03946 | u853900545 | 1546202553 | Python | Python (3.4.3) | py | Runtime Error | 45 | 14228 | 438 | n,t = map(int,input().split())
a = list(map(int,input().split()))
i = 0
j = 0
p = 0
c = 0
while 1:
while i < n-1:
if a[i] > a[i+1]:
i += 1
else:
break
if i >= n-1:
break
j = i+1
while a[j] < [j+1]:
j += 1
if j>= n-1:
break
p1 = a[j]-a[i]
if p < p1:
c = 1
p = p1
elif p == p1:
c += 1
p = p1
i = j+1
print(c) |
s599933607 | p03946 | u853900545 | 1546202479 | Python | Python (3.4.3) | py | Runtime Error | 44 | 14244 | 408 | n,t = map(int,input().split())
a = list(map(int,input().split()))
i = 0
j = 0
p = 0
c = 0
while 1:
while i < n-1:
if a[i] > a[i+1]:
i += 1
else:
break
if i >= n-1:
break
j = i+1
while a[j] < [j+1]:
j += 1
p1 = a[j]-a[i]
if p < p1:
c = 1
p = p1
elif p == p1:
c += 1
p = p1
i = j+1
print(c) |
s794072805 | p03946 | u853900545 | 1546200989 | Python | Python (3.4.3) | py | Runtime Error | 2104 | 14680 | 306 | n,t = map(int,input().split())
a = list(map(int,input().split()))
i = 0
p = 0
c = 0
while i < n:
while i < n:
if a[i] > a[i+1]:
i += 1
else:
break
p1 = max(a[i+1:])-a[i]
if p <= p1:
c += 1
p = p1
i = a.index(max(a[i+1:])) + 1
print(c) |
s965440784 | p03946 | u853900545 | 1546200857 | Python | Python (3.4.3) | py | Runtime Error | 2104 | 14252 | 328 | n,t = map(int,input().split())
a = list(map(int,input().split()))
i = 0
p = 0
c = 0
while 1:
while i < n:
if a[i] > a[i+1]:
i += 1
else:
break
if i >= n-1:
break
p1 = max(a[i:])-a[i]
if p <=p1:
c += 1
p = p1
i = a.index(max(a[i:])) + 1
print(c) |
s617747112 | p03946 | u232852711 | 1531892450 | Python | Python (3.4.3) | py | Runtime Error | 124 | 15020 | 416 | n, t = list(map(int, input().split()))
a = list(map(int, input().split()))
remain_max = [a[-1]]*n
for i in range(1, n):
remain_max[-(i+1)] = max(a[-i], remain_max[-i])
diffs = [0]*n
for i in range(n):
diffs[i] = remain_max[i] - a[i]
max_diff = 0
ans = 0
for i in range(n):
if diffs[i] > max_diff:
max_diff = diffs[i]
ans = 1
elif diffs[i] == max_diff:
ans1 += 1
print(ans) |
s598539208 | p03946 | u443512298 | 1479423499 | Python | Python (3.4.3) | py | Runtime Error | 22 | 3064 | 880 | # coding: utf-8
# R: Right hand side
# L: Left hand side
def add_stone(stone, pos, searched_stones):
sample = searched_stones[::[1, -1][pos == "R"]]
if sample[0] == stone:
return None
for n, s in enumerate(sample[1:]):
if s == stone:
return (stone * (n + 2) + sample[1 + n:])[::[1, -1][pos == "R"]]
def stones_bfs(searched_stones):
queue = [searched_stones + "0"]
patterns = [["B", "R"], ["B", "L"], ["W", "R"], ["W", "L"]]
while queue:
stones = queue.pop(0)
if (stones.count("W") == len(stones) - 1 |
stones.count("B") == len(stones) - 1):
return int(stones[-1])
for p in patterns:
s = add_stone(*p, stones[:-1])
if s is not None:
queue += [s + str(int(stones[-1]) + 1)]
print(stones_bfs(input().strip())) |
s626493298 | p03946 | u984351908 | 1478909554 | Python | Python (3.4.3) | py | Runtime Error | 104 | 15060 | 455 | n, t = list(map(int, input().split()))
a = list(map(int, input().split()))
min = 1000000000
min_c = 0
max_dif = 0
max_dif_c = 0
for i in range(n):
if a[i] < min:
min = a[i]
min_c = 1
continue
elif a[i] == min:
min_c += 1
continue
if a[i] - min > max_dif:
max_dif = a[i] - min
max_dif_c = 1
elif a[i] - min == max_dif:
max_dif_c += 1
c = min([min_c, max_dif_c])
print(str(c))
|
s823002380 | p03946 | u984351908 | 1478909307 | Python | Python (3.4.3) | py | Runtime Error | 23 | 3064 | 422 | n, t = list(map(int, input().split()))
a = list(map(int, input().split()))
min = 1000000000
min_c = 0
max_dif = 0
max_dif_c = 0
for i in range(n):
if a[i] < min:
min = a[i]
min_c = 1
elif a[i] == min:
min_c += 1
if a[i] - min > max_dif:
max_dif = a[i] - min
max_dif_c = 1
elif: a[i] - min == max_dif:
max_dif_c += 1
c = min([min_c, max_dif_c])
print(str(c))
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.