Pagini recente » Cod sursa (job #704469) | Cod sursa (job #3041049) | Rating Simon Aniko (Aniko) | Cod sursa (job #2521584) | Cod sursa (job #3289544)
#include <fstream>
#include <unordered_map>
using namespace std;
ifstream fin("nivele.in");
ofstream fout("nivele.out");
unordered_map<int, int> mp;
bool is_power_of_two(int y) {
return (y > 0) && ((y & (y - 1)) == 0);
}
bool verif(int x, int y) {
return (is_power_of_two(y) && y >= 2 && y <= (1 << (x - 1))) || (x == 2 && y <= 2);
}
int main() {
int t;
fin >> t;
while (t--) {
int n, x, y;
fin >> n;
mp.clear();
for (int i = 1; i <= n; i++) {
fin >> x;
mp[x]++;
}
bool valid = true;
for (auto &t : mp) {
x = t.first;
y = t.second;
if (!verif(x, y)) {
valid = false;
break;
}
}
fout << (valid ? "DA" : "NU") << "\n";
}
return 0;
}