# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
101625 | 2019-03-19T05:27:23 Z | errorgorn | Chase (CEOI17_chase) | C++14 | 2 ms | 384 KB |
#include <cstdio> #include <vector> #include <algorithm> using namespace std; long long chase=0; int n,v; long long arr[11]; bool am[11][11]; void print(vector<int> i){ for (int x=0;x<i.size();x++) printf("%d ",i[x]); printf("\n"); } int bits(int x){ int ans=0; while (x!=0){ x-=(x&(-x)); ans++; } return ans; } void simulate (vector<int> i){ long long pigeons[11]; long long ans; for (int x=0;x<(1<<i.size());x++){ if (bits(x)<=v){ ans=0; for (int y=1;y<=n;y++) pigeons[y]=arr[y]; for (int y=0;y<i.size();y++){ ans-=pigeons[i[y]]; if ( (x&(1<<y))!=0){ for (int z=1;z<=n;z++){ if (am[z][i[y]]) pigeons[i[y]]+=pigeons[z],pigeons[z]=0; } } } for (int y=0;y<i.size();y++){ ans+=pigeons[i[y]]; } if (ans>chase){ chase=ans; } } } } void dfs(vector<int> i){ simulate(i); i.push_back(-1); for (int x=0;x<n;x++){ if (am[x][i[i.size()-2]] && x!=i[i.size()-3]){ i[i.size()-1]=x; dfs(i); } } } int main(){ //freopen("input.txt","r",stdin); int a,b; scanf("%d%d",&n,&v); for (int x=1;x<=n;x++){ scanf("%lld",&arr[x]); } for (int x=1;x<n;x++){ scanf("%d%d",&a,&b); am[a][b]=true; am[b][a]=true; } vector<int> perm(1); for (int x=1;x<=n;x++){ perm[0]=x; dfs(perm); } printf("%lld\n",chase); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 256 KB | Output is correct |
3 | Correct | 2 ms | 256 KB | Output is correct |
4 | Correct | 2 ms | 256 KB | Output is correct |
5 | Correct | 2 ms | 256 KB | Output is correct |
6 | Correct | 2 ms | 256 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 256 KB | Output is correct |
3 | Correct | 2 ms | 256 KB | Output is correct |
4 | Correct | 2 ms | 256 KB | Output is correct |
5 | Correct | 2 ms | 256 KB | Output is correct |
6 | Correct | 2 ms | 256 KB | Output is correct |
7 | Incorrect | 2 ms | 256 KB | Output isn't correct |
8 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 384 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 256 KB | Output is correct |
3 | Correct | 2 ms | 256 KB | Output is correct |
4 | Correct | 2 ms | 256 KB | Output is correct |
5 | Correct | 2 ms | 256 KB | Output is correct |
6 | Correct | 2 ms | 256 KB | Output is correct |
7 | Incorrect | 2 ms | 256 KB | Output isn't correct |
8 | Halted | 0 ms | 0 KB | - |