Problem link : https://www.codechef.com/LTIME58B/problems/ARRP↵
↵
↵
#include <bits/stdc++.h>↵
↵
using namespace std;↵
↵
#define ll lSolutiong long int↵
#define lld long double↵
↵
#define pb push_back↵
#define mp make_pair↵
#define all(c) (c).begin(), (c).end()↵
#define io ios::sync_with_stdio(false);cin.tie(NULL)↵
↵
#define trace1(x) cout <<#x<<": "<<x<<endl;↵
#define trace2(x, y) cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;↵
#define trace3(x, y, z) cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;↵
#define trace4(a, b, c, d) cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;↵
#define trace5(a, b, c, d, e) cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;↵
↵
#define siz(a) (ll)a.size()↵
↵
typedef vector<int> vi;↵
typedef vector<ll> vll;↵
↵
#define mod 1000000007↵
//int MAX = 2e2+1;↵
#define inf 1e9;↵
↵
ll prime[2000006];ll er[2000006];↵
↵
vector<ll> divisors[2000006];ink : https://www.codechef.com/viewsolution/18034419 ↵
↵
↵
int main(){↵
↵
ll t;↵
cin>>t;↵
↵
while(t--){↵
↵
ll n;↵
cin>>n;↵
↵
ll a[n];↵
↵
for(ll i=1;i<=n;i++)↵
cin>>a[i];↵
↵
ll prefix[n];↵
↵
↵
prefix[1]=a[1];↵
↵
for(ll i=2;i<=n;i++)↵
prefix[i]=prefix[i-1]+a[i];↵
↵
ll sum=prefix[n];↵
↵
↵
↵
cout<<"1";↵
↵
for(ll i=2;i<=n;i++){↵
↵
ll flag=0;↵
↵
if(sum%i==0){↵
↵
flag=1;↵
↵
ll k=sum/i;↵
ll p=k;↵
↵
for(ll j=1;j<=n;j++){↵
↵
if(prefix[j]==p)↵
p=p+k;↵
else if(prefix[j]>p){↵
flag=0;↵
break;↵
}↵
↵
} ↵
}↵
↵
if(flag)↵
cout<<"1";↵
else↵
cout<<"0";↵
↵
}↵
↵
cout<<"\n";↵
↵
↵
↵
}↵
↵
↵
return 0;↵
↵
↵
↵
}↵
↵
↵
can anyone help me to compute the time complexity of my code . ↵
It got accepted How??
↵
#include <bits/stdc++.h>↵
↵
using namespace std;↵
↵
#define ll l
#define lld long double↵
↵
#define pb push_back↵
#define mp make_pair↵
#define all(c) (c).begin(), (c).end()↵
#define io ios::sync_with_stdio(false);cin.tie(NULL)↵
↵
#define trace1(x) cout <<#x<<": "<<x<<endl;↵
#define trace2(x, y) cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;↵
#define trace3(x, y, z) cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;↵
#define trace4(a, b, c, d) cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;↵
#define trace5(a, b, c, d, e) cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;↵
↵
#define siz(a) (ll)a.size()↵
↵
typedef vector<int> vi;↵
typedef vector<ll> vll;↵
↵
#define mod 1000000007↵
//int MAX = 2e2+1;↵
#define inf 1e9;↵
↵
ll prime[2000006];ll er[2000006];↵
↵
vector<ll> divisors[2000006];
↵
↵
int main(){↵
↵
ll t;↵
cin>>t;↵
↵
while(t--){↵
↵
ll n;↵
cin>>n;↵
↵
ll a[n];↵
↵
for(ll i=1;i<=n;i++)↵
cin>>a[i];↵
↵
ll prefix[n];↵
↵
↵
prefix[1]=a[1];↵
↵
for(ll i=2;i<=n;i++)↵
prefix[i]=prefix[i-1]+a[i];↵
↵
ll sum=prefix[n];↵
↵
↵
↵
cout<<"1";↵
↵
for(ll i=2;i<=n;i++){↵
↵
ll flag=0;↵
↵
if(sum%i==0){↵
↵
flag=1;↵
↵
ll k=sum/i;↵
ll p=k;↵
↵
for(ll j=1;j<=n;j++){↵
↵
if(prefix[j]==p)↵
p=p+k;↵
else if(prefix[j]>p){↵
flag=0;↵
break;↵
}↵
↵
} ↵
}↵
↵
if(flag)↵
cout<<"1";↵
else↵
cout<<"0";↵
↵
}↵
↵
cout<<"\n";↵
↵
↵
↵
}↵
↵
↵
return 0;↵
↵
↵
↵
}↵
↵
↵
can anyone help me to compute the time complexity of my code . ↵
It got accepted How??