# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
715481 | vjudge1 | Cluedo (IOI10_cluedo) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
int md(int a[],int n){
int sum=0;
for(int i=0;i<n;i++){
sum+=a[i];
}
int mid=sum/2+1;
bool cur[mid],pre[mid];
for(int i=0;i<mid;i++){
cur[i]=pre[i]=false;
}
pre[0]=true;
for(int i=0;i<mid;i++){
for(int j=0;j+a[i]<mid;j++){
if(pre[i]){
cur[j+a[i]]=true;
}
}
}
for(int i=0;i<mid;i++){
if(cur[i]){
pre[i]=true;
}
else pre[i]=false;
cur[i]=false;
}
for(int i=mid-1;i>=0;i--){
if(pre[i]){
return sum-2*i;
}
}
}
signed main(){
ios_base::sync_with_stdio(0),cin.tie(0);
int n;
cin>>n;
while(n--){
int m;
cin>>m;
int a[m];
for(int i=0;i<m;i++){
cin>>a[i];
}
cout<<md(a,m)<<"\n";
}
}