比赛 2025暑期集训第2场 评测结果 ATTTTTTTTTTTTTTTTTTT
题目名称 等差子序列 最终得分 5
用户昵称 LikableP 运行时间 18.474 s
代码语言 C++ 内存使用 1.38 MiB
提交时间 2025-06-29 15:21:28
显示代码纯文本
#include <cstdio>

template <typename T> T read();
void dfs(int);

const int MAXN = 1e4 + 10;

int T;
int n;
int a[MAXN];
bool ok;

int main() {
  freopen("sequence.in", "r", stdin);
  freopen("sequence.out", "w", stdout);
  T = read<int>();
  while (T--) {
    ok = false;

    n = read<int>();
    for (int i = 1; i <= n; ++i) {
      a[i] = read<int>();
    }

    dfs(1);

    if (ok) puts("Y");
    else puts("N");
  }
  return 0;
}

int choose[4];

bool check() {
  return a[choose[2]] - a[choose[1]] == a[choose[3]] - a[choose[2]];
}

void dfs(int pos) {
  if (pos > 3) {
    if (check()) {
      ok = true;
    }
    return;
  }
  if (ok) return;
  for (int i = choose[pos - 1] + 1; i <= n; ++i) {
    choose[pos] = i;
    dfs(pos + 1);
    if (ok) return;
  }
}

#define isdigit(ch) (ch >= '0' && ch <= '9')
template <typename T> T read() {
  T res = 0, f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) res = (res << 3) + (res << 1) + (ch ^ 48);
  return res * f;
}