#include <cstdint>
#include <iostream>
#include <vector>
using namespace std;
namespace {
constexpr bool DEBUG = false;
} // namespace
auto main() -> int {
std::ios_base::sync_with_stdio(false);
// NOLINTBEGIN(readability-identifier-length)
int t = 0;
int n = 0;
int64_t a = 0;
// NOLINTEND(readability-identifier-length)
bool started = false;
int first = 0;
int last = 0;
int64_t diff = 0;
int64_t ends = 0;
std::vector<int64_t> toys;
cin >> t;
for (int i = 0; i < t; i++) {
cin >> n;
started = false;
toys.clear();
toys.reserve(n);
for (int j = 0; j < n; j++) {
cin >> a;
toys.push_back(a);
if (a > 0) {
if (!started) {
started = true;
first = j;
}
last = j;
}
}
diff = 0;
ends = 0;
for (int j = first; j < last; j++) {
diff = 2 * toys[j] - diff;
if (diff <= 0) {
ends += (1 - diff);
if (diff > 2) {
break;
}
diff = 1;
}
}
diff = 2 * toys[last] - diff;
if (diff < 0) {
ends -= diff;
diff = 0;
}
ends += diff;
cout << (ends <= 2 ? "TAK\n" : "NIE\n");
}
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | #include <cstdint> #include <iostream> #include <vector> using namespace std; namespace { constexpr bool DEBUG = false; } // namespace auto main() -> int { std::ios_base::sync_with_stdio(false); // NOLINTBEGIN(readability-identifier-length) int t = 0; int n = 0; int64_t a = 0; // NOLINTEND(readability-identifier-length) bool started = false; int first = 0; int last = 0; int64_t diff = 0; int64_t ends = 0; std::vector<int64_t> toys; cin >> t; for (int i = 0; i < t; i++) { cin >> n; started = false; toys.clear(); toys.reserve(n); for (int j = 0; j < n; j++) { cin >> a; toys.push_back(a); if (a > 0) { if (!started) { started = true; first = j; } last = j; } } diff = 0; ends = 0; for (int j = first; j < last; j++) { diff = 2 * toys[j] - diff; if (diff <= 0) { ends += (1 - diff); if (diff > 2) { break; } diff = 1; } } diff = 2 * toys[last] - diff; if (diff < 0) { ends -= diff; diff = 0; } ends += diff; cout << (ends <= 2 ? "TAK\n" : "NIE\n"); } } |
English