Diff
checker
文本
文本
圖像
文檔
Excel
文件夾
Legal
Enterprise
桌面版
定價
登入
下載 Diffchecker 桌面版
比較文本
尋找兩個文字檔案之間的差異
工具
歷史
即時編輯器
摺疊未變更行
關閉換行
檢視
拆分
統一
比對精度
智能
單詞
字符
語法突出顯示
選擇語法
忽略
文字轉換
前往第一個差異
編輯輸入
Diffchecker Desktop
執行Diffchecker最安全的方式。取得Diffchecker桌面應用程式:您的差異永遠不會離開您的電腦!
取得桌面版
First and last submission
建立於
4 年前
差異永不過期
清除
匯出
分享
解釋
17 刪除
行
總計
刪除
字符
總計
刪除
要繼續使用此功能,請升級到
Diff
checker
Pro
查看價格
69 行
全部複製
8 新增
行
總計
新增
字符
總計
新增
要繼續使用此功能,請升級到
Diff
checker
Pro
查看價格
63 行
全部複製
複製
已複製
複製
已複製
# https://www.codechef.com/viewsolution/
60594129
# https://www.codechef.com/viewsolution/
60638735
複製
已複製
複製
已複製
# cook your dish here
import sys,os,io
import sys,os,io
import math
import math
from collections import defaultdict
from collections import defaultdict
複製
已複製
複製
已複製
def ii():
return int(input())
def li():
return list(map(int,input().split()))
if(os.path.exists('input.txt')):
sys.stdin = open("input.txt","r") ; sys.stdout = open("output.txt","w")
else:
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
import bisect
import bisect
def lengthOfLIS(nums):
def lengthOfLIS(nums):
x = []
x = []
temp = [0]*(len(nums))
temp = [0]*(len(nums))
for i in range(len(nums)):
for i in range(len(nums)):
if not x:
if not x:
x.append(nums[i])
x.append(nums[i])
temp[i]=len(x)
temp[i]=len(x)
continue
continue
ind = bisect.bisect_left(x,nums[i])
ind = bisect.bisect_left(x,nums[i])
複製
已複製
複製
已複製
# replace bisect_left by bisect_right for longes non-dec subsequence
if ind==len(x):
if ind==len(x):
x.append(nums[i])
x.append(nums[i])
else:
else:
x[ind]=nums[i]
x[ind]=nums[i]
temp[i]=len(x)
temp[i]=len(x)
return temp
return temp
def lengthOfLDS(nums):
def lengthOfLDS(nums):
x = []
x = []
temp = [0]*(len(nums))
temp = [0]*(len(nums))
for i in range(len(nums)):
for i in range(len(nums)):
if not x:
if not x:
x.append(nums[i])
x.append(nums[i])
temp[i]=len(x)
temp[i]=len(x)
continue
continue
ind = bisect.bisect_left(x,nums[i])
ind = bisect.bisect_left(x,nums[i])
複製
已複製
複製
已複製
# replace bisect_left by bisect_right for longes non-dec subsequence
if ind==len(x):
if ind==len(x):
x.append(nums[i])
x.append(nums[i])
else:
else:
x[ind]=nums[i]
x[ind]=nums[i]
temp[i]=len(x)
temp[i]=len(x)
return temp[::-1]
return temp[::-1]
def solve():
def solve():
複製
已複製
複製
已複製
n =
ii(
)
n =
int(input()
)
l = li
()
l = li
st(map(int,input().split()))
a = lengthOfLIS(l)
a = lengthOfLIS(l)
for i in range(n):
for i in range(n):
l[i]=-l[i]
l[i]=-l[i]
l = l[::-1]
l = l[::-1]
b = lengthOfLDS(l)
b = lengthOfLDS(l)
ans = 0
ans = 0
for i in range(n-1):
for i in range(n-1):
ans=max(ans,a[i]+b[i+1])
ans=max(ans,a[i]+b[i+1])
print(ans)
print(ans)
複製
已複製
複製
已複製
t = 1
t =
ii(
)
t =
int(input()
)
for
_
in range(t):
for
i
in range(t):
solve()
solve()
複製
已複製
複製
已複製
已保存差異
原始文本
開啟檔案
# https://www.codechef.com/viewsolution/60594129 # cook your dish here import sys,os,io import math from collections import defaultdict def ii(): return int(input()) def li(): return list(map(int,input().split())) if(os.path.exists('input.txt')): sys.stdin = open("input.txt","r") ; sys.stdout = open("output.txt","w") else: input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline import bisect def lengthOfLIS(nums): x = [] temp = [0]*(len(nums)) for i in range(len(nums)): if not x: x.append(nums[i]) temp[i]=len(x) continue ind = bisect.bisect_left(x,nums[i]) # replace bisect_left by bisect_right for longes non-dec subsequence if ind==len(x): x.append(nums[i]) else: x[ind]=nums[i] temp[i]=len(x) return temp def lengthOfLDS(nums): x = [] temp = [0]*(len(nums)) for i in range(len(nums)): if not x: x.append(nums[i]) temp[i]=len(x) continue ind = bisect.bisect_left(x,nums[i]) # replace bisect_left by bisect_right for longes non-dec subsequence if ind==len(x): x.append(nums[i]) else: x[ind]=nums[i] temp[i]=len(x) return temp[::-1] def solve(): n = ii() l = li() a = lengthOfLIS(l) for i in range(n): l[i]=-l[i] l = l[::-1] b = lengthOfLDS(l) ans = 0 for i in range(n-1): ans=max(ans,a[i]+b[i+1]) print(ans) t = 1 t = ii() for _ in range(t): solve()
更改後文本
開啟檔案
# https://www.codechef.com/viewsolution/60638735 import sys,os,io import math from collections import defaultdict import bisect def lengthOfLIS(nums): x = [] temp = [0]*(len(nums)) for i in range(len(nums)): if not x: x.append(nums[i]) temp[i]=len(x) continue ind = bisect.bisect_left(x,nums[i]) if ind==len(x): x.append(nums[i]) else: x[ind]=nums[i] temp[i]=len(x) return temp def lengthOfLDS(nums): x = [] temp = [0]*(len(nums)) for i in range(len(nums)): if not x: x.append(nums[i]) temp[i]=len(x) continue ind = bisect.bisect_left(x,nums[i]) if ind==len(x): x.append(nums[i]) else: x[ind]=nums[i] temp[i]=len(x) return temp[::-1] def solve(): n = int(input()) l = list(map(int,input().split())) a = lengthOfLIS(l) for i in range(n): l[i]=-l[i] l = l[::-1] b = lengthOfLDS(l) ans = 0 for i in range(n-1): ans=max(ans,a[i]+b[i+1]) print(ans) t = int(input()) for i in range(t): solve()
尋找差異