Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Problem D
#include <bits/stdc++.h> using namespace std; #define int long long int t; int getSeg(vector<int> &v) { if(v.size() == 0) return 0; int n = v.size(); int last = v[0]; int ct = 1; int ans = 1; for(int i = 1; i < n; i++) { if(last != v[i]) { ans++; last = v[i]; } } return ans; } void solve() { int n; cin >> n; int a[n]; for(int i = 0; i < n; i++) cin >> a[i]; int res = 0; int last = a[0]; int ct = 1; vector<int> v1; vector<int> v2; for(int i = 0; i < n - 1; i++) { if(a[i] == a[i + 1]) { v1.push_back(a[i]); v2.push_back(a[i + 1]); i++; } else { int last1 = v1[v1.size() - 1]; int last2 = v2[v2.size() - 1]; if(last1 != a[i] && last2 != a[i + 1]) { v1.push_back(a[i]); v2.push_back(a[i + 1]); i++; continue; } if(last1 != a[i + 1] && last2 != a[i]) { v1.push_back(a[i + 1]); v2.push_back(a[i]); i++; continue; } } } cout << getSeg(v1) + getSeg(v2); } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); t = 1; //cin >> t; while(t--) solve(); return 0; }
run
|
edit
|
history
|
help
0
341 30 - B
Subset sum
Hello world.c
ConversionOperator
Barnicle
FindMissingLagrange
FindMissingLagrange
nani
obracanie tablicy
TREE - path from root to leaf with given sum