Submission #173138

# Submission time Handle Problem Language Result Execution time Memory
173138 2020-01-03T12:44:16 Z itgl Bootfall (IZhO17_bootfall) C++14
0 / 100
2 ms 400 KB
#include<bits/stdc++.h>

using namespace std;
int n;
int a[505],b[505];
bool check(int r){
  int l=0;
  sort(b+1,b+n+1);
  for(int i=n;i>0;i--){
    r-=b[i];
    l+=b[i];

    if(l>r) return 0;
    if(r==l) return 1;
  }
  return 0;
}

int main(){
  cin >> n;
  int sum=0;
  for(int i=1;i<=n;i++){
    cin>>a[i];
    sum+=a[i];
    b[i]=a[i];
  }
  if(check(sum)){
    vector<int> vec;
    b[1]=1;
    int sum1=sum-a[1];

    for(int i=1;i<=sum;i++){
      sum1++;
      if(check(sum1))vec.push_back(i);
    }

    b[1]=a[1];
    for(int i=2;i<=n;i++){
      int s=vec.size();
      if(s==0){
        cout << 0;
        return 0;
      }
      for(int j=s-1;j>=0;j--){
        b[i]=vec[j];
        sum1=sum-a[2];
        if(vec[j]!=-1)
          if(!check(sum1+vec[j]))vec[j]=-1;
      }
      b[i]=a[i];
    }
    int cnt=0;
    for(int i=0;i<vec.size();i++){
      if(vec[i]!=-1)cnt++;
    }
    cout << cnt << endl;
    for(int i=0;i<vec.size();i++){
      if(vec[i]!=-1)cout<< vec[i] << ' ';
    }
  }else cout << 0;



  return 0;
}

Compilation message

bootfall.cpp: In function 'int main()':
bootfall.cpp:53:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<vec.size();i++){
                 ~^~~~~~~~~~~
bootfall.cpp:57:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<vec.size();i++){
                 ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 400 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 400 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 400 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 400 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 400 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 400 KB Output isn't correct
2 Halted 0 ms 0 KB -