概要
AtCoderのABC134「Sequence Decomposing」で9/35件がTLEになってしまいます。(その他はACです。)
勉強不足で恐縮なのですが、計算量を減らす方法がわからず、ご教示いただけましたら幸いです。
何卒宜しくお願い致します。
問題
https://atcoder.jp/contests/abc134/submissions/6481452
コード
c++
1#include <iostream> 2#include <tuple> 3 4std::tuple<int, int> get_smaller_max(int a, int l[], int l_count) { 5 int max = -1, index = -1; 6 for (size_t i=0; i < l_count; i++) { 7 if (l[i] < a && l[i] > max) { 8 max = l[i]; 9 index = i; 10 } 11 } 12 return std::forward_as_tuple(max, index); 13} 14 15int main() { 16 int n; std::cin >> n; 17 18 int l[n], l_count = 0, max, index; 19 for (size_t i = 0; i < n; i++) { 20 int a; std::cin >> a; 21 std::tie(max, index) = get_smaller_max(a, l, l_count); 22 if (max == -1) { 23 l[l_count] = a; 24 l_count++; 25 } else { 26 l[index] = a; 27 } 28 } 29 30 std::cout << l_count << std::endl; 31 return 0; 32}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/07/21 23:14
2019/07/22 03:47