#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
#define st first
#define nd second
typedef pair<int,int> pun;
typedef long long ll;
bool try_testing(const vector<int>& v) {
for (int start = 0; start < v.size(); start ++) {
vector<int> xs = v;
int idx = start;
while (true) {
if (idx == v.size() || xs[idx] == 0) break;
xs[idx] --;
if (idx > 0 && xs[idx - 1] > 0) idx --;
else idx ++;
}
bool broken = false;
for (int x : xs) if (x > 0) broken = true;
if (not broken) return true;
}
return false;
}
void test(bool should_print) {
int n;
cin >> n;
vector<int> v(n+1, 0);
for (int i = 0; i < n; i ++) cin >> v[i];
if (should_print) {
cerr << n << "\n";
for (int x : v) cerr << x << " ";
}
while (v.back() == 0) v.pop_back();
vector<int> xs;
int start = 0;
while (start < v.size() && v[start] == 0) start ++;
for (int i = start; i < v.size(); i ++) {
xs.push_back(v[i]);
}
bool broken = not try_testing(xs);
cout << (broken ? "NIE" : "TAK") << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
for(int i = 1; i <=t; i ++) {
test( i == 18409);
}
}
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 | #include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; #define st first #define nd second typedef pair<int,int> pun; typedef long long ll; bool try_testing(const vector<int>& v) { for (int start = 0; start < v.size(); start ++) { vector<int> xs = v; int idx = start; while (true) { if (idx == v.size() || xs[idx] == 0) break; xs[idx] --; if (idx > 0 && xs[idx - 1] > 0) idx --; else idx ++; } bool broken = false; for (int x : xs) if (x > 0) broken = true; if (not broken) return true; } return false; } void test(bool should_print) { int n; cin >> n; vector<int> v(n+1, 0); for (int i = 0; i < n; i ++) cin >> v[i]; if (should_print) { cerr << n << "\n"; for (int x : v) cerr << x << " "; } while (v.back() == 0) v.pop_back(); vector<int> xs; int start = 0; while (start < v.size() && v[start] == 0) start ++; for (int i = start; i < v.size(); i ++) { xs.push_back(v[i]); } bool broken = not try_testing(xs); cout << (broken ? "NIE" : "TAK") << "\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; for(int i = 1; i <=t; i ++) { test( i == 18409); } } |
English