# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
79992 | pzdba | Igra (COCI17_igra) | C++14 | 3 ms | 668 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |