답안 #703615

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
703615 2023-02-27T19:08:06 Z delrey Zamjena (COCI18_zamjena) C++14
70 / 70
84 ms 14416 KB
#include <bits/stdc++.h>

using namespace std;

int n, a[50000], b[50000];
unordered_map <string, vector<int> > varA, varB;
string x[50000], y[50000];

int StrToInt(string &s)
{
    int k = 0;
    for(size_t i = 0; i < s.length(); i++)
        k = k * 10 + s[i] - '0';
    return k;
}

int main()
{
    cin>>n;
    string s;
    for(int i = 0; i < n; i++)
    {
        cin>>s;
        if(s[0] >= '0' && s[0] <= '9')
        {
            a[i] = StrToInt(s);
            continue;
        }
        varA[s].push_back(i);
        x[i] = s;
    }
    for(int i = 0; i < n; i++)
    {
        cin>>s;
        if(s[0] >= '0' && s[0] <= '9')
        {
            b[i] = StrToInt(s);
            continue;
        }
        varB[s].push_back(i);
        y[i] = s;
    }
    bool finish = false;
    while(!finish)
    {
        finish = true;
        for(int i = 0; i < n; i++)
        {
            int k = -1;
            if(a[i] && !b[i])
            {
                k = a[i];
                s = y[i];
            }
            if(!a[i] && b[i])
            {
                k = b[i];
                s = x[i];
            }
            if(k == -1)
                continue;
            for(auto j : varA[s])
                a[j] = k;
            for(auto j : varB[s])
                b[j] = k;
            finish = false;
        }
    }
    for(int i = 0; i < n; i++)
        if(a[i] != b[i])
        {
            cout<<"NE"<<endl;
            return 0;
        }
    cout<<"DA"<<endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Correct 2 ms 3412 KB Output is correct
3 Correct 2 ms 3412 KB Output is correct
4 Correct 2 ms 3412 KB Output is correct
5 Correct 2 ms 3412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3412 KB Output is correct
2 Correct 2 ms 3412 KB Output is correct
3 Correct 2 ms 3412 KB Output is correct
4 Correct 2 ms 3412 KB Output is correct
5 Correct 2 ms 3412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Correct 2 ms 3412 KB Output is correct
3 Correct 2 ms 3436 KB Output is correct
4 Correct 2 ms 3412 KB Output is correct
5 Correct 2 ms 3412 KB Output is correct
6 Correct 2 ms 3412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3540 KB Output is correct
2 Correct 2 ms 3540 KB Output is correct
3 Correct 4 ms 3832 KB Output is correct
4 Correct 5 ms 4052 KB Output is correct
5 Correct 5 ms 3924 KB Output is correct
6 Correct 5 ms 3768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 4840 KB Output is correct
2 Correct 22 ms 6544 KB Output is correct
3 Correct 42 ms 9372 KB Output is correct
4 Correct 46 ms 9860 KB Output is correct
5 Correct 84 ms 14416 KB Output is correct
6 Correct 46 ms 8816 KB Output is correct