#include <iostream>
using namespace std;
const int mxN = 1e6 + 13;
int tab[mxN], n;
bool spr(int p)
{
bool dod[2];
int last = tab[p];
if(p == n - 1)
return tab[p] <= 1;
for(int i = p + 1; i < n - 1; i++)
{
int tmp = tab[i] - last;
if(tmp == 0)
if(!dod[i % 2])
tmp++, dod[i % 2] = true;
if(tmp <= 0)
return false;
last = tmp;
}
if(last - tab[n - 1] == -1 && !dod[(n - 1) % 2])
return true;
else
return last - tab[n - 1] == 0 || (last - tab[n - 1] == 1 && !dod[n % 2]);
}
void TC()
{
cin >> n;
for(int i = 0; i < n; i++)
cin >> tab[i];
while(tab[n - 1] == 0)
n--;
int p = 0;
while(tab[p] == 0)
p++;
if(spr(p))
cout << "TAK";
else
cout << "NIE";
cout << '\n';
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t;
cin >> t;
while(t--)
TC();
}
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 | #include <iostream> using namespace std; const int mxN = 1e6 + 13; int tab[mxN], n; bool spr(int p) { bool dod[2]; int last = tab[p]; if(p == n - 1) return tab[p] <= 1; for(int i = p + 1; i < n - 1; i++) { int tmp = tab[i] - last; if(tmp == 0) if(!dod[i % 2]) tmp++, dod[i % 2] = true; if(tmp <= 0) return false; last = tmp; } if(last - tab[n - 1] == -1 && !dod[(n - 1) % 2]) return true; else return last - tab[n - 1] == 0 || (last - tab[n - 1] == 1 && !dod[n % 2]); } void TC() { cin >> n; for(int i = 0; i < n; i++) cin >> tab[i]; while(tab[n - 1] == 0) n--; int p = 0; while(tab[p] == 0) p++; if(spr(p)) cout << "TAK"; else cout << "NIE"; cout << '\n'; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while(t--) TC(); } |
English