#include<bits/stdc++.h>
using namespace std;
#ifndef d
#define d(...)
#endif
#define st first
#define nd second
#define pb push_back
#define siz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
typedef long long LL;
typedef long double LD;
constexpr int INF=1e9+7;
constexpr LL INFL=1e18;
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
return os << "(" << P.st << "," << P.nd << ")";
}
constexpr int mod=INF,maxB=300000,C=10;
int p[C]={1973,2687,3529,4409,4001,4547,6101,6301,7001,10007};
//int m[C]={982462037,982465993,982470059};
int Hf[C],Hb[C],cur[C];
int main()
{
int n;
scanf("%d",&n); n=0;
char c=0;
fill(cur,cur+C,1);
while(c<33) c=getc_unlocked(stdin);
while(c>32) {
for(int i=0;i<C;i++) {
Hf[i]=((LL)Hf[i]*p[i]+c)%mod;
Hb[i]=(Hb[i]+(LL)c*cur[i])%mod;
cur[i]=((LL)cur[i]*p[i])%mod;
}
c=getc_unlocked(stdin);
}
for(int i=0;i<C;i++) {
if(Hf[i]!=Hb[i]) {
puts("NIE");
return 0;
}
}
puts("TAK");
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 46 47 48 | #include<bits/stdc++.h> using namespace std; #ifndef d #define d(...) #endif #define st first #define nd second #define pb push_back #define siz(c) (int)(c).size() #define all(c) (c).begin(), (c).end() typedef long long LL; typedef long double LD; constexpr int INF=1e9+7; constexpr LL INFL=1e18; template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) { return os << "(" << P.st << "," << P.nd << ")"; } constexpr int mod=INF,maxB=300000,C=10; int p[C]={1973,2687,3529,4409,4001,4547,6101,6301,7001,10007}; //int m[C]={982462037,982465993,982470059}; int Hf[C],Hb[C],cur[C]; int main() { int n; scanf("%d",&n); n=0; char c=0; fill(cur,cur+C,1); while(c<33) c=getc_unlocked(stdin); while(c>32) { for(int i=0;i<C;i++) { Hf[i]=((LL)Hf[i]*p[i]+c)%mod; Hb[i]=(Hb[i]+(LL)c*cur[i])%mod; cur[i]=((LL)cur[i]*p[i])%mod; } c=getc_unlocked(stdin); } for(int i=0;i<C;i++) { if(Hf[i]!=Hb[i]) { puts("NIE"); return 0; } } puts("TAK"); return 0; } |
English