# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
490336 | niloyroot | Igra (COCI17_igra) | C++14 | 1 ms | 460 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using pl = pair<ll,ll>;
#define pb push_back
#define form(m,it) for(auto it=m.begin(); it!=m.end(); it++)
#define forp(i,a,b) for(ll i=a; i<=b; i++)
#define forn(i,a,b) for(ll i=a; i>=b; i--)
#define newl '\n'
#define ff first
#define ss second
const ll mod = 1000000007;
void solve(){
ll n; cin>>n;
string a,b; cin>>a>>b;
ll c[3]={0};
forp(i,0,n-1){c[a[i]-'a']++;}
ll cnt[3][n+1];
memset(cnt,0,sizeof(cnt));
forn(i,n-1,0){
forp(j,0,2){
cnt[j][i]=cnt[j][i+1]+(b[i]-'a'==j);
}
}
string s="";
bool g; ll sum;
forp(i,0,n-1){
forp(j,0,2){
g=1;
if(j==b[i]-'a'){continue;}
forp(k,0,2){
sum=0;
forp(m,0,2){
if(m!=k){
sum+=c[m];
if(m==j){sum--;}
}
}
if(sum<cnt[k][i+1]){
g=0;
}
}
if(g){
c[j]--;
s+=(j+'a'); break;
}
}
}
cout<<s<<newl;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t=1; //cin>>t;
while(t--)solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |