//Autor: Mateusz Wasylkiewicz
//Zawody: Potyczki Algorytmiczne 2018
//Strona: http://potyczki.mimuw.edu.pl/
//Zadanie: Palindrom, runda 3B
//Czas: Theta(WEJSCIE)
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MOD = 972549269;
void wczytaj_n()
{
LL n;
cin >> n;
}
bool rozwiaz()
{
LL h1 = 0, h2 = 0, pot = 1;
char z;
while (cin >> z)
{
LL a = LL(z) - LL('a');
h1 = (10 * h1 + a) % MOD;
h2 = (h2 + a * pot) % MOD;
pot = (10 * pot) % MOD;
}
return h1 == h2;
}
void zrob_test()
{
wczytaj_n();
cout << (rozwiaz() ? "TAK" : "NIE") << '\n';
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
zrob_test();
return 0;
}
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 | //Autor: Mateusz Wasylkiewicz //Zawody: Potyczki Algorytmiczne 2018 //Strona: http://potyczki.mimuw.edu.pl/ //Zadanie: Palindrom, runda 3B //Czas: Theta(WEJSCIE) #include <bits/stdc++.h> using namespace std; typedef long long LL; const LL MOD = 972549269; void wczytaj_n() { LL n; cin >> n; } bool rozwiaz() { LL h1 = 0, h2 = 0, pot = 1; char z; while (cin >> z) { LL a = LL(z) - LL('a'); h1 = (10 * h1 + a) % MOD; h2 = (h2 + a * pot) % MOD; pot = (10 * pot) % MOD; } return h1 == h2; } void zrob_test() { wczytaj_n(); cout << (rozwiaz() ? "TAK" : "NIE") << '\n'; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); zrob_test(); return 0; } |
English