Pagini recente » Cod sursa (job #1890360) | Cod sursa (job #3145054) | Cod sursa (job #1001200) | Cod sursa (job #2613955) | Cod sursa (job #2683509)
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
ifstream f("nivele.in");
ofstream g("nivele.out");
const int maxn = 50005;
int n;
int a[maxn];
int pwr(int x, int y) {
if(y == 0) { return 1; }
if(y == 1) { return x; }
int half = pwr(x, y / 2);
if(y % 2 == 0) {
return half * half;
} else {
return half * half * x;
}
}
bool solve(int n, int a[]) {
if(n > 50000) { return false; }
int i;
int lasty = 1, lastx = 1;
sort(a+1, a+n+1);
for(i = 1; i <= n; i ++) {
if(lastx <= 0) { return true; }
lastx = lastx * pwr(2, a[i] - lasty);
lastx --;
lasty = a[i];
}
if(lastx == 0) { return true; }
return false;
}
int main()
{
int t;
f >> t;
while(t --) {
f >> n;
for(int i = 1; i <= n; i ++) {
f >> a[i];
}
g << (solve(n, a) == true ? "DA" : "NU") << '\n';
}
f.close(); g.close();
return 0;
}