num = gets.to_i num.times do left, right = [], [] arr = gets.chomp.split(' ').map(&:to_i) arr.each do|a| if (left.last ||0) < a left << a elsif (right.last ||0) < a right << a else break end end puts (arr.size == (left.size + right.size)) ? 'YES' : 'NO' end
🍮 Pythonコード
n = int(raw_input()) for i in range(n): left, right = [], [] arr = map(int, raw_input().split(' ')) for a in arr: if len(left) == 0or left[len(left)-1] < a: left.append(a) elif len(right) == 0or right[len(right)-1] < a: right.append(a) else: break
if len(arr) == len(left) + len(right): print'YES' else: print'NO'
😼 c++コード
#include #include
usingnamespacestd;
int a[10];
booldfs(int i, int left, int right){ if(i == 10) { returntrue; }
bool ans = false; if(left < a[i]) { ans = dfs(i+1, a[i], right); } if(right < a[i]) { ans = dfs(i+1, left, a[i]); } return ans; }
int n = Integer.parseInt(br.readLine()); for (int i = 0; i < n; i++) { String tmp = br.readLine(); String[] strArray = tmp.split(" "); List intList = Arrays.asList(strArray).stream().map(s -> Integer.valueOf(s)).collect(Collectors.toList()); ArrayList arr1 = new ArrayList<>(); ArrayList arr2 = new ArrayList<>();