Skip to content

Instantly share code, notes, and snippets.

@peryaudo
Created December 19, 2010 07:28
Show Gist options
  • Save peryaudo/747173 to your computer and use it in GitHub Desktop.
Save peryaudo/747173 to your computer and use it in GitHub Desktop.
Wrong Answer
#include <cstdio>
#include <vector>
#include <queue>
using namespace std;
class M {
public:
int total, pos;
M(int total, int pos){
this->total = total;
this->pos = pos;
return;
}
};
int main()
{
int N;
scanf("%d\n", &N);
vector<int> v(N);
for(int i = 0; i < N; i++)
scanf("%d", &v[i]);
v.pop_back();
N--;
long long total = 0;
queue<M> q;
q.push(M(v[0], 1));
while(!q.empty()){
M m = q.front(); q.pop();
if(m.pos > (N - 1)){
total++;
continue;
}
int t = m.total + v[m.pos];
if(0 <= t && t < 20){
q.push(M(t, m.pos + 1));
}
t = m.total - v[m.pos];
if(0 <= t && t < 20){
q.push(M(t, m.pos + 1));
}
}
printf("%lld\n", total);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment