답안 #580830

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
580830 2022-06-22T00:05:51 Z Metal_Sonic Igra (COCI17_igra) C++17
100 / 100
1 ms 340 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define sz(x) (int)(x).size()
#define all(x) x.begin() , x.end()
void setIO(string name = "") {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    if(sz(name)){
        freopen((name+".in").c_str(), "r", stdin);
        freopen((name+".out").c_str(), "w", stdout);
    }
}
void run_test_case(){
    // ffs stop brute forcing anything and think
    int n;cin>>n;
    string s , m;cin>>s>>m;
    char a='a',b='b',c='c';
    string ans = "";
    map<char,int>A,B;
    for(int i = 0; i < n; i++){
        A[s[i]]++;
        B[m[i]]++;
    }
    for(int i = 0; i < n; i++){
       if(m[i] == 'a' && A[b] && A[b]-1+A[a] >= B[c] && A[b]-1+A[c] >= B[a]-1)ans+='b',A[b]--,B[a]--;
       else if(m[i] == 'a')ans+='c',A[c]--,B[a]--;
       else if(m[i] == 'b' && A[a] && A[a]-1+A[b] >= B[c] && A[a]-1+A[c] >= B[b]-1)ans+='a',A[a]--,B[b]--;
       else if(m[i] == 'b')ans+='c',A[c]--,B[b]--;
       else if(m[i] == 'c' && A[a] && A[a]-1+A[c] >= B[b] && A[a]-1+A[b] >= B[c]-1)ans+='a',A[a]--,B[c]--;
       else ans+='b',A[b]--,B[c]--;
    }
    cout<<ans;
}
int main() {
    setIO();
    int T = 1;
    while(T--){
        run_test_case();
    }
    return 0;
}

Compilation message

igra.cpp: In function 'void setIO(std::string)':
igra.cpp:9:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |         freopen((name+".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
igra.cpp:10:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |         freopen((name+".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 236 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct