답안 #1008298

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1008298 2024-06-26T09:03:02 Z m5588ohammed Bootfall (IZhO17_bootfall) C++14
0 / 100
40 ms 77652 KB
/******************************************************************************
 
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.
 
*******************************************************************************/
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
 
int vis[270][72902];
int arr[270],skip=-1,t,flag=0;
int ans[270],curr[72902];
int n;
void solve(int i,int sum){
    if(((t-arr[skip])-sum)-sum<0) return;
    if(vis[i][sum]==1) return;
    
    if(i==n){
        curr[((t-arr[skip])-sum)-sum]=1;
        return;
    }
    
    if(i!=skip) solve(i+1,sum+arr[i]);
    solve(i+1,sum);
    vis[i][sum]=1;
    return;
}
void check(int i,int sum){
    if(sum>(t+1)/2) return;
    if(vis[i][sum]==1) return ;
    
    if(i==n){
        if(t/2==sum) flag=1;
        return;
    }
    
    
    check(i+1,sum+arr[i]);
    check(i+1,sum);
    vis[i][sum]=1;
    return;
}
signed main()
{
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>arr[i];
        t+=arr[i];
    }
    
    if(t%2==0) check(0,0);
    if(flag==0){
        cout<<0<<endl;
        return 0;
    }
    
    skip=0;
    memset(vis,0,sizeof vis);
    solve(0,0);
    for(int i=1;i<=72901;i++) ans[i]=curr[i];
    for(int i=1;i<n;i++){
        skip=i;
        memset(vis,0,sizeof vis);
        memset(curr,0,sizeof curr);
        solve(0,0);
        for(int j=1;j<=72901;j++) ans[j]=min(ans[j],curr[j]);
        for(int j=1;j<=72901;j++) ans[j]=min(ans[j],curr[j]);
    }
    
    int siz=0;
    for(int j=1;j<=72901;j++) siz+=ans[j];
    cout<<siz<<endl;
    for(int j=1;j<=72901;j++) if(ans[j]==1) cout<<j<<" ";
    return 0;
}

Compilation message

bootfall.cpp: In function 'int main()':
bootfall.cpp:63:37: warning: iteration 269 invokes undefined behavior [-Waggressive-loop-optimizations]
   63 |     for(int i=1;i<=72901;i++) ans[i]=curr[i];
      |                               ~~~~~~^~~~~~~~
bootfall.cpp:63:18: note: within this loop
   63 |     for(int i=1;i<=72901;i++) ans[i]=curr[i];
      |                 ~^~~~~~~
bootfall.cpp:69:41: warning: iteration 269 invokes undefined behavior [-Waggressive-loop-optimizations]
   69 |         for(int j=1;j<=72901;j++) ans[j]=min(ans[j],curr[j]);
      |                                   ~~~~~~^~~~~~~~~~~~~~~~~~~~
bootfall.cpp:69:22: note: within this loop
   69 |         for(int j=1;j<=72901;j++) ans[j]=min(ans[j],curr[j]);
      |                     ~^~~~~~~
bootfall.cpp:70:41: warning: iteration 269 invokes undefined behavior [-Waggressive-loop-optimizations]
   70 |         for(int j=1;j<=72901;j++) ans[j]=min(ans[j],curr[j]);
      |                                   ~~~~~~^~~~~~~~~~~~~~~~~~~~
bootfall.cpp:70:22: note: within this loop
   70 |         for(int j=1;j<=72901;j++) ans[j]=min(ans[j],curr[j]);
      |                     ~^~~~~~~
bootfall.cpp:74:41: warning: iteration 269 invokes undefined behavior [-Waggressive-loop-optimizations]
   74 |     for(int j=1;j<=72901;j++) siz+=ans[j];
      |                                    ~~~~~^
bootfall.cpp:74:18: note: within this loop
   74 |     for(int j=1;j<=72901;j++) siz+=ans[j];
      |                 ~^~~~~~~
bootfall.cpp:76:39: warning: iteration 269 invokes undefined behavior [-Waggressive-loop-optimizations]
   76 |     for(int j=1;j<=72901;j++) if(ans[j]==1) cout<<j<<" ";
      |                                  ~~~~~^
bootfall.cpp:76:18: note: within this loop
   76 |     for(int j=1;j<=72901;j++) if(ans[j]==1) cout<<j<<" ";
      |                 ~^~~~~~~
bootfall.cpp:63:37: warning: 'void* __builtin_memcpy(void*, const void*, long unsigned int)' forming offset [1080, 291607] is out of the bounds [0, 1080] of object 'ans' with type 'int [270]' [-Warray-bounds]
   63 |     for(int i=1;i<=72901;i++) ans[i]=curr[i];
      |                               ~~~~~~^~~~~~~~
bootfall.cpp:15:5: note: 'ans' declared here
   15 | int ans[270],curr[72902];
      |     ^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 40 ms 77652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 40 ms 77652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 40 ms 77652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 40 ms 77652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 40 ms 77652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 40 ms 77652 KB Output isn't correct
2 Halted 0 ms 0 KB -