제출 #79992

#제출 시각아이디문제언어결과실행 시간메모리
79992pzdbaIgra (COCI17_igra)C++14
100 / 100
3 ms668 KiB
#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]++;
		}
	}
}

컴파일 시 표준 에러 (stderr) 메시지

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 timeMemoryGrader output
Fetching results...