답안 #1008070

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1008070 2024-06-26T07:19:48 Z vicvic Zamjena (COCI18_zamjena) C++11
56 / 70
32 ms 6588 KB
#include <iostream>
#include <unordered_map>
#include <set>
#include <cstring>
#include <string>
using namespace std;
unordered_map <int, int> umap;
unordered_map <string, int> found;
int v[50005], v1[50005], n, cnt=1006;
int transform_nr (string s)
{
    if (!isdigit (s[0]))
    {
        if (found[s])
        {
            return found[s];
        }
        else
        {
            found[s]=++cnt;
            return found[s];
        }
    }
    else
    {
        int nr=0;
        for (int i=0;s[i];i++)
        {
            nr=nr*10+s[i]-'0';
        }
        return nr;
    }
}
int main()
{
    cin >> n;
    for (int i=1;i<=n;i++)
    {
        string s;
        cin >> s;
        v[i]=transform_nr (s);
    }
    for (int i=1;i<=n;i++)
    {
        string s;
        cin >> s;
        v1[i]=transform_nr (s);
    }
    for (int i=1;i<=n;i++)
    {
        if (v[i]<=1000 && v1[i]<=1000)
        {
            if (v[i]!=v1[i])
            {
                cout << "NE";
                return 0;
            }
        }
        if (v[i]>1000 && v1[i]<=1000)
        {
            if (umap[v[i]] && umap[v[i]]!=v1[i])
            {
                cout << "NE";
                return 0;
            }
            umap[v[i]]=v1[i];
        }
        if (v[i]<=1000 && v1[i]>1000)
        {
            if (umap[v1[i]] && umap[v1[i]]!=v[i])
            {
                cout << "NE";
                return 0;
            }
            umap[v1[i]]=v[i];
        }
        if (v[i]>1000 && v1[i]>1000)
        {
            if (!umap[v[i]] && !umap[v1[i]])
            {
                continue;
            }
            if (umap[v[i]] && umap[v1[i]] && umap[v[i]]!=umap[v1[i]])
            {
                cout << "NE";
                return 0;
            }
            else if (!umap[v[i]])
            {
                umap[v[i]]=umap[v1[i]];
            }
            else if (!umap[v1[i]])
            {
                umap[v1[i]]=umap[v[i]];
            }
        }
    }
    for (int j=1;j<=2;j++)
    for (int i=1;i<=n;i++)
    {
        if (v[i]>1000 && v1[i]>1000)
        {
            if (!umap[v[i]] && !umap[v1[i]])
            {
                continue;
            }
            if (umap[v[i]] && umap[v1[i]] && umap[v[i]]!=umap[v1[i]])
            {
                cout << "NE";
                return 0;
            }
            else if (!umap[v[i]])
            {
                umap[v[i]]=umap[v1[i]];
            }
            else if (!umap[v1[i]])
            {
                umap[v1[i]]=umap[v[i]];
            }
        }
    }
    cout << "DA";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 508 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 3 ms 604 KB Output is correct
6 Correct 2 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1116 KB Output is correct
2 Correct 13 ms 1988 KB Output is correct
3 Correct 18 ms 3512 KB Output is correct
4 Correct 22 ms 3764 KB Output is correct
5 Correct 32 ms 6588 KB Output is correct
6 Correct 27 ms 2908 KB Output is correct