alexjercan/bugnet huggingface dataset:
Problem p00033 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

int ball[15], success, B[15], C[15];

void dfs(int lb, int lc, int qiu) {
  if (success) // 找到一种可行方案 就可以了 不必再递归
    return;
  // 如果确定【11】 最多就【10】 说明已经确定了一种方案  现在看可不可行
  if (qiu > 10) {
    int flag = 1;
    for (int i = 0; i < lb - 1; ++i) {
      if (B[i] >= B[i + 1]) {
        flag = 0;
        break;
      }
    }
    for (int i = 0; i < lc - 1; ++i) {
      if (C[i] >= C[i + 1]) {
        flag = 0;
        break;
      }
    }
    if (flag) {
      success = 1;
    }
    return;
  }

  B[lb] = ball[qiu];
  dfs(lb + 1, lc, qiu + 1);
  C[lc] = ball[qiu];
  dfs(lb, lc + 1, qiu + 1);
}

int main() {
  int n;
  scanf("%d", &n);
  while (n--) {
    for (int i = 1; i <= 10; ++i) {
      scanf("%d", &ball[i]);
    }
    success = 0;
    dfs(0, 0, 1); // 代表现在B C没球  现在看ball【1】去哪
    if (success)
      puts("YES");
    else
      puts("NO");
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
#include <cstdio>
#include <string.h>
int a[50][11];
int b[50][11], c[50][11];
// int flag[100][11];
int by = 0, cy = 0;
int lb;
int lc;
void dfs(int x, int y) {
  if (y < 10) {
    if (b[x][by] < a[x][y]) {
      b[x][++by] = a[x][y++];
      ++lb;
    } else if (c[x][cy] < a[x][y]) {
      c[x][++cy] = a[x][y++];
      ++lc;
    }
    // y +=1;

    dfs(x, y);
  }
}
void solve() {
  int n;
  cin >> n;
  while (n--) {

    for (int i = 0; i < n; i++)
      for (int j = 0; j < 10; j++)
        cin >> a[i][j];
    for (int i = 0; i < n; i++) {
      dfs(i, 0);
      if (lb + lc == 10)
        printf("YES\\n");
      else
        printf("NO\\n");
    }
  }
}

int main() {
  solve();
  return 0;
}
Problem p00033 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <list>
#include <queue>
#include <stack>
#include <vector>

using namespace std;

#define FOR(x) for (int i = 0; i < x; i++)

stack<short> left, right;
short a[10], n, j;

bool solve(short c, bool judge) {
  if (c == 10)
    return true;
  if (left.top() < a[c]) {
    left.push(a[c]);
    if (solve(c + 1, true))
      return true;
  }
  if (right.top() < a[c]) {
    right.push(a[c]);
    if (solve(c + 1, false))
      return true;
  }
  if (judge)
    left.pop();
  else
    right.pop();
  return false;
}

int main() {
  scanf("%d", &n);
  FOR(n) {
    left.push(0);
    right.push(0);
    for (j = 0; j < 10; j++)
      scanf("%d", &a[j]);
    if (solve(0, true))
      printf("YES\\n");
    else
      printf("NO\\n");
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <list>
#include <queue>
#include <stack>
#include <vector>

using namespace std;

#define FOR(x) for (int i = 0; i < x; i++)

stack<short> left, right;
short a[10], n;

bool solve(short c, bool judge) {
  if (c == 10)
    return true;
  if (left.top() < a[c]) {
    left.push(a[c]);
    if (solve(c + 1, true))
      return true;
  }
  if (right.top() < a[c]) {
    right.push(a[c]);
    if (solve(c + 1, false))
      return true;
  }
  if (judge)
    left.pop();
  else
    right.pop();
  return false;
}

int main() {
  scanf("%d", &n);
  FOR(n) {
    left.push(0);
    right.push(0);
    for (i = 0; i < 10; i++)
      scanf("%d", &a[i]);
    if (solve(0, true))
      printf("YES\\n");
    else
      printf("NO\\n");
    while (left.empty())
      left.pop();
    while (right.empty())
      right.pop();
  }
  return 0;
}
Problem p00033 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
using namespace std;

int ball[10];

bool solve(int i, int a, int b) {
  if (i == 10)
    return true;
  bool ans = false;
  if (a < ball[i])
    ans = solve(i + 1, ball[i], b);
  if (b < ball[i])
    ans = solve(i + 1, a, ball[i]);
  return ans;
}

int main() {
  int n;
  cin >> n;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> ball[j];
    }
    if (solve(0, 0, 0))
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }

  return 0;
}
// beatmaniaIIDX 23th copula

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;

int ball[10];

bool solve(int i, int a, int b) {
  if (i == 10)
    return true;
  bool ans = false;
  if (a < ball[i])
    ans = solve(i + i, ball[i], b);
  if (b < ball[i])
    ans = solve(i + i, a, ball[i]);
  return ans;
}

int main() {
  int n;
  cin >> n;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10;) {
      cin >> ball[j];
    }
    if (solve(0, 0, 0))
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }

  return 0;
}
// beatmaniaIIDX 23th copula
Problem p00033 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>

#define N 10

int D, Ball[N];
int R, L;

bool solve(int i) {
  if (i == N)
    return true;
  if (R < Ball[i]) {
    R = Ball[i];
    if (solve(i + 1))
      return true;
  }
  if (L < Ball[i]) {
    L = Ball[i];
    if (solve(i + 1))
      return true;
  }
  return false;
}

int main() {
  scanf("%d", &D);
  for (int i = 0; i < D; i++) {
    R = L = 0;
    for (int j = 0; j < N; j++)
      scanf("%d", &Ball[j]);
    R = Ball[0];
    if (solve(1))
      printf("YES\\n");
    else
      printf("NO\\n");
  }
  return 0;
}

Error: -11

Fixed submission:

#include <cstdio>

#define N 10

int D, Ball[N];
int R, L;

bool solve(int i) {
  if (i == N)
    return true;
  if (R < Ball[i]) {
    R = Ball[i];
    if (solve(i + 1))
      return true;
  }
  if (L < Ball[i]) {
    L = Ball[i];
    if (solve(i + 1))
      return true;
  }
  return false;
}

int main() {
  scanf("%d", D);
  for (int i = 0; i < D; i++) {
    R = L = 0;
    for (int j = 0; j < N; j++)
      scanf("%d", &Ball[j]);
    R = Ball[0];
    if (solve(1))
      printf("YES\\n");
    else
      printf("NO\\n");
  }
  return 0;
}
Problem p00033 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int B[11] = {0};
int C[11] = {0};

bool DFS(int *a, int i = 0, int b = 1, int c = 1) {
  bool judge = true;

  if (i == 10)
    return judge;

  judge = false;

  if (B[b - 1] < a[i]) {
    B[b] = a[i];
    judge = DFS(a, i + 1, b + 1, c);
  }
  if (C[c - 1] < a[i]) {
    C[c] = a[i];
    judge = DFS(a, i + 1, b, c + 1);
  }

  return judge;
}

int main() {
  int N;
  int i = 0;
  cin >> N;

  while (i < N) {
    int A[10];
    for (int i = 0; i < 10; i++) {
      cin >> A[i];
    }

    if (DFS(A) == true) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }

    i++;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int B[11] = {0};
int C[11] = {0};

bool DFS(int *a, int i = 0, int b = 1, int c = 1) {
  bool judge = true;

  if (i == 10)
    return judge;

  judge = false;

  if (B[b - 1] < a[i]) {
    B[b] = a[i];
    judge = DFS(a, i + 1, b + 1, c);
  }
  if (C[c - 1] < a[i]) {
    C[c] = a[i];
    judge = DFS(a, i + 1, b, c + 1);
  }

  return judge;
}

int main() {
  int N;
  int i = 0;
  cin >> N;

  while (i < N) {
    int A[10] = {0};
    for (int i = 0; i < 10; i++)
      cin >> A[i];

    if (DFS(A) == true)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;

    for (int i = 1; i <= 10; i++) {
      cout << "??????B[" << i << "]=" << B[i] << ' ';
    }
    cout << endl;

    for (int i = 1; i <= 10; i++) {
      cout << "??????C[" << i << "]=" << C[i] << ' ';
    }
    cout << endl;

    i++;
  }

  while (1)
    ;

  return 0;
}
Problem p00033 (C++) — buggy submission, verdict: Runtime Error

// 0033.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//

#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define roop(a, t) for (int a = 0; a < t; a++)
int a[10], n;
bool bit(int n, vector<int> left, vector<int> right) {
  if (n == 10) {
    bool left_f = true;
    bool left_r = true;
    roop(i, (int)left.size() - 1) {
      if (left[i + 1] <= left[i]) {
        return false;
      }
    }
    roop(i, (int)right.size() - 1) {
      if (right[i + 1] <= right[i]) {
        return false;
      }
    }
    return true;
  }
  if (left.size() > 0 && right.size() > 0) {
    if (left[left.size() - 1] > a[n] && right[right.size() - 1] > a[n]) {
      return false;
    }
  }
  vector<int> new_l = left;
  vector<int> new_r = right;

  new_l.push_back(a[n]);
  new_r.push_back(a[n]);
  return (bit(n + 1, new_l, right) || bit(n + 1, left, new_r));
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  vector<int> emptynow;
  roop(i, n) {
    roop(j, 10) { cin >> a[j]; }
    if (bit(0, emptynow, emptynow)) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
  return 0;
}


Error: -11

Fixed submission:

//
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define roop(a, t) for (int a = 0; a < t; a++)
int a[10], n;
bool bit(int n, vector<int> left, vector<int> right) {
  if (n == 10) {
    bool left_f = true;
    bool left_r = true;
    roop(i, left.size() - 1) {
      if (left[i + 1] <= left[i]) {
        return false;
      }
    }
    roop(i, right.size() - 1) {
      if (right[i + 1] <= right[i]) {
        return false;
      }
    }
    return true;
  }
  if (left[left.size() - 1] > a[n] && right[right.size() - 1] > a[n]) {
    return false;
  }
  vector<int> new_l = left;
  vector<int> new_r = right;

  new_l.push_back(a[n]);
  new_r.push_back(a[n]);
  return (bit(n + 1, new_l, right) || bit(n + 1, left, new_r));
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  vector<int> emptynow;
  roop(i, n) {
    roop(j, 10) { cin >> a[j]; }
    if (bit(0, emptynow, emptynow)) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
  return 0;
}
Problem p00033 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

int B, C, num[12], b, c;

bool dfs(int b, int c, int i) {
  if (i == 10)
    return true;
  if (b < num[i] && dfs(num[i], c, i + 1)) {
    return true;
  }
  if (c < num[i] && dfs(b, num[i], i + 1)) {
    return true;
  }
  return false;
}

int main(void) {
  int N;
  cin >> N;
  for (int j = 0; j < N; j++) {
    B = 0;
    C = 0;
    for (int i = 0; i < 10; i++) {
      cin >> num[i];
    }
    dfs(0, 0, 0);
    if (dfs(0, 0, 0))
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
#include <string>
using namespace std;

int B, C, num[20], b, c;

string dfs(int x) {
  if (x == 10)
    return "YES";
  else if (B > num[x]) {
    if (C < num[x]) {
      C = num[x];
      return dfs(x + 1);
    } else
      return "NO";
  } else if (B < num[x]) {
    B = num[x];
    return dfs(x + 1);
  }
}

int main(void) {
  int N;
  while (cin >> N) {
    B = 0;
    C = 0;
    for (int i = 0; i < 10; i++) {
      cin >> num[i];
    }
    string str = dfs(0);
    cout << str << endl;
  }
  return 0;
}
Problem p00033 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>

using namespace std;

typedef vector<int> VI;

bool dfs(const VI &balls, int idx, int l, int r) {
  if (idx >= 10)
    return true;
  int n = balls[idx];
  if (n > l && dfs(balls, idx + 1, n, r))
    return true;
  if (n > r && dfs(balls, idx + 1, l, n))
    return true;
  return false;
}

void solve() {
  VI balls;
  for (int i = 0; i < 10; i++) {
    int n;
    cin >> n;
    balls.push_back(n);
  }
  if (dfs(balls, 0, 0, 0)) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    solve();
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <cstring>
#include <iostream>

using namespace std;

const int MAX_H = 1000;
const int MAX_W = 1000;
char field[MAX_H][MAX_W];

int dy[] = {0, -1, 0, 1};
int dx[] = {-1, 0, 1, 0};

void dfs(int i, int j) {
  char c = field[i][j];
  if (c == 0)
    return;
  field[i][j] = 0; // mark as visited

  for (int k = 0; k < 4; k++) {
    int new_i = i + dy[k];
    int new_j = j + dx[k];
    if (field[new_i][new_j] == c) {
      dfs(new_i, new_j);
    }
  }
}

int main() {

  while (1) {
    int W, H;
    cin >> H >> W;
    if (W == 0 && H == 0) {
      break;
    }

    int ans = 0;

    memset(field, 0, MAX_W * MAX_H);
    for (int i = 1; i <= H; i++) {
      for (int j = 1; j <= W; j++) {
        cin >> field[i][j];
      }
    }

    for (int i = 1; i <= H; i++) {
      for (int j = 1; j <= W; j++) {
        if (field[i][j]) {
          dfs(i, j);
          ans++;
        }
      }
    }

    cout << ans << endl;
  }

  return 0;
}
Problem p00033 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <stack>
using namespace std;
int main() {
  int k, n, i, j, x[10];
  scanf("%d", &n);
  for (k = 0; k < n; k++) {
    for (i = 0; i < 10; i++) {
      scanf("%d", &x[i]);
    }
    stack<int> B;
    stack<int> C;
    B.push(x[0]);
    for (i = 1; i <= 9; i++) {
      if (x[i - 1] > x[i]) {
        C.push(x[i]);
        goto ccc;
      } else {
        B.push(x[i]);
        goto bbb;
      }
    bbb:;
    }
  ccc:
    for (j = i; j < 9; j++) {
      if (B.top() < x[j + 1]) {
        B.push(x[j + 1]);
      } else if (C.top() < x[j + 1]) {
        C.push(x[j + 1]);
      } else {
        printf("NO\\n");
        goto aaa;
      }
    }
    printf("YES\\n");
  aaa:;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <stack>
using namespace std;
int main() {
  int a, b, n, i, j, x[10];
  scanf("%d", &n);
  for (j = 0; j < n; j++) {
    for (i = 0; i < 10; i++) {
      scanf("%d", &x[i]);
    }
    stack<int> B;
    stack<int> C;
    B.push(x[0]);
    for (i = 1; i <= 9; i++) {
      if (x[i - 1] > x[i]) {
        C.push(x[i]);
        goto ccc;
      } else {
        B.push(x[i]);
        goto bbb;
      }
    bbb:;
    }
  ccc:
    for (j = i; j < 9; j++) {
      if (B.top() < x[j + 1]) {
        B.push(x[j + 1]);
      } else if (C.top() < x[j + 1]) {
        C.push(x[j + 1]);
      } else {
        printf("NO\\n");
        goto aaa;
      }
    }
    printf("YES\\n");
  aaa:;
  }
  return 0;
}
Problem p00033 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

int main() {
  int a;
  int b[10];
  cin >> a;

  for (int j = 0; j < a; j++) {

    int flg = 0;

    for (int i = 0; i < 10; i++) {
      cin >> b[i];
    }

    stack<int> ta, tb;
    ta.push(b[0]);
    tb.push(0);

    for (int k = 1; k < 10; k++) {
      if (b[k] > ta.top()) {
        ta.push(b[k]);
      } else if (b[k] > tb.top()) {
        tb.push(b[k]);
      } else {
        flg++;
        break;
      }
    }
    if (flg == 0) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;

int main() {
  int n;
  int d[10];
  vector<int> va;
  vector<int> vb;
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> d[i];
    }

    int ca = 0, cb = 0;
    va[0] = d[0];
    ca++;
    if (d[1] > va[0]) {
      va[1] = d[1];
      ca++;
    }

    else {
      vb[0] = d[1];
      cb++;
    }

    for (int j = 2; j < 10; j++) {

      if (d[j] > va[ca - 1]) {
        va.push_back(d[j]);
        ca++;
      }

      else if (d[j] > vb[cb - 1]) {
        vb.push_back(d[j]);
        cb++;
      }

      else {
        cout << "NO" << endl;
        goto FINLOOP;
      }
    }
    cout << "YES" << endl;

  FINLOOP:

    va.erase(va.begin(), va.end());
    vb.erase(vb.begin(), vb.end());
  }
  return 0;
}
Problem p00033 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

#include <string.h>

int a[13], vis[13], flag;

void dfs(int x, int l, int r)

{

  int i;

  if (x == 11)
    return;

  if (flag)
    return;

  if (a[x] > l)
    dfs(x + 1, a[x], r);

  else if (a[x] > r)
    dfs(x + 1, l, a[x]);

  else {
    flag = 1;
    return;
  }
}

int main()

{

  int T, i, j, k;

  scanf("%d", &T);

  while (T--)

  {

    flag = 0;

    for (i = 1; i <= 10; i++)

      scanf("%d", &a[i]);

    memset(vis, 0, sizeof(vis));

    dfs(1, 0, 0);

    if (flag)
      printf("NO\\n");

    else
      printf("YES\\n");
  }

  return 0;
}

Error: 1

Fixed submission:

/*
 * AOJ 0033: Ball
 * ?¢????????????????1-10???10???????????????????????????????????\\2????????????????????????????????\\??????????????????????¢????????????????????????¨???
 * ?±???????DFS
 * ?????????????????????????????\\??§???????????¶???????´????????????\\??°?????\\????????¶??§????????????
 */

#include <cstdio>
#include <iostream>

using namespace std;

int a[100], b[20][100];
int len[20];
bool ans;

void dfs(int step) {
  if (ans)
    return;
  if (step == 10) {
    ans = true;
    return;
  }
  for (int i = 0; i < 2; ++i) {
    if (len[i] == 0 || a[step] > b[i][len[i] - 1]) {
      b[i][len[i]++] = a[step];
      dfs(step + 1);
      --len[i];
    }
  }
}

void solve() {
  ans = false;
  for (int i = 0; i < 10; ++i) {
    cin >> a[i];
  }
  len[0] = len[1] = 0;
  dfs(0);
}

int main() {
  int T;
  cin >> T;
  while (T--) {
    solve();
    cout << (ans ? "YES" : "NO") << endl;
  }
  return 1;
}
Problem p00033 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>

int a[10];

int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    bool ans = true;
    for (int i = 0; i < 10; ++i) {
      scanf("%d", &a[i]);
    }
    int l, r;
    l = r = 0;
    for (int i = 0; i < 10; ++i) {
      if (a[i] > l) {
        l = a[i];
      } else if (a[i] > r) {
        r = a[i];
      } else {
        ans = false;
        break;
      }
    }
    printf("%s\\n", ans ? "YES" : "NO");
  }
  return 0;
}

Error: 1

Fixed submission:

#include <cstdio>

int a[13];

int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    bool ans = true;
    for (int i = 0; i < 10; ++i) {
      scanf("%d", &a[i]);
    }
    int l, r;
    l = r = 0;
    for (int i = 0; i < 10; ++i) {
      if (a[i] > l) {
        l = a[i];
      } else if (a[i] > r) {
        r = a[i];
      } else {
        ans = false;
        break;
      }
    }
    printf("%s\\n", ans ? "YES" : "NO");
  }
  return 1;
}
Problem p00033 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  vector<bool> b;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int o[10];
    for (int i = 0; i < 10; i++) {
      cin >> o[i];
    }
    bool bo = true;
    int l = o[0], r = 0;
    for (int i = 1; i < 10; i++) {
      if (l >= r) {
        if (o[i] >= l) {
          l = o[i];
          goto cont;
        } else {
          goto L;
        }
      } else {
      L:
        if (o[i] >= r) {
          r = o[i];
          goto cont;
        } else {
          bo = false;
        }
      }
    cont:;
    }
    b.push_back(bo);
  }
  for (bool i : b) {
    if (i)
      cout << "YES";
    else
      cout << "NO";
    cout << endl;
  }
  char ch;
  cin >> ch;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  vector<bool> l;
  int o[10], n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++)
      cin >> o[j];
    int sum = o[0], num = 0;
    for (int k = 1; k < 10; k++) {
      if (o[k] < sum) {
        num++;
      }
      sum = max(sum, o[k]);
    }
    l.push_back(!(num >= 2));
  }
  for (bool b : l) {
    if (b)
      cout << "YES";
    else
      cout << "NO";
    cout << endl;
  }
  char c;
  cin >> c;
}
Problem p00033 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

int a[20];

bool check(int x) {
  int pre = 0;
  for (int i = 0; i < 10; i++)
    if (x & (1 << i)) {
      if (a[i] < pre)
        return false;
      pre = a[i];
    }
  return true;
}

bool dfs(int i, int x, int pre) {
  if (i == 10) {
    return check(x);
  }
  bool temp = false;
  if (a[i] > pre)
    temp = dfs(i + 1, x, a[i]);
  return temp || dfs(i + 1, x | (1 << i), pre);
}

int main() {
  int T;
  cin >> T;
  while (T--) {
    for (int i = 0; i < 10; i++)
      scanf("%d", &a[i]);
    printf("%s\\n", dfs(1, 0, a[0]) ? "YES" : "NO");
  }
  return 0;
}

Error: TLE

Fixed submission:

// 1.?取?入
// 2.把桶?来?去放球
// 3.?出?果
#include <stdio.h>
#include <string.h>
#define MAXN 15
int ball[MAXN];      // A里的球?号
int bucket[2][MAXN]; //?个桶
int num[2];          //?个桶内当前球的数量
void init() {
  num[0] = num[1] = 0;
  memset(ball, 0, sizeof(ball));
  memset(bucket, 0, sizeof(bucket));
}
void getInput() {
  for (int i = 0; i < 10; i++)
    scanf("%d", &ball[i]);
}

int dfs(int no, int bktno) {
  int state = 0;
  // printf("%d\\n",no);
  if (no > 9)
    return 1;
  int bktno2 = (bktno + 1) % 2;
  if (num[bktno] == 0 || ball[no] > bucket[bktno][num[bktno]]) {
    bucket[bktno][++num[bktno]] = ball[no];
    state = dfs(no + 1, bktno);
  } else if (num[bktno2] == 0 || ball[no] > bucket[bktno2][num[bktno2]]) {
    bucket[bktno2][++num[bktno2]] = ball[no];
    state = dfs(no + 1, bktno2);
  } else {
    num[bktno]--;
    if (num[bktno] == 0)
      return 0;
    state = dfs(no - 1, bktno2);
  }
  return state;
}

int main() {
#ifdef debug
  freopen("in.txt", "r", stdin);
#endif
  int item;
  scanf("%d", &item);
  while (item--) {
    init();
    getInput();
    // for(int i=0;i<10;i++) {
    //     printf("%d ",ball[i]);
    // }
    // printf("\\n");
    if (dfs(0, 0)) {
      printf("YES\\n");
    } else {
      printf("NO\\n");
    }
  }
}