#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(int _n=(n), i=0;i<_n;++i) #define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i) #define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;--i) #define TRACE(x) cerr << "TRACE(" #x ")" << endl; #define DEBUG(x) cerr << #x << " = " << (x) << endl; typedef long long LL; typedef unsigned long long ULL; class ProblemSet { public: void read(); bool check() const; private: int cnt[5][3] = {}; }; void ProblemSet::read() { int n; cin >> n; REP(i,n) { string s; cin >> s; assert(s.size() == 2); int a = s[0]-'1'; int b = s[1]-'A'; assert(a>=0 && a<5); assert(b>=0 && b<3); cnt[a][b] += 1; } } bool ProblemSet::check() const { REP(a,5) REP(b,3) { int want = a==4 ? 2 : 1; if (cnt[a][b] < want) return false; } return true; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); ProblemSet ps; ps.read(); cout << (ps.check() ? "TAK" : "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 45 46 47 | #include <bits/stdc++.h> using namespace std; #define REP(i,n) for(int _n=(n), i=0;i<_n;++i) #define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i) #define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;--i) #define TRACE(x) cerr << "TRACE(" #x ")" << endl; #define DEBUG(x) cerr << #x << " = " << (x) << endl; typedef long long LL; typedef unsigned long long ULL; class ProblemSet { public: void read(); bool check() const; private: int cnt[5][3] = {}; }; void ProblemSet::read() { int n; cin >> n; REP(i,n) { string s; cin >> s; assert(s.size() == 2); int a = s[0]-'1'; int b = s[1]-'A'; assert(a>=0 && a<5); assert(b>=0 && b<3); cnt[a][b] += 1; } } bool ProblemSet::check() const { REP(a,5) REP(b,3) { int want = a==4 ? 2 : 1; if (cnt[a][b] < want) return false; } return true; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); ProblemSet ps; ps.read(); cout << (ps.check() ? "TAK" : "NIE") << "\n"; } |