1851F - Lisa and the Martians - CodeForces Solution


bitmasks data structures greedy sortings strings trees

Please click on ads to support us..

C++ Code:

// Problem: F. Lisa and the Martians
// Contest: Codeforces - Codeforces Round 888 (Div. 3)
// URL: https://codeforces.com/contest/1851/problem/F
// Memory Limit: 512 MB
// Time Limit: 3000 ms
// Date: 2023-07-26 08:52:12
// 
// Powered by CP Editor (https://cpeditor.org)

#include <algorithm>
#include <iostream>
#include <sstream>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <string>
#include <stack>
#include <deque>
#include <queue>
#include <cmath>
#include <set>
#include <map>
using namespace std;
typedef long long LL;
using i64 = long long;

void solve() {
	int n, k;
	cin >> n >> k;
	
	vector<int> a(n);
	for (int i = 0; i < n; i ++ ) {
		cin >> a[i];
	}
	
	vector<int> p(n);
	iota(p.begin(), p.end(), 0);
	sort(p.begin(), p.end(), [&](int i, int j) {
		return a[i] < a[j];
	});
	
	int s = (1 << k) - 1, cur = 0;
	for (int i = 1; i < n - 1; i ++ ) {
		if ((s ^ (a[p[i]] ^ a[p[i + 1]])) > (s ^ (a[p[cur]] ^ a[p[cur + 1]]))) {
			cur = i;
		}
	}
	
	s = s ^ a[p[cur + 1]];
	cout << p[cur] + 1 << ' ' << p[cur + 1] + 1 << ' ' << s << '\n';
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int tt;
	cin >> tt;
	while (tt -- ) {
		solve();	
	}
	
	return 0;
}


Comments

Submit
0 Comments
More Questions

892A - Greed
32A - Reconnaissance
1236D - Alice and the Doll
1207B - Square Filling
1676D - X-Sum
1679A - AvtoBus
1549A - Gregor and Cryptography
918C - The Monster
4B - Before an Exam
545B - Equidistant String
1244C - The Football Season
1696B - NIT Destroys the Universe
1674A - Number Transformation
1244E - Minimizing Difference
1688A - Cirno's Perfect Bitmasks Classroom
219A - k-String
952A - Quirky Quantifiers
451B - Sort the Array
1505H - L BREAK into program
171E - MYSTERIOUS LANGUAGE
630D - Hexagons
1690D - Black and White Stripe
1688D - The Enchanted Forest
1674C - Infinite Replacement
712A - Memory and Crow
1676C - Most Similar Words
1681A - Game with Cards
151C - Win or Freeze
1585A - Life of a Flower
1662A - Organizing SWERC