Submission #34046210


Source Code Expand

//Author = Anirudh Srikanth (yeetholmes619) [B20CS006]
//https://github.com/yeetholmes619/Template.git
#include<bits/stdc++.h>
#define curtime             chrono::high_resolution_clock::now()
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#define timedif(start,end)  chrono::duration_cast<chrono::nanoseconds>(end - start).count()
using namespace std;
#define RESET   "\033[0m"
#define BR   "\033[1m\033[31m"      /* Bold Red */
#define BG   "\033[1m\033[32m"      /* Bold Green */
#define BB   "\033[1m\033[34m"      /* Bold Blue */
#define ll long long
#define ld long double
#define INF 1000000007
#define pb push_back
#define pf push_front
#define FOR(i,a,b) for(int i = a; i <= b; i++)
#define ROF(i,a,b) for(int i = a; i >= b; i--)
#define vi vector<int>
#define vvi vector<vectort<int>>
#define vpii vector<pair<int,int>>
#define pii pair<int,int>
#define mii map<int,int>
#define mci map<char,int>
//as seen on https://codeforces.com/profile/I_love_Tanya_Romanova 's template
//in order to be able to use pre-defined variables in STL
#define y0 sdkfaslhagaklsldk
#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define norm asdfasdgasdgsd
#define left asdgashgrketwjklrej
#define have adsgagshdshfhds
#define ends asdgahhfdsfshdshfd
#define prev asdgSHJsfgsdfhdsh

#define umap unordered_map
#define sz(x) (int)(x.size())
#define mp make_pair
#define allvec(v) v.begin(), v.end()
#define int long long
#define output(value) cout << value << "\n"
#define error(errorString) cout << BR << errorString << RESET<< "\n"
#define info(infoString) cout << BB << infoString << RESET << "\n"
#define success(successString) cout << BB << successString << RESET << "\n"
#define allarr(a,n) a, a+n
const int mod1 =1000000007;
const int mod2 = 998244353;
// precedence order :- double > float > long long int > long int > int > char
// remember that boolean arrays and variables if uninitialized are given false
// say x is a character, s += x is faster than s = s+x
//Check if constraints are correct
// for single arrays declare them as long long int
//overflow must be taken care of!! use strings when big
//	0 < |int| < 1e9
//	0 < |long long int| < 1e18
//when you are working with stacks, remember to take care of stacks of 0 size
//when you see a problem, and you know how you would tackle it in the real world, but don't know how
//you would do it in code, go step by step, in each step try to be concious of what you want to do
//and once you have done so, review through and remember what data structure would be perfect
//when we pass an array in a function the pointer is passed but when we pass a vector, a copy is passed
template<typename T1, typename T2> // cin >> pair<T1, T2>
istream& operator>>(istream &istream, pair<T1, T2> &p) { return (istream >> p.first >> p.second); } 
template<typename T> // cin >> vector<T>
istream& operator>>(istream &istream, vector<T> &v)
{
	for (auto &it : v)
		cin >> it;
	return istream;
}
 
template<typename T1, typename T2> // cout << pair<T1, T2>
ostream& operator<<(ostream &ostream, const pair<T1, T2> &p) { return (ostream << p.first << " " << p.second); }
template<typename T> // cout << vector<T>
ostream& operator<<(ostream &ostream, const vector<T> &c) { for (auto &it : c) cout << it << " "; return ostream; }
 
//\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\DEBUG/\/\/\/\/\/\/\/\/\/\/\/\///\/\/
void __print(int32_t x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n"<<RESET;}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef DEBUG
#define debug(x...) cerr <<BR<< "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

//\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\///\/\/\/\/\/\/
//\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\GLOBAL VARIABLES/\/\/\/\/\/\/\/\/\/\/\/\///\/\/
int n;
vi v;
//\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\///\/\/\/\/\/\/
void take(){
        cin>>n;
        v.resize(2*n);
        cin>>v;
}

void solve(){
        take();
        vi ans;
        for(int i = 0; i < (2*n)-1; i++){
                if(i%2 == 0){
                        if(v[i] > v[i+1]){
                                swap(v[i],v[i+1]);
                                ans.pb(i+1);
                        }
                }else if(v[i] < v[i+1]){
                        ans.pb(i+1);
                        swap(v[i],v[i+1]);
                }
        }
        if(ans.size() > n){
                ans.clear();
                for(int i = 1; i <= 2*n-1; i+=2){
                        ans.pb(i);
                }

                cout<<ans.size()<<"\n";
                cout<<ans<<"\n";
                return;
        }
        cout<<ans.size()<<"\n";
        cout<<ans<<"\n";
}


int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    auto time0 = curtime;
	ll t = 1;
	for(int i = 1 ; i <= t; i++) {
		//cout << "Case #" << i << ": ";
		solve();
	}
#ifdef YEET
    cerr<<"Execution Time: "<<timedif(time0,curtime)*1e-9<<" sec\n";
#endif
}

Submission Info

Submission Time
Task A - Make it Zigzag
User yeetholmes619
Language C++ (GCC 9.2.1)
Score 400
Code Size 6110 Byte
Status AC
Exec Time 32 ms
Memory 6784 KiB

Compile Error

./Main.cpp: In function ‘void solve()’:
./Main.cpp:133:23: warning: comparison of integer expressions of different signedness: ‘std::vector<long long int>::size_type’ {aka ‘long unsigned int’} and ‘long long int’ [-Wsign-compare]
  133 |         if(ans.size() > n){
      |            ~~~~~~~~~~~^~~
./Main.cpp: In function ‘int32_t main()’:
./Main.cpp:151:10: warning: variable ‘time0’ set but not used [-Wunused-but-set-variable]
  151 |     auto time0 = curtime;
      |          ^~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 2
AC × 23
Set Name Test Cases
Sample 00-sample-001.txt, 00-sample-002.txt
All 00-sample-001.txt, 00-sample-002.txt, 01-001.txt, 01-002.txt, 01-003.txt, 01-004.txt, 01-005.txt, 01-006.txt, 01-007.txt, 01-008.txt, 01-009.txt, 01-010.txt, 01-011.txt, 01-012.txt, 01-013.txt, 01-014.txt, 01-015.txt, 01-016.txt, 01-017.txt, 01-018.txt, 01-019.txt, 01-020.txt, 01-021.txt
Case Name Status Exec Time Memory
00-sample-001.txt AC 7 ms 3604 KiB
00-sample-002.txt AC 2 ms 3608 KiB
01-001.txt AC 2 ms 3588 KiB
01-002.txt AC 2 ms 3632 KiB
01-003.txt AC 2 ms 3524 KiB
01-004.txt AC 2 ms 3620 KiB
01-005.txt AC 3 ms 3580 KiB
01-006.txt AC 3 ms 3520 KiB
01-007.txt AC 22 ms 5060 KiB
01-008.txt AC 13 ms 4016 KiB
01-009.txt AC 23 ms 5620 KiB
01-010.txt AC 8 ms 3740 KiB
01-011.txt AC 26 ms 5000 KiB
01-012.txt AC 30 ms 5792 KiB
01-013.txt AC 30 ms 5788 KiB
01-014.txt AC 30 ms 5784 KiB
01-015.txt AC 30 ms 5864 KiB
01-016.txt AC 32 ms 5768 KiB
01-017.txt AC 31 ms 5808 KiB
01-018.txt AC 30 ms 5772 KiB
01-019.txt AC 30 ms 5712 KiB
01-020.txt AC 24 ms 4728 KiB
01-021.txt AC 32 ms 6784 KiB