1927B - Following the String - CodeForces Solution


constructive algorithms greedy strings

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
#define ff first
#define ss second
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define vvi vector<vector<int>>
#define endl '\n'
const int base = 31;
const int MOD = 1e9 + 7;
const int maxN = 200006;
using namespace std;
int n, a[maxN];
map<char, int> mp;

void Input() {
	cin >> n;
	mp.clear();
	for(int i = 1; i <= n; i++) cin >> a[i];
}	

void Process() {
	for(int i = 1; i <= n; i++) {
		for(char c = 'a'; c <= 'z'; c++) {
			if (mp[c] == a[i]) {
				cout << c;
				mp[c]++;
				break;
			}
		}
	}
	cout << endl;
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	int test = 1;
	cin >> test;

	while(test--) {
		Input();
		Process();
	}
	return 0;
}

// special cases (n=1?)
// 2 segments intersect: max(l, L) <= min(r, R)

/*
-Use: ordered_set st;
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
-Use: loang
int X[4] = {0, -1, 1, 0};
int Y[4] = {1, 0, 0, -1};
*/

/*
#######################################
##                                   ##
##             LuOsIer               ##
##                                   ##
#######################################
*/



Comments

Submit
0 Comments
More Questions

645A - Amity Assessment
1144A - Diverse Strings
1553B - Reverse String
1073A - Diverse Substring
630N - Forecast
312B - Archer
34D - Road Map
630I - Parking Lot
160B - Unlucky Ticket
371B - Fox Dividing Cheese
584B - Kolya and Tanya
137B - Permutation
550C - Divisibility by Eight
5A - Chat Servers Outgoing Traffic
615A - Bulbs
5B - Center Alignment
549A - Face Detection
535B - Tavas and SaDDas
722C - Destroying Array
366A - Dima and Guards
716B - Complete the Word
1461C - Random Events
1627A - Not Shading
141B - Hopscotch
47B - Coins
1466C - Canine poetry
74A - Room Leader
1333D - Challenges in school №41
1475B - New Year's Number
461A - Appleman and Toastman