/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 1ms 332.0 KiB
#2 Wrong Answer 4ms 540.0 KiB

Code

#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define MOD 1000000007
#define pie 2 * (acos(0.0))
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define pb push_back
#define nl '\n'
#define lcm(a, b) (a * b) / (__gcd<ll>(a, b))
#define print(v)          \
    for (auto e : v)      \
        cout << e << " "; \
    cout << endl;
#define printp(v)    \
    for (auto e : v) \
        cout << e.first << " " << e.second << endl;
#define srt(v) sort(v.begin(), v.end())
#define rsrt(v) sort(v.rbegin(), v.rend())
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define trav(a, x) for (auto &a : x)
#define F first
#define S second
#define setbit(x) __builtin_popcount(x)
#define sz(x) (int)(x).size()
#define vi vector<int>
#define pi pair<int, int>
#define even(n) if (n % 2 == 0)
#define odd(n) if (n % 2 == 1)
#define sp << " " <<

#define alliswell                \
    ios::sync_with_stdio(false); \
    cin.tie(nullptr);

void solve()
{
    int n; cin >> n;
    string s, t;
    cin >> s >> t;

    string ans = "";
    if(s[0] <= t[0])
        {
            ans += s[0];
        }
        else 
        {
            ans += t[0];
        }
    for(int i = 1; i < n; i++)
    {
        if(s[i] <= t[i])
        {
            char c = ans[i-1];
            if(c > s[i])
            {
                ans += t[i];
            }
            else{
                ans += s[i];
            }
        }
        else 
        {
            char c = ans[i-1];
            if(c > t[i])
            {
                ans += s[i];
            }
            else{
                ans += t[i];
            }
        }
    }
    bool f = true;
    //cout << ans << nl;

    for(int i = 0; i < n - 1; i++)
    {
        if(ans[i] > ans[i+1])
        {
            f = false;
           no;
           return;
        }
    }
    yes;
}

int main()
{
    alliswell

    int t; cin >> t;
    while(t--) solve();

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1117 String Sorted
Contest
LU IUJPC : Sylhet Division 2024, Mock Round
Language
C++17 (G++ 13.2.0)
Submit At
2024-12-07 10:32:56
Judged At
2024-12-07 10:32:56
Judged By
Score
0
Total Time
4ms
Peak Memory
540.0 KiB