Solution for Back From Summer '17 P2: Crayola Lightsaber in C++


June 1, 2020 0.017075 seconds C++
#include <bits/stdc++.h>
using namespace std;

typedef long long LL; 
typedef pair<int, int> pii; 
typedef pair<LL, LL> pll; 
typedef pair<string, string> pss; 
typedef vector<int> vi; 
typedef vector<vi> vvi; 
typedef vector<pii> vii; 
typedef vector<LL> vl; 
typedef vector<vl> vvl;
typedef queue<int> qi;
typedef queue<char> qc;
typedef stack<int> si;
typedef stack<char> sc;
#define F first
#define S second
#define PB push_back

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

	int n;
	cin >> n;

	int colors[6] = {0};
	string inp;

	for(int i = 0; i < n; i++){
		cin >> inp;
		if(inp == "orange") {colors[1]++; continue;}
		switch(inp[2]){
			case 'd': colors[0]++; break;
			case 'l': colors[2]++; break;
			case 'e': colors[3]++; break;
			case 'u': colors[4]++; break;
			case 'a': colors[5]++; break;
		}
	}
	sort(colors, colors + 6);
	/*for(int i = 0; i < 6; i++){
		cout << colors[i] << " ";
	}
	cout << "\n";*/
	int g = colors[5];
	int r = n - g;

	cout << min(g, r + 1) + r;

    return 0;
}

Editorial


No editorial for this problem. :(

Original Problem


You can view the original page for this problem on the DMOJ.