This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#ifndef LOCAL
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#endif
#include <bits/stdc++.h>
using namespace std;
using vecp = vector<pair<int,int>>;
#define vecm(a,n,m) vector<vector<int>>a(n,vector<int>(m,0));
#define int int64_t
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mpii map<int,int>
#define lb lower_bound
#define ub upper_bound
#define foor(i,a,b) for(int i=a;i<b; i++)
#define foor(i,a) foor(i,0,a)
#define ins insert
#define ss second
#define ff first
#define until(x, a) for (auto x : a)
#define ln(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define seea(a,n) for(int i=0;i<n;i++){cin>>a[i];}
#define seev(v,n) for(int i=0;i<n;i++){int x; cin>>x; v.push_back(x);}
const int mod = 1E9+7;
const int MAXN=200000;
const int inf=1e18;
vector<vector<int>> g;
void solution(){
int n;
cin >> n;
int a[n];
for(int i=0; i<n; i++){
cin >> a[i];
}
vi k;
g.assign(n+1,{});
int ind=0;int cnt=0;
for(int i=0; i<n; i++){
if(k.size()>0 && i==n-1){
if(k.size()>=1){
k.push_back(a[i]);
a[i]=0;
cnt++;
g[ind]=k;
}
k.clear();
}
if(a[i]+1==a[i+1]){
k.push_back(a[i]);
a[i]=0;
}
else {
if(k.size()>=1){
k.push_back(a[i]);
a[i]=0;
cnt++;
g[ind]=k;
ind++;
}
k.clear();
}
}
for(int i=0; i<n; i++){
if(a[i]==0)continue;
if(i==n-1){
cnt++;continue;
}
if(a[i]!=0 && a[i+1]==0){
cnt++;continue;
}
if(a[i]>a[i+1]){
cnt++;
continue;
}
for(int j=0; j<n; j++){
if(g[j].size()==0)continue;
if(g[j][0]-1==a[i] && g[j].back()+1==a[i+1]){
i++;
break;
}
}
cnt++;
}
cout << cnt;
// 1 2 3 4 5
// 1 4 0 0 5
}
int32_t main(){
clock_t tStart = clock();
std::ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int q = 1; // cin >> q;
while(q--) {
solution();
cout << '\n';
}
cerr<<fixed<<setprecision(3)<<"\nTime Taken: "<<(double)(clock()- tStart)/CLOCKS_PER_SEC<<endl;
}
/*
██╗ ██╗ █████╗ ██████╗ ██╗██╗ ██╗ ██████╗████████╗
██║░░██║██╔══██╗██╔════╝░░░░░██║██║░░░██║██╔════╝╚══██╔══╝
███████║██║░░██║╚█████╗░░░░░░██║██║░░░██║╚█████╗░░░░██║░░░
██╔══██║██║░░██║░╚═══██╗██╗░░██║██║░░░██║░╚═══██╗░░░██║░░░
██║░░██║╚█████╔╝██████╔╝╚█████╔╝╚██████╔╝██████╔╝░░░██║░░░
╚═╝░░╚═╝░╚════╝░╚═════╝░░╚════╝░░╚═════╝░╚═════╝░░░░╚═╝░░░
*/
Compilation message (stderr)
money.cpp:19: warning: "foor" redefined
19 | #define foor(i,a) foor(i,0,a)
|
money.cpp:18: note: this is the location of the previous definition
18 | #define foor(i,a,b) for(int i=a;i<b; i++)
|
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |