Submission #499083

# Submission time Handle Problem Language Result Execution time Memory
499083 2021-12-27T08:14:02 Z LouayFarah Igra (COCI17_igra) C++14
20 / 100
48 ms 476 KB
#include "bits/stdc++.h"

using namespace std;

#define endl "\n"
#define ll long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second

const long long MOD = 1e9+7;
const long long INF = 1e18;

int nx[4] = {0, 0, -1, 1};
int ny[4] = {1, -1, 0, 0};


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);


    ll n;
    cin >> n;

    string a, b;
    cin >> a >> b;

    sort(a.begin(), a.end());

    vector<bool> visited(n, false);

    string res1 = "";
    string res2 = "";
    string res3 = "";
    string res4 = "";

    for(int i = 0; i<n; i++)
    {
        for(int j = 0; j<n; j++)
        {
            if(visited[j])
                continue;

            if(a[j]!=b[i])
            {
                visited[j] = true;
                res1.pb(a[j]);
                break;
            }
        }
    }

    visited.assign(n, false);

    for(int i = 0; i<n; i++)
    {
        for(int j = n-1; j>=0; j--)
        {
            if(visited[j])
                continue;

            if(a[j]!=b[i])
            {
                visited[j] = true;
                res2.pb(a[j]);
                break;
            }
        }
    }

    visited.assign(n, false);

    for(int i = n-1; i>=0; i--)
    {
        for(int j = 0; j<n; j++)
        {
            if(visited[j])
                continue;

            if(a[j]!=b[i])
            {
                visited[j] = true;
                res3.pb(a[j]);
                break;
            }
        }
    }
    reverse(res3.begin(), res3.end());
    visited.assign(n, false);

    for(int i = n-1; i>=0; i--)
    {
        for(int j = n-1; j>=0; j--)
        {
            if(visited[j])
                continue;

            if(a[j]!=b[i])
            {
                visited[j] = true;
                res4.pb(a[j]);
                break;
            }
        }
    }

    reverse(res4.begin(), res4.end());

    vector<string> res;
    if(int(res1.size())==n)
        res.pb(res1);
    if(int(res2.size())==n)
        res.pb(res2);
    if(int(res3.size())==n)
        res.pb(res3);
    if(int(res4.size())==n)
        res.pb(res4);

    sort(res.begin(), res.end());

    cout << res[0] << endl;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Incorrect 1 ms 208 KB Output isn't correct
3 Correct 0 ms 208 KB Output is correct
4 Runtime error 1 ms 448 KB Execution killed with signal 11
5 Runtime error 1 ms 336 KB Execution killed with signal 11
6 Runtime error 1 ms 336 KB Execution killed with signal 11
7 Runtime error 1 ms 436 KB Execution killed with signal 11
8 Runtime error 3 ms 464 KB Execution killed with signal 11
9 Runtime error 46 ms 472 KB Execution killed with signal 11
10 Runtime error 48 ms 476 KB Execution killed with signal 11