Codechef lunchtime problem ARRP

Правка en1, от priyanka_1998, 2018-04-04 16:13:16

Problem link : https://www.codechef.com/LTIME58B/problems/ARRP

include <bits/stdc++.h>

using namespace std;

define ll long 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 vi; typedef vector vll;

define mod 1000000007

//int MAX = 2e2+1;

define inf 1e9;

ll prime[2000006];ll er[2000006];

vector 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??

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский priyanka_1998 2018-04-04 16:14:58 946
en1 Английский priyanka_1998 2018-04-04 16:13:16 1839 Initial revision (published)