# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
632191 | Jovan26 | Kpart (eJOI21_kpart) | C++14 | 1014 ms | 492 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
bool podeli(int arr[], int x,int y)
{
int totalSum = 0, i;
for(i=x; i<y; i++)
totalSum += arr[i];
// if sum is odd then does not exist.
if( (totalSum & 1) != 0)
return false;
// Sum of each part.
int partSum = totalSum/2;
// latest compilers allows variable length arrays.
// Else declare the array on heap
bool partArr[partSum+1][33];
// initialize top row as true
for (i = x; i <= y; i++)
partArr[0][i] = true;
// initialize first column as false (except part[0][0])
for (i = 1; i <= partSum; i++)
partArr[i][0] = false;
// Fill the partition table in botton up manner
for (i = x+1; i <= partSum; i++)
{
for (int j = x+1; j <= y; j++)
{
partArr[i][j] = partArr[i][j-1];
if (i >= arr[j-1])
partArr[i][j] = partArr[i][j] || partArr[i - arr[j-1]][j-1];
}
}
return partArr[partSum][y];
}
int main(){
int t;
cin>>t;
vector<int> u[t];
for(int e = 0; e<t;e++){
int n;
cin>>n;
int a[n];
int br[n+1];
for(int i=0;i<n;i++){
cin>>a[i];
br[i] = 0;
}
br[n] = 0;
for(int i=2;i<=n;i++){
for(int j=0;j<=n-i;j++){
if(podeli(a,j,j+i)){
br[i]++;
}
}
}
int rez = 0;
for(int i=2;i<=n;i++){
if(br[i]==n-i+1){
rez++;
}
}
u[e].push_back(rez);
for(int i=2;i<=n;i++) {
if(br[i]==n-i+1) u[e].push_back(i);
}
}
for(int i=0;i<t;i++){
for(int j=0;j<u[i].size();j++){
cout<<u[i][j];
if(j!=u[i].size()-1) cout<<" ";
}
if(i!=t-1) cout<<endl;
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |