|
|
Show all threads Hide all threads Show all messages Hide all messages | SPOILER. Hint | andreyDagger | 2065. Different Sums | 25 Sep 2021 20:31 | 1 | Fill n - k + 1 elements with zeros | Seriously!!!!!Why WA?? | Unsocial_A | 2065. Different Sums | 26 Sep 2018 10:23 | 1 | int main() { optimize(); int n,k; cin>>n>>k; k--; int z=k; bool b=0; int a[n+10]; for(int i=0;i<n;i++) { if(k!=0) { if(b==0) { a[i]=k; b=1; z--; } else { if(z==0) { a[i]=0; k=0; b=1; continue; } a[i]=-k; k--; b=0; z--; if(z==0) k=0; } } else a[i]=0; //dbg(z); } for(int i=n-1;i>=0;i--) cout<<a[i]<<" "; //return main(); } when going to print 0 0 -3 3 or -3 3 0 0 I am getting WA..But When I print 0 0 -1 1 I get AC..Why?what is the difference between 1st two case and last one??Can anyone explain me?? | WA27 | reshke | 2065. Different Sums | 28 Aug 2016 22:12 | 4 | WA27 reshke 25 Aug 2016 20:07 My algo generate array like [1, -1, 2, -2, 3, -3 ...,0], but i got WA27 Any suggetion's? (Bad english) Edited by author 25.08.2016 23:47 You need array like [..., -3, 3, -2, 2, -1, 1, 0], i.e. move all zeros to the beginning of your array, and you'll get AC. Edited by author 26.08.2016 12:12 I don't understand why, but it does not work anyway. Should be output be like 0 1 -1 2 -2 3 -3 4 -4....? My AC program gives answers like (0...0 1 -1 2 -2 3 -3...), but your one - (0 1 -1 2 -2 3 -3 ... n -n ... -n), as I understand. Do you see the difference? | why not an all-zero array? | Ade [FDU] | 2065. Different Sums | 2 Jan 2016 14:11 | 2 | Only one subarray sum, isn't it? At least K different (unique) numbers, read attentively. |
|
|
|