Submission #79992

# Submission time Handle Problem Language Result Execution time Memory
79992 2018-10-17T21:54:33 Z pzdba Igra (COCI17_igra) C++14
100 / 100
3 ms 668 KB
#include <bits/stdc++.h>
using namespace std;
char s[5005], m[5005];
int cnt[3];
int dp[3][5005];
int main(){
	int n;
	scanf("%d", &n);
	scanf("%s", s+1);
	scanf("%s", m+1);
	for(int i=1;i<=n;i++) cnt[s[i]-'a']++;
	for(int i=1;i<=n;i++){
		int c = m[i]-'a';
		dp[c][i]++;
		for(int j=0;j<3;j++) dp[j][i] += dp[j][i-1];
	}
	for(int i=1;i<=n;i++){
		for(int j=0;j<3;j++){
			if(m[i] == j+'a' || cnt[j] == 0) continue;

			bool ok = 0;
			cnt[j]--;

			int a2 = dp[0][n] - dp[0][i];
			int b2 = dp[1][n] - dp[1][i];
			int c2 = dp[2][n] - dp[2][i];

			int a1 = cnt[0];
			int b1 = cnt[1];
			int c1 = cnt[2];

			for(int k=0;k<=min(a1, b2);k++){
				int ta = a2, tb = b2, tc = c2;
				int d = k;
				tb -= k;
				tc -= a1-k;

				d = min(tc, b1);
				tc -= d;
				ta -= b1-d;

				d = min(ta, c1);
				ta -= d;
				tb -= c1-d;

				if(ta == 0 && tb == 0 && tc == 0){
					ok = 1;
					break;
				}
			}

			if(ok){
				printf("%c", j+'a');
				break;
			}
			cnt[j]++;
		}
	}
}

Compilation message

igra.cpp: In function 'int main()':
igra.cpp:8:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
igra.cpp:9:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s", s+1);
  ~~~~~^~~~~~~~~~~
igra.cpp:10:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s", m+1);
  ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 2 ms 476 KB Output is correct
5 Correct 2 ms 588 KB Output is correct
6 Correct 2 ms 588 KB Output is correct
7 Correct 2 ms 632 KB Output is correct
8 Correct 2 ms 636 KB Output is correct
9 Correct 2 ms 640 KB Output is correct
10 Correct 3 ms 668 KB Output is correct