Submission #475165

# Submission time Handle Problem Language Result Execution time Memory
475165 2021-09-21T10:23:59 Z Mr_Ph Po (COCI21_po) C++14
40 / 70
1000 ms 1876 KB
///made by : Mr_Ph :D
#include<bits/stdc++.h>
#include<unordered_map>
typedef long long ll;
typedef long long int lli;
typedef unsigned long long ull;
using namespace std;
const double PI=acos(-1.0);
const ll mod=(ll)1e9+7;
//int dx[4] = {0, 0, 1, -1};
//int dy[4] = {1, -1, 0, 0};
///the defines :)
#define endl '\n'
#define vi vector<int>
#define vll vector<ll>
#define lower(s) transform(s.begin(),s.end(),s.begin(),::tolower)
#define upper(s) transform(s.begin(),s.end(),s.begin(),::toupper)
#define ent(arr) for(int i=0;i<arr.size();i++)cin>>arr[i];
#define all(arr) arr.begin(),arr.end()
#define allr(arr) arr.rbegin(),arr.rend()
#define sz size()
///the end of the defines ;)
void solve()
{
    int n;
    cin>>n;
    vll arr(n);
    ent(arr);
    vll arr1(n);
    if(n<=1000)
    {
        ll cnt=0;
        while(arr!=arr1)
        {
            ll mn=INT_MAX;
            ll start=-2,End=-1;
            for(int i=0; i<n; i++)
            {
                if(arr[i]==0)
                    if(start!=-2&&End!=-1)
                        break;
                if(arr[i]!=0)
                {
                    mn=min(mn,arr[i]);
                    if(start==-2)
                        start=i;
                    End=i;
                }
            }
            if(start!=-2&&End!=-1)
            {
                cnt++;
                for(int i=start; i<=End; i++)
                    arr[i]-=mn;
            }
        }
        cout<<cnt<<endl;
    }
    else
    {
        if((n*(n-1)/2)<100000)
        {
            set<ll>st;
            for(int i=0; i<n; i++)
                st.insert(arr[i]);
            cout<<st.sz<<endl;
        }
        else
        {
            ll cnt=0;
            for(int i=0; i<n; i++)
            {
                //cout<<arr[i]<<" ";
                if(arr[i]==0)
                    continue;
                ll e=arr[i];
                for(int j=i; j<n; j++)
                {
                    if(arr[j]<e)
                        break;
                    arr[j]-=e;
                }
                cnt++;
            }
            cout<<cnt<<endl;
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen("window.in","r",stdin);
    //freopen("output.txt","w",stdout);
    int t=1;//int st;
    //cin>>t;//cin>>st;
    while(t--)
        solve();
}

Compilation message

Main.cpp: In function 'void solve()':
Main.cpp:18:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 | #define ent(arr) for(int i=0;i<arr.size();i++)cin>>arr[i];
      |                              ~^~~~~~~~~~~
Main.cpp:28:5: note: in expansion of macro 'ent'
   28 |     ent(arr);
      |     ^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 2 ms 204 KB Output is correct
4 Incorrect 5 ms 1100 KB Output isn't correct
5 Incorrect 8 ms 1428 KB Output isn't correct
6 Execution timed out 1097 ms 1876 KB Time limit exceeded
7 Correct 13 ms 1868 KB Output is correct