답안 #87020

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
87020 2018-11-29T08:26:14 Z minhtri5302 Zamjena (COCI18_zamjena) C++14
28 / 70
48 ms 5392 KB
//Trương Minh Trí
#include <bits/stdc++.h>
#define FOR(i, x, y) for(int i = x; i <= y; ++i)
#define FORN(i, x, y) for(int i = x; i >= y; --i)
#define Task "Zamjena"
#define maxn 50005
#define maxm
#define emlacongchuacuaanh 1302
#define pii pair <int, int>
#define pll pair <long long, long long>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define reset(x) memset(x, 0, sizeof(x));
using namespace std;
int n;
string a[maxn], b[maxn];
bool ok(string x)
{
    return (x[0] >= '0' && x[0] <= '9');
}
map<string, string> mm;
int save[maxn], cnt;
int save1[maxn], cnt1;
int save2[maxn], cnt2;
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    //freopen(Task".inp", "r", stdin);
    //freopen(Task".out", "w", stdout);
    cin >> n;
    FOR(i, 1, n) cin >> a[i];
    FOR(i, 1, n) cin >> b[i];
    FOR(i, 1, n)
    {
        if(!ok(a[i]) && !ok(b[i]))
        {
            save[++cnt] = i;
            continue;
        }
        if(ok(a[i]) && ok(b[i]))
        {
            if(a[i] == b[i]) continue;
            else return cout <<"NE", 0;
        }
        if(ok(a[i]) && !ok(b[i]))
        {
            if(mm[b[i]] =="") mm[b[i]] = a[i];
            else if(mm[b[i]] != a[i]) return cout <<"NE", 0;
        }
        if(!ok(a[i]) && ok(b[i]))
        {
            if(mm[a[i]] == "") mm[a[i]] = b[i];
            else if(mm[a[i]] != b[i]) return cout <<"NE", 0;
        }
    }
    FOR(i, 1, cnt)
    {
        int pos = save[i];
        if(mm[a[pos]] != "" && mm[b[pos]] != "")
        {
            if(mm[a[pos]] == mm[b[pos]]) continue;
            else return cout <<"NE", 0;
        }
        else if(mm[a[pos]] =="" && mm[b[pos]] == "")
        {
            save1[++cnt1] = pos;
            continue;
        }
        else if(mm[b[i]] != "" )  mm[a[i]] = mm[b[i]];
        else mm[b[i]] = mm[a[i]];
    }
    FOR(i, 1, cnt1)
    {
        int pos = save1[i];
        if(mm[a[pos]] != "" && mm[b[pos]] != "")
        {
            if(mm[a[pos]] == mm[b[pos]]) continue;
            else return cout <<"NE", 0;
        }
        else if(mm[a[pos]] =="" && mm[b[pos]] == "")
        {
            save2[++cnt2] = pos;
            continue;
        }
        else if(mm[b[i]] != "" )  mm[a[i]] = mm[b[i]];
        else mm[b[i]] = mm[a[i]];
    }
     FOR(i, 1, cnt2)
    {
        int pos = save2[i];
        if(mm[a[pos]] != "" && mm[b[pos]] != "")
        {
            if(mm[a[pos]] == mm[b[pos]]) continue;
            else return cout <<"NE", 0;
        }
        else if(mm[a[pos]] =="" && mm[b[pos]] == "")
        {
            mm[a[pos]] = mm[b[pos]] = "HVH";
        }
        else if(mm[b[i]] != "" )  mm[a[i]] = mm[b[i]];
        else mm[b[i]] = mm[a[i]];
    }
    cout << "DA";


}


























template <typename T> inline void read(T &x){char c;bool nega=0;while((!isdigit(c=getchar()))&&(c!='-'));if(c=='-'){nega=1;c=getchar();}x=c-48;while(isdigit(c=getchar())) x=x*10+c-48;if(nega) x=-x;}
template <typename T> inline void writep(T x){if(x>9) writep(x/10);putchar(x%10+48);}
template <typename T> inline void write(T x){if(x<0){putchar('-');x=-x;}writep(x);putchar(' ');}
template <typename T> inline void writeln(T x){write(x);putchar('\n');}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 3448 KB Output is correct
2 Correct 5 ms 3608 KB Output is correct
3 Correct 5 ms 3608 KB Output is correct
4 Correct 5 ms 3616 KB Output is correct
5 Correct 5 ms 3616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 3640 KB Output is correct
2 Correct 4 ms 3640 KB Output is correct
3 Correct 5 ms 3640 KB Output is correct
4 Correct 5 ms 3716 KB Output is correct
5 Correct 5 ms 3716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 3716 KB Output is correct
2 Correct 5 ms 3716 KB Output is correct
3 Correct 5 ms 3716 KB Output is correct
4 Correct 5 ms 3716 KB Output is correct
5 Correct 5 ms 3720 KB Output is correct
6 Incorrect 5 ms 3724 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 3856 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 4496 KB Output is correct
2 Incorrect 48 ms 5392 KB Output isn't correct
3 Halted 0 ms 0 KB -