Created
December 19, 2010 07:28
-
-
Save peryaudo/747173 to your computer and use it in GitHub Desktop.
Wrong Answer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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