877C - Slava and tanks - CodeForces Solution


constructive algorithms *1600

Please click on ads to support us..

Python Code:

import sys 
sys.setrecursionlimit(1000000000)
import math
import heapq
import time 
from collections import deque
from collections import defaultdict
mod = 10**9+7
def solve(n):
    o,e = [],[]

    for i in range(1,n+1):
        if i%2==0:
            e.append(i)
        else:
            o.append(i)
    return e+o+e
    




                
                    
    

    
n = int(input())
         
res2 = solve(n)
print(len(res2))
print(*res2)





C++ Code:

#include <bits/stdc++.h>
using namespace std;
#define umap unordered_map
#define cy cout << "YES" << endl
#define cn cout << "NO" << endl
#define ll long long
#define forn(i, l, r) for (int i = l; i <= r; i++)
#define forn_(i, l, r) for (int i = l; i >= r; i--)
#define debug(a) cout << #a << "=" << a << endl;
const int inf = 0x3f3f3f3f;
const int N = 2e5 + 5;
int T;

ll n;
void solve() {
	cin >> n;

	cout << n / 2 * 2 + (n + 1) / 2 << endl;
	for (int i = 2; i <= n; i += 2) cout << i << ' ';
	for (int i = 1; i <= n; i += 2) cout << i << ' ';
	for (int i = 2; i <= n; i += 2) cout << i << ' ';
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	T = 1;

	while (T--) solve();
	return 0;
}


Comments

Submit
0 Comments
More Questions

Lift queries
Goki and his breakup
Ali and Helping innocent people
Book of Potion making
Duration
Birthday Party
e-maze-in
Bricks Game
Char Sum
Two Strings
Anagrams
Prime Number
Lexical Sorting Reloaded
1514A - Perfectly Imperfect Array
580A- Kefa and First Steps
1472B- Fair Division
996A - Hit the Lottery
MSNSADM1 Football
MATCHES Playing with Matches
HRDSEQ Hard Sequence
DRCHEF Doctor Chef
559. Maximum Depth of N-ary Tree
821. Shortest Distance to a Character
1441. Build an Array With Stack Operations
1356. Sort Integers by The Number of 1 Bits
922. Sort Array By Parity II
344. Reverse String
1047. Remove All Adjacent Duplicates In String
977. Squares of a Sorted Array
852. Peak Index in a Mountain Array