1138B - Circus - CodeForces Solution


brute force greedy math strings *1800

Please click on ads to support us..

C++ Code:

/*
Problem: 1138B
Date: 22-01-2024 05:16 AM
*/


#include <iostream>
#include <set>
#include <vector>
#include <cmath>

using namespace std;

int n;
string c, a;
vector<int> s[2][2];
vector<int> f;

int main() {
	cin >> n >> c >> a;
	for(int i = 0; i < n; i++) {
		s[c[i] - '0'][a[i] - '0'].push_back(i + 1);
	}
	int na = s[0][0].size(), nb = s[0][1].size(), nc = s[1][0].size(), nd = s[1][1].size();
	for(int a = 0; a <= na; a++) {
		for(int b = 0; b <= nb; b++) {
			int d = a - n/2 + nb + nd;
			int c = nb + nd - b - 2 * d;
			if(0 <= c && c <= nc && 0 <= d && d <= nd) {
				for(int i = 0; i < a; i++) {
					cout << s[0][0][i] << " ";
				}for(int i = 0; i < b; i++) {
					cout << s[0][1][i] << " ";
				}for(int i = 0; i < c; i++) {
					cout << s[1][0][i] << " ";
				}for(int i = 0; i < d; i++) {
					cout << s[1][1][i] << " ";
				}
				return 0;
			}
		}
	}
	cout << -1 << endl;
}


Comments

Submit
0 Comments
More Questions

1300B - Assigning to Classes
1647A - Madoka and Math Dad
710A - King Moves
1131A - Sea Battle
118A - String Task
236A - Boy or Girl
271A - Beautiful Year
520B - Two Buttons
231A - Team
479C - Exams
1030A - In Search of an Easy Problem
158A - Next Round
71A - Way Too Long Words
160A - Twins
1A - Theatre Square
1614B - Divan and a New Project
791A - Bear and Big Brother
1452A - Robot Program
344A - Magnets
96A - Football
702B - Powers of Two
1036A - Function Height
443A - Anton and Letters
1478B - Nezzar and Lucky Number
228A - Is your horseshoe on the other hoof
122A - Lucky Division
1611C - Polycarp Recovers the Permutation
432A - Choosing Teams
758A - Holiday Of Equality
1650C - Weight of the System of Nested Segments