Submission #87818

# Submission time Handle Problem Language Result Execution time Memory
87818 2018-12-02T16:55:17 Z Koschei Igra (COCI17_igra) C++17
100 / 100
3 ms 744 KB
#include <iostream>

using namespace std;

const int MAXN = 5001;

int n;
int cnts[3];
int cntm[3];
char s[MAXN];
char m[MAXN];
char r[3] = {'a', 'b', 'c'};

int main()
{
	ios_base::sync_with_stdio(false);
	cin >> n >> s >> m;
	for (int i = 0; i < n; i++)
	{
		cnts[s[i]-'a']++;
		cntm[m[i]-'a']++;
	}
	for (int i = 0; i < n; i++)
	{
		cntm[m[i]-'a']--;
		for (int j = 0; j < 3; j++)
		{
			if (m[i] != r[j])
			{
				if ((j == 0) && cnts[0])
				{
					if ((cnts[0]+cnts[1]>=cntm[2]+1) && (cnts[0]+cnts[2]>=cntm[1]+1))
					{
						cout << 'a';
						cnts[0]--;
						break;
					}
				}
				if ((j == 1) && cnts[1])
				{
					if ((cnts[0]+cnts[1]>=cntm[2]+1) && (cnts[1]+cnts[2]>=cntm[0]+1))
					{
						cout << 'b';
						cnts[1]--;
						break;
					}
				}
				if ((j == 2) && cnts[2])
				{
					if ((cnts[2]+cnts[1]>=cntm[0]+1) && (cnts[0]+cnts[2]>=cntm[1]+1))
					{
						cout << 'c';
						cnts[2]--;
						break;
					}
				}
			}
		}
	}
	return 0;	
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
3 Correct 3 ms 624 KB Output is correct
4 Correct 2 ms 624 KB Output is correct
5 Correct 3 ms 624 KB Output is correct
6 Correct 2 ms 624 KB Output is correct
7 Correct 2 ms 640 KB Output is correct
8 Correct 2 ms 640 KB Output is correct
9 Correct 3 ms 640 KB Output is correct
10 Correct 2 ms 744 KB Output is correct