Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
35596 林芳菲 【J】T3 C++ 解答错误 15 1086 MS 1820 KB 1534 2024-12-13 20:03:15

Tests(3/20):


#include <cstdio> #include <iostream> #include <algorithm> using namespace std; int t, n; int a[200010]; int c[200010]; bool isPal(int x) { int l = 1, r = n; while (l <= r) { if (a[l] != a[r]) { if (a[l] == x) l++; if (a[r] == x) r--; if (l <= r && a[l] != a[r]) return false; } l++, r--; } return true; } int main() { // freopen("flogic.in", "r", stdin); // freopen("flogic.out", "w", stdout); cin >> t; while (t--) { cin >> n; int cnt = 0; for (int i = 1; i <= n; i++) c[i] = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; cnt += 1 - c[a[i]]; c[a[i]] = 1; } int l = 1, r = n; bool ansIsFound = false; while (l <= r) { if (a[l] != a[r]) { bool f1 = isPal(a[l]); bool f2 = isPal(a[r]); int ty = 0; if (f1 && f2) ty = 3; else if (f1) ty = 2; else if (f2) ty = 1; if (ty == 0) { ansIsFound = true; cout << "0" << endl << endl; break; } else if (ty == 1) { ansIsFound = true; cout << "1" << endl; cout << a[r] << endl; break; } else if (ty == 2) { ansIsFound = true; cout << "1" << endl; cout << a[l] << endl; break; } } l++, r--; } if (!ansIsFound) { cout << cnt << endl; for (int i = 1; i <= n; i++) if (c[i]) cout << i << " "; cout << endl; } } // fclose(stdin); // fclose(stdout); return 0; }


测评信息: