1005A - Tanya and Stairways - CodeForces Solution


implementation *800

Please click on ads to support us..

Python Code:

n = int(input())
w = [int(i) for i in input().split()]

print(w.count(1))
d = []
for i in range(1, n):
    if w[i] == 1:
        d.append(w[i-1])
d.append(w[-1])
print(*d)

C++ Code:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
typedef long long int lint;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
template <typename T>
using ordered_set = tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>;
#define of(m) find_by_order((m)); //random access of ordered set
#define all(v) (v).begin(),(v).end()
#define r_all(v) (v).rbegin(),(v).rend()
#define s(v) (v).size()
#define endl "\n";
#define NO cout << "NO\n";
#define YES cout << "YES\n";
#define No cout << "No\n";
#define Yes cout << "Yes\n";
#define PF push_front
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define rep(i, m) for(ll i=0;i<(m);++i)
#define rep_inv(i,m) for(ll i=(m);i>=0;--i)
#define repn(i,in, m) for(ll i=(in);i<(m);++i)
#define repn_inv(i,m,in) for(ll i=(in);i>=(m);--i)
#define clr(a) memset((a),0,sizeof(a))
#define vi vector<int>
#define vll vector<ll>

const int MOD = 1e9 + 7;
const int N = 1e6 + 5;

void print_vec(vector<ll>& v){
    for(ll i=0; i<s(v); i++) cout << v[i] << " ";
    cout << endl
}
bool is_sorted(vector<ll>& v){
    bool x = true;
    for(ll i=0; i<s(v)-1; i++) x &= (v[i] <= v[i+1]);
    return x;
}

const ll M = 27;
ll vis[M];
vector<char> g[M];
vector<char> topo;

void dfs(char u){
    vis[u-'A'] = 1;
    for(auto &v: g[u-'A']){
        if(!vis[v-'A']) dfs(v);
    }
    topo.push_back(u);
}

bool is_palindrome_s(string s) {
    string p = s;
    reverse(all(p));
    if (s == p) return true;
    else return false;
}


int main() {
    ll n; cin >> n;
    vll v(n);
    rep(i, n) cin >> v[i];
    vll ans;
    repn(i, 1, n){
        if(v[i] == 1) ans.PB(v[i-1]);
    }
    ans.PB(v[n-1]);
    cout << s(ans) << endl
    print_vec(ans);
    return 0;
}


Comments

Submit
0 Comments
More Questions

768A - Oath of the Night's Watch
156C - Cipher
545D - Queue
459B - Pashmak and Flowers
1538A - Stone Game
1454C - Sequence Transformation
165B - Burning Midnight Oil
17A - Noldbach problem
1350A - Orac and Factors
1373A - Donut Shops
26A - Almost Prime
1656E - Equal Tree Sums
1656B - Subtract Operation
1656A - Good Pairs
1367A - Short Substrings
87A - Trains
664A - Complicated GCD
1635D - Infinite Set
1462A - Favorite Sequence
1445B - Elimination
1656C - Make Equal With Mod
567A - Lineland Mail
1553A - Digits Sum
1359B - New Theatre Square
766A - Mahmoud and Longest Uncommon Subsequence
701B - Cells Not Under Attack
702A - Maximum Increase
1656D - K-good
1426A - Floor Number
876A - Trip For Meal