#include <bits/stdc++.h>
#define qio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
const int N = 1e6 + 5;
int t, n, tab[N], x[N], l, r;
bool res;
void solve() {
x[r] = -1;
x[l] = tab[l];
for(int j = l + 1 ; j<=r ; j++){
x[j] = tab[j] - x[j-1] + 1;
if (j < r && x[j] <= 0) {
break;
}
}
if (x[r] == 0 || x[r] == 1) res = true;
}
int main() {
qio;
cin >> t;
for(int i = 1 ; i<=t ; i++){
cin>>n;
res = false;
l = 1;
r = n;
for(int j = 1 ; j<=n ; j++){
cin>>tab[j];
}
while(tab[l] == 0) l++;
while(tab[r] == 0) r--;
solve();
tab[l+1]--;
solve();
if (res) cout << "TAK\n";
else cout << "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 | #include <bits/stdc++.h> #define qio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) using namespace std; const int N = 1e6 + 5; int t, n, tab[N], x[N], l, r; bool res; void solve() { x[r] = -1; x[l] = tab[l]; for(int j = l + 1 ; j<=r ; j++){ x[j] = tab[j] - x[j-1] + 1; if (j < r && x[j] <= 0) { break; } } if (x[r] == 0 || x[r] == 1) res = true; } int main() { qio; cin >> t; for(int i = 1 ; i<=t ; i++){ cin>>n; res = false; l = 1; r = n; for(int j = 1 ; j<=n ; j++){ cin>>tab[j]; } while(tab[l] == 0) l++; while(tab[r] == 0) r--; solve(); tab[l+1]--; solve(); if (res) cout << "TAK\n"; else cout << "NIE\n"; } } |
English