Submission #1305467

#TimeUsernameProblemLanguageResultExecution timeMemory
1305467the_commando_xZamjena (COCI18_zamjena)C++17
70 / 70
97 ms24492 KiB
// #pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;

using pii = pair<int, int>;
using vii = vector<pii>;
using vvii = vector<vii>;

using l = long long;
using vl = vector<l>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;

using pll = pair<l, l>;
using vll = vector<pll>;
using vvll = vector<vll>;

using d = double;
using vd = vector<d>;
using vvd = vector<vd>;
using vvvd = vector<vvd>;

using ld = long double;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;

using vb = vector<bool>;
using vvb = vector<vb>;
using pbb = pair<bool, bool>;
using vbb = vector<pbb>;

using vs = vector<string>;
using vss = vector<vector<string>>;

#define ff first
#define ss second

#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()

void setIO(string name = "")
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if (!name.empty())
    {
        (void)freopen((name + ".in").c_str(), "r", stdin);
        (void)freopen((name + ".out").c_str(), "w", stdout);
    }
}

const ld pi = 3.14159265358979323846;

const l LINF = 1e18;
const l INF = 1e9;

const l MOD = 1e9 + 7;
// const l MOD = 998244353;

const l MAXN = 2e5 + 5;

int n;

vss s(2, vs(MAXN, ""));

map<string, bool> vis;
map<string, vs> adj;

bool isNumeric(const string &s)
{
    return '0' <= s[0] && s[0] <= '9';
}

void parser(string &s)
{
    reverse(all(s));
    while (s.size() && s.back() == '0')
        s.pop_back();

    if (s.empty())
        s.push_back('0');

    reverse(all(s));
}

bool flag = true;

void dfs(string &u, string &x)
{
    if (flag == false)
        return;
    if (vis[u])
        return;

    vis[u] = true;

    if (isNumeric(u))
        if (u != x)
            return (void)(flag = false);

    for (string v : adj[u])
        if (flag == false)
            return;
        else
            dfs(v, x);
}

void solve()
{
    cin >> n;
    for (int i = 0; i < 2; ++i)
        for (int j = 0; j < n && cin >> s[i][j]; ++j)
            if (isNumeric(s[i][j]))
                parser(s[i][j]); // removing leading zeros

    for (int i = 0; i < n; ++i)
    {
        if (isNumeric(s[0][i]) && isNumeric(s[1][i]))
            if (s[0][i] != s[1][i])
                return (void)(cout << "NE");

        adj[s[0][i]].push_back(s[1][i]);
        adj[s[1][i]].push_back(s[0][i]);
    }

    for (int i = 0; i < 2; ++i)
        for (int j = 0; j < n; ++j)
            if (isNumeric(s[i][j]))
                dfs(s[i][j], s[i][j]);

    cout << (flag ? "DA" : "NE");
}

int main()
{
    setIO("");

#ifndef ONLINE_JUDGE
    // setIO("filename");
#endif

    int t = 1;
    // cin >> t;
    while (t--)
        solve();

    return 0;
}

Compilation message (stderr)

zamjena.cpp: In function 'void setIO(std::string)':
zamjena.cpp:56:22: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |         (void)freopen((name + ".in").c_str(), "r", stdin);
      |               ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
zamjena.cpp:57:22: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |         (void)freopen((name + ".out").c_str(), "w", stdout);
      |               ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...