Submission #497399

#TimeUsernameProblemLanguageResultExecution timeMemory
497399beksultan04Bootfall (IZhO17_bootfall)C++14
13 / 100
6 ms324 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define pii pair<int,int> #define OK puts("OK"); #define fr first #define sc second #define ret return #define scan1(a) scanf("%lld",&a); #define scan2(a,b) scanf("%lld %lld",&a, &b); #define scan3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c); #define all(s) s.begin(),s.end() #define pb push_back #define endi puts(""); const int N = 1e6+12,INF=1e9+7; int a[N],b[N],q[N],dp[N],n,sum; void add(int x){ int i; for (i=1000;i>=0;--i){ dp[i+x]+=dp[i]; } ret ; } void del(int x){ int i; for (i=0;i<=1000;++i){ dp[i+x]-=dp[i]; } ret ; } bool is(int x){ int i; for (i=1;i<=n;++i){ del(q[i]); if ((sum-q[i]+x)/2 >= x && dp[(sum-q[i]+x)/2-x]==0 || (sum-q[i]+x)/2 < x){ add(q[i]); ret 0; } add(q[i]); } ret 1; } main(){ int i,j,x; scan1(n) for (i=1;i<=n;++i) scan1(q[i]) dp[0]=1; for (i=1;i<=n;++i){ if (i!= 1 && q[i] %2 != q[i-1]%2){ cout <<0; ret 0; } sum+=q[i]; add(q[i]); } if (dp[sum/2]==0 || sum&1){ cout <<0; ret 0; } vector <int> ans; for (x=1;x<sum;++x){ if (x%2 == q[1]%2 && is(x))ans.pb(x); } cout <<ans.size()<<"\n"; for (i=0;i<ans.size();++i){ cout <<ans[i]<<" "; } }

Compilation message (stderr)

bootfall.cpp: In function 'bool is(long long int)':
bootfall.cpp:38:33: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   38 |         if ((sum-q[i]+x)/2 >= x && dp[(sum-q[i]+x)/2-x]==0 || (sum-q[i]+x)/2 < x){
      |             ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
bootfall.cpp: At global scope:
bootfall.cpp:47:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   47 | main(){
      | ^~~~
bootfall.cpp: In function 'int main()':
bootfall.cpp:70:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |     for (i=0;i<ans.size();++i){
      |              ~^~~~~~~~~~~
bootfall.cpp:48:11: warning: unused variable 'j' [-Wunused-variable]
   48 |     int i,j,x;
      |           ^
bootfall.cpp:9:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 | #define scan1(a) scanf("%lld",&a);
      |                  ~~~~~^~~~~~~~~~~
bootfall.cpp:49:5: note: in expansion of macro 'scan1'
   49 |     scan1(n)
      |     ^~~~~
bootfall.cpp:9:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 | #define scan1(a) scanf("%lld",&a);
      |                  ~~~~~^~~~~~~~~~~
bootfall.cpp:51:9: note: in expansion of macro 'scan1'
   51 |         scan1(q[i])
      |         ^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...